From 49b0f7c6d21c8c94bdac3963c181ebc7f4e5ccb8 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 16 Jul 2019 23:59:42 +0200 Subject: HDB: Normalised usage of _systemInit for Lua --- engines/hdb/lua-script.cpp | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'engines/hdb') diff --git a/engines/hdb/lua-script.cpp b/engines/hdb/lua-script.cpp index 797e030af7..1160d000d7 100644 --- a/engines/hdb/lua-script.cpp +++ b/engines/hdb/lua-script.cpp @@ -86,10 +86,12 @@ bool LuaScript::loadLua(const char *name) { if (luaStream == NULL) { warning("The %s MPC entry can't be found", name); + _systemInit = false; + return false; } - initScript(luaStream, name, luaLength); + _systemInit = initScript(luaStream, name, luaLength); return true; } @@ -1706,7 +1708,7 @@ void debugHook(lua_State *L, lua_Debug *ar) { } bool LuaScript::initScript(Common::SeekableReadStream *stream, const char *scriptName, int32 length) { - if (_systemInit) { + if (_state != NULL) { lua_close(_state); } @@ -1718,8 +1720,6 @@ bool LuaScript::initScript(Common::SeekableReadStream *stream, const char *scrip } luaL_openlibs(_state); - _systemInit = true; - // Register Extensions for (int i = 0; luaFuncs[i].luaName; i++) { lua_register(_state, luaFuncs[i].luaName, luaFuncs[i].function); @@ -1915,11 +1915,6 @@ void LuaScript::invokeLuaFunction(char *luaFunc, int x, int y, int value1, int v } bool LuaScript::executeMPC(Common::SeekableReadStream *stream, const char *name, const char *scriptName, int32 length) { - - if (!_systemInit) { - return false; - } - char *chunk = new char[length + 1]; stream->read((void *)chunk, length); chunk[length] = '\0'; // be on the safe side @@ -1946,11 +1941,6 @@ bool LuaScript::executeMPC(Common::SeekableReadStream *stream, const char *name, } bool LuaScript::executeFile(const Common::String &filename) { - - if (!_systemInit) { - return false; - } - Common::File *file = new Common::File; if (!file->open(filename)) { @@ -1982,11 +1972,6 @@ bool LuaScript::executeFile(const Common::String &filename) { } bool LuaScript::executeChunk(Common::String &chunk, const Common::String &chunkName) const { - - if (!_systemInit) { - return false; - } - // Compile Chunk if (luaL_loadbuffer(_state, chunk.c_str(), chunk.size(), chunkName.c_str())) { error("Couldn't compile \"%s\": %s", chunkName.c_str(), lua_tostring(_state, -1)); -- cgit v1.2.3