bool CSettings::IsInteger(String strSetting) { SettingsValue * setting = GetSetting(strSetting); if(setting && setting->IsInteger()) return true; return false; }
// getConfig() SQInteger CServerNatives::GetConfig(SQVM * pVM) { // Create a new table sq_newtable(pVM); for(std::map<String, SettingsValue *>::iterator iter = CSettings::GetValues()->begin(); iter != CSettings::GetValues()->end(); iter++) { // Get the setting SettingsValue * setting = iter->second; // Push the setting name onto the stack sq_pushstring(pVM, iter->first.Get(), iter->first.GetLength()); // Push the value onto the stack if(setting->IsBool()) sq_pushbool(pVM, setting->bValue); else if(setting->IsInteger()) sq_pushinteger(pVM, setting->iValue); else if(setting->IsFloat()) sq_pushfloat(pVM, setting->fValue); else if(setting->IsString()) sq_pushstring(pVM, setting->strValue, setting->strValue.GetLength()); else if(setting->IsList()) { // Create a new array sq_newarray(pVM, 0); for(std::list<String>::iterator iter2 = setting->listValue.begin(); iter2 != setting->listValue.end(); iter2++) { // Push the list value onto the stack sq_pushstring(pVM, (*iter2).Get(), (*iter2).GetLength()); // Create a new array slot sq_arrayappend(pVM, -2); } } // Create a new table slot sq_createslot(pVM, -3); } return 1; }
// getConfig() int CServerNatives::GetConfig(lua_State * pVM) { // Create a new table script_newtable(pVM, 0); for(std::map<String, SettingsValue *>::iterator iter = CSettings::GetValues()->begin(); iter != CSettings::GetValues()->end(); iter++) { // Get the setting SettingsValue * setting = iter->second; // Push the setting name onto the stack script_pushlstring(pVM, iter->first.Get(), iter->first.GetLength()); // Push the value onto the stack if(setting->IsBool()) script_pushbool(pVM, setting->bValue); else if(setting->IsInteger()) script_pushinteger(pVM, setting->iValue); else if(setting->IsFloat()) script_pushfloat(pVM, setting->fValue); else if(setting->IsString()) script_pushlstring(pVM, setting->strValue, setting->strValue.GetLength()); else if(setting->IsList()) { // Create a new array CScriptArray a(pVM); for(std::list<String>::iterator iter2 = setting->listValue.begin(); iter2 != setting->listValue.end(); iter2++) { // Push the list value onto the stack a.push(iter2->Get(), iter2->GetLength()); // Create a new array slot //script_arrayappend(pVM, -2); } } // Create a new table slot script_tableset(pVM, -3); } return 1; }
String CSettings::GetEx(String strSetting) { String strValue; // Get the setting SettingsValue * setting = GetSetting(strSetting); // Does the setting exist? if(setting) { if(setting->IsBool()) strValue.FromBoolean(setting->bValue); else if(setting->IsInteger()) strValue.FromInteger(setting->iValue); else if(setting->IsFloat()) strValue.FromFloat(setting->fValue); else if(setting->IsString()) strValue = setting->strValue; } return strValue; }