From 5d0d1432ed4090481af148e509e48953841fa89b Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Fri, 6 Jan 2012 22:46:41 -0200 Subject: [PATCH] lua fixes --- modules/core_lib/settings.lua | 7 +------ modules/core_lib/util.lua | 7 +++++++ src/framework/core/configmanager.cpp | 23 ++--------------------- src/framework/core/configmanager.h | 8 ++++---- src/framework/luascript/luavaluecasts.cpp | 8 ++++---- 5 files changed, 18 insertions(+), 35 deletions(-) diff --git a/modules/core_lib/settings.lua b/modules/core_lib/settings.lua index 972b1b94..3a951821 100644 --- a/modules/core_lib/settings.lua +++ b/modules/core_lib/settings.lua @@ -27,12 +27,7 @@ function Settings.remove(key) end function Settings.set(key, value) - local valuestr = convertSettingValue(value) - if valuestr == '' then - g_configs.remove(key) - else - g_configs.set(key, convertSettingValue(value)) - end + g_configs.set(key, convertSettingValue(value)) end function Settings.setDefault(key, value) diff --git a/modules/core_lib/util.lua b/modules/core_lib/util.lua index 23cfd059..f231b902 100644 --- a/modules/core_lib/util.lua +++ b/modules/core_lib/util.lua @@ -76,3 +76,10 @@ function toboolean(str) end return false end + +local oldtonumber = tonumber +function tonumber(v) + local v = oldtonumber(v) + if not v then return 0 end + return v +end diff --git a/src/framework/core/configmanager.cpp b/src/framework/core/configmanager.cpp index 252c02be..410c1851 100644 --- a/src/framework/core/configmanager.cpp +++ b/src/framework/core/configmanager.cpp @@ -49,30 +49,11 @@ bool ConfigManager::save() { OTMLDocumentPtr doc = OTMLDocument::create(); for(auto it : m_confsMap) { + if(it.second == "") + continue; OTMLNodePtr node = OTMLNode::create(it.first, it.second); doc->addChild(node); } 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); -} diff --git a/src/framework/core/configmanager.h b/src/framework/core/configmanager.h index cca797c2..8297b5f2 100644 --- a/src/framework/core/configmanager.h +++ b/src/framework/core/configmanager.h @@ -31,10 +31,10 @@ public: bool load(const std::string& file); bool save(); - bool exists(const std::string& key); - void set(const std::string& key, const std::string& value); - std::string get(const std::string& key); - void remove(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) { m_confsMap[key] = value; } + std::string get(const std::string& key) { return m_confsMap[key]; } + void remove(const std::string& key) { m_confsMap[key] = ""; } private: std::string m_fileName; diff --git a/src/framework/luascript/luavaluecasts.cpp b/src/framework/luascript/luavaluecasts.cpp index a23083cd..cb9065ee 100644 --- a/src/framework/luascript/luavaluecasts.cpp +++ b/src/framework/luascript/luavaluecasts.cpp @@ -45,8 +45,8 @@ void push_luavalue(int i) bool luavalue_cast(int index, int& i) { i = g_lua.toInteger(index); - if(i == 0 && !g_lua.isNumber(index)) - return false; + //if(i == 0 && !g_lua.isNumber(index)) + // return false; return true; } @@ -59,8 +59,8 @@ void push_luavalue(double d) bool luavalue_cast(int index, double& d) { d = g_lua.toNumber(index); - if(d == 0 && !g_lua.isNumber(index)) - return false; + //if(d == 0 && !g_lua.isNumber(index)) + // return false; return true; }