mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 12:04:55 +02:00
replace require with dofile, rename Hotkeys to Keyboard
This commit is contained in:
@@ -512,6 +512,22 @@ int LuaInterface::luaScriptLoader(lua_State* L)
|
||||
}
|
||||
}
|
||||
|
||||
int LuaInterface::luaScriptRunner(lua_State* L)
|
||||
{
|
||||
std::string fileName = g_lua.popString();
|
||||
if(!boost::ends_with(fileName, ".lua"))
|
||||
fileName += ".lua";
|
||||
|
||||
try {
|
||||
g_lua.loadScript(fileName);
|
||||
g_lua.call(0, LUA_MULTRET);
|
||||
return g_lua.stackSize();
|
||||
} catch(LuaException& e) {
|
||||
logError("failed to load script file '", fileName, "' :'", e.what());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int LuaInterface::luaErrorHandler(lua_State* L)
|
||||
{
|
||||
// pops the error message
|
||||
@@ -583,6 +599,10 @@ void LuaInterface::createLuaState()
|
||||
pushCFunction(&LuaInterface::luaScriptLoader);
|
||||
rawSeti(5);
|
||||
pop(2);
|
||||
|
||||
// replace dofile
|
||||
pushCFunction(&LuaInterface::luaScriptRunner);
|
||||
setGlobal("dofile");
|
||||
}
|
||||
|
||||
void LuaInterface::closeLuaState()
|
||||
|
@@ -186,6 +186,8 @@ public:
|
||||
private:
|
||||
/// Load scripts requested by lua 'require'
|
||||
static int luaScriptLoader(lua_State* L);
|
||||
/// Run scripts requested by lua 'dofile'
|
||||
static int luaScriptRunner(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