Use new coding style in game modules

Lots of refactoring and changes
Remove docs folder
This commit is contained in:
Eduardo Bart
2012-07-24 02:30:08 -03:00
parent 1c3e630237
commit c54cd1fdf1
69 changed files with 1629 additions and 2634 deletions

View File

@@ -70,6 +70,13 @@ bool Module::load()
if(m_sandboxed)
g_lua.resetGlobalEnvironment();
// add to package.loaded
g_lua.getGlobalField("package", "loaded");
g_lua.getRef(m_sandboxEnv);
g_lua.setField(m_name);
g_lua.pop();
m_loaded = true;
g_logger.debug(stdext::format("Loaded module '%s'", m_name));
} catch(stdext::exception& e) {
if(m_sandboxed)
@@ -78,7 +85,6 @@ bool Module::load()
return false;
}
m_loaded = true;
g_modules.updateModuleLoadOrder(asModule());
for(const std::string& modName : m_loadLaterModules) {
@@ -119,6 +125,12 @@ void Module::unload()
g_lua.clearTable();
g_lua.pop();
// remove from package.loaded
g_lua.getGlobalField("package", "loaded");
g_lua.pushNil();
g_lua.setField(m_name);
g_lua.pop();
m_loaded = false;
//g_logger.info(stdext::format("Unloaded module '%s'", m_name));
g_modules.updateModuleLoadOrder(asModule());

View File

@@ -930,18 +930,21 @@ void LuaInterface::setTable(int index)
void LuaInterface::clearTable(int index)
{
assert(hasIndex(index) && isTable(index));
pushNil();
pushNil(); // table, nil
bool stop = false;
while(!stop && next(index-1)) {
pop();
pushValue();
if(next(index-2))
pop();
else
stop = true;
insert(-2);
pushNil();
rawSet(index-3);
while(next(index-1)) { // table, key, value
pop(); // table, key
pushValue(); // table, key, key
if(next(index-2)) { // table, key, nextkey, value
pop(); // table, key, nextkey
insert(-2); // table, nextkey, key
pushNil(); // table, nextkey, key, nil
rawSet(index-3); // table, nextkey
} else { // table, key
pushNil(); // table, key, nil
rawSet(index-2); // table
break;
}
}
}

View File

@@ -191,10 +191,8 @@ void OTMLParser::parseNode(const std::string& data)
if(boost::starts_with(value, "[") && boost::ends_with(value, "]")) {
std::string tmp = value.substr(1, value.length()-2);
boost::tokenizer<boost::escaped_list_separator<char>> tokens(tmp);
for(std::string v : tokens) {
stdext::trim(v);
node->writeIn(v);
}
for(std::string v : tokens)
node->writeIn(stdext::trim(v));
} else
node->setValue(value);
}