new scripting functionality

* dofiles functions to run all scripts inside a directory
* new style option ! that evaluates its value from a lua code
This commit is contained in:
Eduardo Bart
2012-04-26 12:11:03 -03:00
parent 243bd3a930
commit fae2cc6481
5 changed files with 44 additions and 28 deletions

View File

@@ -536,6 +536,24 @@ int LuaInterface::luaScriptRunner(lua_State* L)
}
}
int LuaInterface::luaScriptsRunner(lua_State* L)
{
std::string directory = g_lua.popString();
for(const std::string& fileName : g_resources.listDirectoryFiles(directory)) {
if(!boost::ends_with(fileName, ".lua"))
continue;
try {
g_lua.loadScript(directory + "/" + fileName);
g_lua.call(0, 0);
} catch(LuaException& e) {
logError("failed to load script file '", fileName, "' :'", e.what());
}
}
return 0;
}
int LuaInterface::luaErrorHandler(lua_State* L)
{
// pops the error message
@@ -614,6 +632,10 @@ void LuaInterface::createLuaState()
// replace dofile
pushCFunction(&LuaInterface::luaScriptRunner);
setGlobal("dofile");
// dofiles
pushCFunction(&LuaInterface::luaScriptsRunner);
setGlobal("dofiles");
}
void LuaInterface::closeLuaState()

View File

@@ -188,6 +188,8 @@ private:
static int luaScriptLoader(lua_State* L);
/// Run scripts requested by lua 'dofile'
static int luaScriptRunner(lua_State* L);
/// Run scripts requested by lua 'dofiles'
static int luaScriptsRunner(lua_State* L);
/// Handle lua errors from safeCall
static int luaErrorHandler(lua_State* L);
/// Handle bound cpp functions callbacks