From f9beeb66d3674c86c51674577b2b13b13540ba8a Mon Sep 17 00:00:00 2001 From: Nipun Garg Date: Thu, 6 Jun 2019 03:41:38 +0530 Subject: HDB: Add init() to load the GLOBAL_LUA code --- engines/hdb/lua-script.cpp | 25 +++++++++++-------------- engines/hdb/lua-script.h | 2 ++ 2 files changed, 13 insertions(+), 14 deletions(-) (limited to 'engines/hdb') diff --git a/engines/hdb/lua-script.cpp b/engines/hdb/lua-script.cpp index 79d4afb362..184ff474dd 100644 --- a/engines/hdb/lua-script.cpp +++ b/engines/hdb/lua-script.cpp @@ -40,20 +40,19 @@ LuaScript::~LuaScript() { } } -#if 0 + bool LuaScript::init() { - // Create new lua_State and initialize the Std Libs - _state = luaL_newstate(); - if (!_state || !registerStdLibs()) { - error("Cannot initialize Lua"); + // Load Global Lua Code + _globalLuaStream = g_hdb->fileMan->findFirstData("GLOBAL_LUA", TYPE_BINARY); + _globalLuaLength = g_hdb->fileMan->getLength("GLOBAL_LUA", TYPE_BINARY); + if (_globalLuaStream == NULL || _globalLuaLength == 0) { + error("LuaScript::initScript: 'global code' failed to load"); return false; } - _systemInit = true; - return true; } -#endif + /* Called from Lua, this will pop into the menu @@ -622,12 +621,10 @@ bool LuaScript::initScript(Common::SeekableReadStream *stream, int32 length) { // Load GLOBAL_LUA and execute it - g_hdb->fileMan->findFirstData("GLOBAL_LUA", TYPE_BINARY); - - //if (!executeMPC(globalStream, "global code", globalLength)) { - // error("LuaScript::initScript: 'global code' failed to execute"); - // return false; - //} + if (!executeMPC(_globalLuaStream, "global code", _globalLuaLength)) { + error("LuaScript::initScript: 'global code' failed to execute"); + return false; + } // Load script and execute it diff --git a/engines/hdb/lua-script.h b/engines/hdb/lua-script.h index eee51cd396..ec7213315e 100644 --- a/engines/hdb/lua-script.h +++ b/engines/hdb/lua-script.h @@ -44,6 +44,8 @@ public: private: lua_State *_state; + Common::SeekableReadStream* _globalLuaStream; + int32 _globalLuaLength; bool _systemInit; bool registerExtensions(); -- cgit v1.2.3