allow setting/getting nodes in g_configs
This commit is contained in:
parent
289efe34cf
commit
98ef0e4574
|
@ -1,5 +1,13 @@
|
||||||
Settings = {}
|
Settings = {}
|
||||||
|
|
||||||
|
Settings.exists = g_configs.exists
|
||||||
|
Settings.setNode = g_configs.setNode
|
||||||
|
Settings.mergeNode = g_configs.mergeNode
|
||||||
|
Settings.getNode = g_configs.getNode
|
||||||
|
Settings.remove = g_configs.remove
|
||||||
|
Settings.setList = g_configs.setList
|
||||||
|
Settings.getList = g_configs.getList
|
||||||
|
|
||||||
local function convertSettingValue(value)
|
local function convertSettingValue(value)
|
||||||
if type(value) == 'table' then
|
if type(value) == 'table' then
|
||||||
if value.x and value.width then
|
if value.x and value.width then
|
||||||
|
@ -20,21 +28,10 @@ local function convertSettingValue(value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Settings.exists(key)
|
|
||||||
return g_configs.exists(key)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Settings.remove(key)
|
|
||||||
g_configs.remove(key)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Settings.set(key, value)
|
function Settings.set(key, value)
|
||||||
g_configs.set(key, convertSettingValue(value))
|
g_configs.set(key, convertSettingValue(value))
|
||||||
end
|
end
|
||||||
|
|
||||||
function Settings.setList(key, list)
|
|
||||||
g_configs.setList(key, list)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Settings.setDefault(key, value)
|
function Settings.setDefault(key, value)
|
||||||
if Settings.exists(key) then return false end
|
if Settings.exists(key) then return false end
|
||||||
|
@ -49,10 +46,6 @@ function Settings.get(key, default)
|
||||||
return g_configs.get(key)
|
return g_configs.get(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Settings.getList(key)
|
|
||||||
return g_configs.getList(key)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Settings.getString(key, default)
|
function Settings.getString(key, default)
|
||||||
return Settings.get(key, default)
|
return Settings.get(key, default)
|
||||||
end
|
end
|
||||||
|
|
|
@ -112,3 +112,21 @@ void ConfigManager::remove(const std::string& key)
|
||||||
if(child)
|
if(child)
|
||||||
m_confsDoc->removeChild(child);
|
m_confsDoc->removeChild(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigManager::setNode(const std::string& key, const OTMLNodePtr& node)
|
||||||
|
{
|
||||||
|
remove(key);
|
||||||
|
addNode(key, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigManager::addNode(const std::string& key, const OTMLNodePtr& node)
|
||||||
|
{
|
||||||
|
OTMLNodePtr clone = node->clone();
|
||||||
|
node->setTag(key);
|
||||||
|
m_confsDoc->addChild(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
OTMLNodePtr ConfigManager::getNode(const std::string& key)
|
||||||
|
{
|
||||||
|
return m_confsDoc->get(key);
|
||||||
|
}
|
||||||
|
|
|
@ -37,6 +37,11 @@ public:
|
||||||
void setList(const std::string& key, const std::vector<std::string>& list);
|
void setList(const std::string& key, const std::vector<std::string>& list);
|
||||||
std::string get(const std::string& key);
|
std::string get(const std::string& key);
|
||||||
std::vector<std::string> getList(const std::string& key);
|
std::vector<std::string> getList(const std::string& key);
|
||||||
|
|
||||||
|
void setNode(const std::string& key, const OTMLNodePtr& node);
|
||||||
|
void addNode(const std::string& key, const OTMLNodePtr& node);
|
||||||
|
OTMLNodePtr getNode(const std::string& key);
|
||||||
|
|
||||||
bool exists(const std::string& key);
|
bool exists(const std::string& key);
|
||||||
void remove(const std::string& key);
|
void remove(const std::string& key);
|
||||||
|
|
||||||
|
|
|
@ -381,6 +381,9 @@ void Application::registerLuaFunctions()
|
||||||
g_lua.bindClassStaticFunction("g_configs", "getList", std::bind(&ConfigManager::getList, &g_configs, _1));
|
g_lua.bindClassStaticFunction("g_configs", "getList", std::bind(&ConfigManager::getList, &g_configs, _1));
|
||||||
g_lua.bindClassStaticFunction("g_configs", "exists", std::bind(&ConfigManager::exists, &g_configs, _1));
|
g_lua.bindClassStaticFunction("g_configs", "exists", std::bind(&ConfigManager::exists, &g_configs, _1));
|
||||||
g_lua.bindClassStaticFunction("g_configs", "remove", std::bind(&ConfigManager::remove, &g_configs, _1));
|
g_lua.bindClassStaticFunction("g_configs", "remove", std::bind(&ConfigManager::remove, &g_configs, _1));
|
||||||
|
g_lua.bindClassStaticFunction("g_configs", "setNode", std::bind(&ConfigManager::setNode, &g_configs, _1, _2));
|
||||||
|
g_lua.bindClassStaticFunction("g_configs", "addNode", std::bind(&ConfigManager::addNode, &g_configs, _1, _2));
|
||||||
|
g_lua.bindClassStaticFunction("g_configs", "getNode", std::bind(&ConfigManager::getNode, &g_configs, _1));
|
||||||
|
|
||||||
// PlatformWindow
|
// PlatformWindow
|
||||||
g_lua.registerStaticClass("g_window");
|
g_lua.registerStaticClass("g_window");
|
||||||
|
|
|
@ -264,7 +264,7 @@ bool luavalue_cast(int index, OTMLNodePtr& node)
|
||||||
std::string cnodeName = g_lua.toString(-2);
|
std::string cnodeName = g_lua.toString(-2);
|
||||||
if(g_lua.isTable()) {
|
if(g_lua.isTable()) {
|
||||||
OTMLNodePtr cnode;
|
OTMLNodePtr cnode;
|
||||||
if(luavalue_cast(-1, node)) {
|
if(luavalue_cast(-1, cnode)) {
|
||||||
cnode->setTag(cnodeName);
|
cnode->setTag(cnodeName);
|
||||||
node->addChild(cnode);
|
node->addChild(cnode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,10 @@ void Connection::write(uint8* buffer, uint16 size)
|
||||||
if(!m_connected)
|
if(!m_connected)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// send old buffer if we can't add more data
|
||||||
|
if(m_sendBufferSize + size >= SEND_BUFFER_SIZE && m_sendEvent)
|
||||||
|
m_sendEvent->execute();
|
||||||
|
|
||||||
// we can't send right, otherwise we could create tcp congestion
|
// we can't send right, otherwise we could create tcp congestion
|
||||||
memcpy(m_sendBuffer + m_sendBufferSize, buffer, size);
|
memcpy(m_sendBuffer + m_sendBufferSize, buffer, size);
|
||||||
m_sendBufferSize += size;
|
m_sendBufferSize += size;
|
||||||
|
@ -172,7 +176,6 @@ void Connection::onConnect(const boost::system::error_code& error)
|
||||||
m_connected = true;
|
m_connected = true;
|
||||||
|
|
||||||
// disable nagle's algorithm
|
// disable nagle's algorithm
|
||||||
//TODO: implement custom cache
|
|
||||||
boost::asio::ip::tcp::no_delay option(true);
|
boost::asio::ip::tcp::no_delay option(true);
|
||||||
m_socket.set_option(option);
|
m_socket.set_option(option);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue