From 34f9ecb6c823b5c786e07d8846899bb46e746d30 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 1 Feb 2012 22:10:55 -0200 Subject: [PATCH] fixes in Settings/g_configs --- modules/addon_terminal/terminal.lua | 5 ++++ modules/core_lib/settings.lua | 2 +- src/framework/core/configmanager.cpp | 1 + src/framework/luascript/luavaluecasts.cpp | 32 ++++++++++++++++------- src/framework/otml/otmlnode.h | 1 + 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/modules/addon_terminal/terminal.lua b/modules/addon_terminal/terminal.lua index c5fd92dc..5fdb07c0 100644 --- a/modules/addon_terminal/terminal.lua +++ b/modules/addon_terminal/terminal.lua @@ -173,6 +173,11 @@ end function Terminal.executeCommand(command) if command == nil or #command == 0 then return end + + logLocked = true + Logger.log(LogInfo, '>> ' .. command) + logLocked = false + -- detect and convert commands with simple syntax local realCommand if commandEnv[command] then diff --git a/modules/core_lib/settings.lua b/modules/core_lib/settings.lua index bdb90605..60e76c82 100644 --- a/modules/core_lib/settings.lua +++ b/modules/core_lib/settings.lua @@ -2,7 +2,7 @@ Settings = {} Settings.exists = g_configs.exists Settings.setNode = g_configs.setNode -Settings.mergeNode = g_configs.mergeNode +Settings.addNode = g_configs.addNode Settings.getNode = g_configs.getNode Settings.remove = g_configs.remove Settings.setList = g_configs.setList diff --git a/src/framework/core/configmanager.cpp b/src/framework/core/configmanager.cpp index a5aab0df..924b669b 100644 --- a/src/framework/core/configmanager.cpp +++ b/src/framework/core/configmanager.cpp @@ -123,6 +123,7 @@ void ConfigManager::addNode(const std::string& key, const OTMLNodePtr& node) { OTMLNodePtr clone = node->clone(); node->setTag(key); + node->setUnique(true); m_confsDoc->addChild(node); } diff --git a/src/framework/luascript/luavaluecasts.cpp b/src/framework/luascript/luavaluecasts.cpp index 0a9d537f..573d2d39 100644 --- a/src/framework/luascript/luavaluecasts.cpp +++ b/src/framework/luascript/luavaluecasts.cpp @@ -243,14 +243,13 @@ void push_otml_subnode_luavalue(const OTMLNodePtr& node) void push_luavalue(const OTMLNodePtr& node) { g_lua.newTable(); + int currentIndex = 1; for(const OTMLNodePtr& cnode : node->children()) { + push_otml_subnode_luavalue(cnode); if(cnode->isUnique()) { - push_otml_subnode_luavalue(cnode); - if(!g_lua.isNil()) { - g_lua.setField(cnode->tag()); - } else - g_lua.pop(); - } + g_lua.setField(cnode->tag()); + } else + g_lua.rawSeti(currentIndex++); } } @@ -261,15 +260,28 @@ bool luavalue_cast(int index, OTMLNodePtr& node) if(g_lua.isTable(index)) { g_lua.pushNil(); while(g_lua.next(index < 0 ? index-1 : index)) { - std::string cnodeName = g_lua.toString(-2); + bool listItem = false; + std::string cnodeName; + if(g_lua.isNumber(-2)) + listItem = true; + else + cnodeName = g_lua.toString(-2); if(g_lua.isTable()) { OTMLNodePtr cnode; if(luavalue_cast(-1, cnode)) { - cnode->setTag(cnodeName); + if(listItem) + node->setUnique(false); + else + cnode->setTag(cnodeName); node->addChild(cnode); } - } else - node->writeAt(cnodeName, g_lua.toString()); + } else { + std::string value = g_lua.toString(); + if(listItem) + node->writeIn(value); + else + node->writeAt(cnodeName, value); + } g_lua.pop(); } return true; diff --git a/src/framework/otml/otmlnode.h b/src/framework/otml/otmlnode.h index 1b1e6e74..3897d293 100644 --- a/src/framework/otml/otmlnode.h +++ b/src/framework/otml/otmlnode.h @@ -147,6 +147,7 @@ void OTMLNode::write(const T& v) { template void OTMLNode::writeAt(const std::string& childTag, const T& v) { OTMLNodePtr child = OTMLNode::create(childTag); + child->setUnique(true); child->write(v); addChild(child); }