diff options
-rw-r--r-- | engines/hdb/lua-script.cpp | 20 | ||||
-rw-r--r-- | engines/hdb/lua-script.h | 1 |
2 files changed, 19 insertions, 2 deletions
diff --git a/engines/hdb/lua-script.cpp b/engines/hdb/lua-script.cpp index 79d164e525..8a79bdd1ed 100644 --- a/engines/hdb/lua-script.cpp +++ b/engines/hdb/lua-script.cpp @@ -644,7 +644,6 @@ bool LuaScript::initScript(Common::SeekableReadStream *stream, const char *scrip spawn names into Lua once they are implemented. */ - // Register panic callback function lua_atpanic(_state, panicCB); @@ -696,7 +695,6 @@ bool LuaScript::initScript(Common::SeekableReadStream *stream, const char *scrip return false; } - // Error handling function to be executed after the function is put on the stack lua_rawgeti(_state, LUA_REGISTRYINDEX, _pcallErrorhandlerRegistryIndex); lua_insert(_state, -2); @@ -713,6 +711,24 @@ bool LuaScript::initScript(Common::SeekableReadStream *stream, const char *scrip return true; } +bool LuaScript::callFunction(const char *name, int returns) { + + if (!_systemInit) { + return false; + } + + lua_getglobal(_state, name); + + if (lua_pcall(_state, 0, 0, -2)) { + error("An error occured while executing \"%s\": %s.", name, lua_tostring(_state, -1)); + lua_pop(_state, -1); + + return false; + } + + return true; +} + bool LuaScript::executeMPC(Common::SeekableReadStream *stream, const char *name, const char *scriptName, int32 length) { if (!_systemInit) { diff --git a/engines/hdb/lua-script.h b/engines/hdb/lua-script.h index 2a8686f96c..ea209a383c 100644 --- a/engines/hdb/lua-script.h +++ b/engines/hdb/lua-script.h @@ -39,6 +39,7 @@ public: bool init(); bool initScript(Common::SeekableReadStream *stream, const char *scriptName, int32 length); + bool callFunction(const char *name, int returns); bool executeMPC(Common::SeekableReadStream *stream, const char *name, const char *scriptName, int32 length); bool executeFile(const Common::String &filename); |