replace require with dofile, rename Hotkeys to Keyboard

This commit is contained in:
Eduardo Bart
2012-02-06 02:39:52 -02:00
parent 64c9e4f1d5
commit f97104f12e
41 changed files with 284 additions and 126 deletions

View File

@@ -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()

View File

@@ -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