lua fixes
This commit is contained in:
parent
3c62ce97db
commit
5d0d1432ed
|
@ -27,12 +27,7 @@ function Settings.remove(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Settings.set(key, value)
|
function Settings.set(key, value)
|
||||||
local valuestr = convertSettingValue(value)
|
g_configs.set(key, convertSettingValue(value))
|
||||||
if valuestr == '' then
|
|
||||||
g_configs.remove(key)
|
|
||||||
else
|
|
||||||
g_configs.set(key, convertSettingValue(value))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Settings.setDefault(key, value)
|
function Settings.setDefault(key, value)
|
||||||
|
|
|
@ -76,3 +76,10 @@ function toboolean(str)
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local oldtonumber = tonumber
|
||||||
|
function tonumber(v)
|
||||||
|
local v = oldtonumber(v)
|
||||||
|
if not v then return 0 end
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
|
|
@ -49,30 +49,11 @@ bool ConfigManager::save()
|
||||||
{
|
{
|
||||||
OTMLDocumentPtr doc = OTMLDocument::create();
|
OTMLDocumentPtr doc = OTMLDocument::create();
|
||||||
for(auto it : m_confsMap) {
|
for(auto it : m_confsMap) {
|
||||||
|
if(it.second == "")
|
||||||
|
continue;
|
||||||
OTMLNodePtr node = OTMLNode::create(it.first, it.second);
|
OTMLNodePtr node = OTMLNode::create(it.first, it.second);
|
||||||
doc->addChild(node);
|
doc->addChild(node);
|
||||||
}
|
}
|
||||||
return doc->save(m_fileName);
|
return doc->save(m_fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigManager::exists(const std::string& key)
|
|
||||||
{
|
|
||||||
return m_confsMap.find(key) != m_confsMap.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigManager::set(const std::string& key, const std::string& value)
|
|
||||||
{
|
|
||||||
m_confsMap[key] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ConfigManager::get(const std::string& key)
|
|
||||||
{
|
|
||||||
return m_confsMap[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigManager::remove(const std::string& key)
|
|
||||||
{
|
|
||||||
auto it = m_confsMap.find(key);
|
|
||||||
if(it != m_confsMap.end())
|
|
||||||
m_confsMap.erase(it);
|
|
||||||
}
|
|
||||||
|
|
|
@ -31,10 +31,10 @@ public:
|
||||||
bool load(const std::string& file);
|
bool load(const std::string& file);
|
||||||
bool save();
|
bool save();
|
||||||
|
|
||||||
bool exists(const std::string& key);
|
bool exists(const std::string& key) { return m_confsMap.find(key) != m_confsMap.end(); }
|
||||||
void set(const std::string& key, const std::string& value);
|
void set(const std::string& key, const std::string& value) { m_confsMap[key] = value; }
|
||||||
std::string get(const std::string& key);
|
std::string get(const std::string& key) { return m_confsMap[key]; }
|
||||||
void remove(const std::string& key);
|
void remove(const std::string& key) { m_confsMap[key] = ""; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_fileName;
|
std::string m_fileName;
|
||||||
|
|
|
@ -45,8 +45,8 @@ void push_luavalue(int i)
|
||||||
bool luavalue_cast(int index, int& i)
|
bool luavalue_cast(int index, int& i)
|
||||||
{
|
{
|
||||||
i = g_lua.toInteger(index);
|
i = g_lua.toInteger(index);
|
||||||
if(i == 0 && !g_lua.isNumber(index))
|
//if(i == 0 && !g_lua.isNumber(index))
|
||||||
return false;
|
// return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,8 +59,8 @@ void push_luavalue(double d)
|
||||||
bool luavalue_cast(int index, double& d)
|
bool luavalue_cast(int index, double& d)
|
||||||
{
|
{
|
||||||
d = g_lua.toNumber(index);
|
d = g_lua.toNumber(index);
|
||||||
if(d == 0 && !g_lua.isNumber(index))
|
//if(d == 0 && !g_lua.isNumber(index))
|
||||||
return false;
|
// return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue