mirror of
https://github.com/edubart/otclient.git
synced 2026-01-17 11:01:30 +01:00
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:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user