aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorEugene Sandulenko2019-06-06 01:14:16 +0200
committerEugene Sandulenko2019-09-03 17:16:43 +0200
commit656e67db699b750f2cd20e669d90611a55022b92 (patch)
treebe8ecafe026251198e02276db429d391f02107f1 /engines
parent93faee87c3196aed72c66013d9cff710c949eb53 (diff)
downloadscummvm-rg350-656e67db699b750f2cd20e669d90611a55022b92.tar.gz
scummvm-rg350-656e67db699b750f2cd20e669d90611a55022b92.tar.bz2
scummvm-rg350-656e67db699b750f2cd20e669d90611a55022b92.zip
HDB: Move debugging facilities earlier in the code
Diffstat (limited to 'engines')
-rw-r--r--engines/hdb/lua-script.cpp87
1 files changed, 45 insertions, 42 deletions
diff --git a/engines/hdb/lua-script.cpp b/engines/hdb/lua-script.cpp
index 9751f73968..3ca4e73e57 100644
--- a/engines/hdb/lua-script.cpp
+++ b/engines/hdb/lua-script.cpp
@@ -572,6 +572,21 @@ struct FuncInit {
{ NULL, NULL }
};
+namespace {
+int panicCB(lua_State *L) {
+ error("Lua panic. Error message: %s", lua_isnil(L, -1) ? "" : lua_tostring(L, -1));
+ return 0;
+}
+
+void debugHook(lua_State *L, lua_Debug *ar) {
+ if (!lua_getinfo(L, "Sn", ar))
+ return;
+
+ debug("LUA: %s %s: %s %d", ar->namewhat, ar->name, ar->short_src, ar->currentline);
+}
+}
+
+
bool LuaScript::initScript(Common::SeekableReadStream *stream, int32 length) {
if (_systemInit) {
@@ -619,6 +634,35 @@ bool LuaScript::initScript(Common::SeekableReadStream *stream, int32 length) {
spawn names into Lua once they are implemented.
*/
+
+ lua_atpanic(_state, panicCB);
+
+ const char errorHandlerCode[] =
+ "local function ErrorHandler(message) "
+ " return message .. '\\n' .. debug.traceback('', 2) "
+ "end "
+ "return ErrorHandler";
+
+ if (luaL_loadbuffer(_state, errorHandlerCode, strlen(errorHandlerCode), "PCALL ERRORHANDLER") != 0) {
+ // An error occurred, so dislay the reason and exit
+ error("Couldn't compile luaL_pcall errorhandler:\n%s", lua_tostring(_state, -1));
+ lua_pop(_state, 1);
+
+ return false;
+ }
+
+
+ // Running the code, the error handler function sets the top of the stack
+ if (lua_pcall(_state, 0, 1, 0) != 0) {
+ // An error occurred, so dislay the reason and exit
+ error("Couldn't prepare luaL_pcall errorhandler:\n%s", lua_tostring(_state, -1));
+ lua_pop(_state, 1);
+
+ return false;
+ }
+
+ lua_sethook(_state, debugHook, LUA_MASKCALL | LUA_MASKLINE, 0);
+
// Load GLOBAL_LUA and execute it
if (!executeMPC(_globalLuaStream, "global code", _globalLuaLength)) {
@@ -639,6 +683,7 @@ bool LuaScript::initScript(Common::SeekableReadStream *stream, int32 length) {
return true;
}
+
bool LuaScript::executeMPC(Common::SeekableReadStream *stream, const char *name, int32 length) {
if (!_systemInit) {
@@ -696,54 +741,12 @@ bool LuaScript::executeFile(const Common::String &filename) {
}
#endif
-namespace {
-int panicCB(lua_State *L) {
- error("Lua panic. Error message: %s", lua_isnil(L, -1) ? "" : lua_tostring(L, -1));
- return 0;
-}
-
-void debugHook(lua_State *L, lua_Debug *ar) {
- if (!lua_getinfo(L, "Sn", ar))
- return;
-
- debug("LUA: %s %s: %s %d", ar->namewhat, ar->name, ar->short_src, ar->currentline);
-}
-}
-
bool LuaScript::executeChunk(const char *chunk, uint chunkSize, const Common::String &chunkName) const {
if (!_systemInit) {
return false;
}
- lua_atpanic(_state, panicCB);
-
- const char errorHandlerCode[] =
- "local function ErrorHandler(message) "
- " return message .. '\\n' .. debug.traceback('', 2) "
- "end "
- "return ErrorHandler";
-
- if (luaL_loadbuffer(_state, errorHandlerCode, strlen(errorHandlerCode), "PCALL ERRORHANDLER") != 0) {
- // An error occurred, so dislay the reason and exit
- error("Couldn't compile luaL_pcall errorhandler:\n%s", lua_tostring(_state, -1));
- lua_pop(_state, 1);
-
- return false;
- }
-
-
- // Running the code, the error handler function sets the top of the stack
- if (lua_pcall(_state, 0, 1, 0) != 0) {
- // An error occurred, so dislay the reason and exit
- error("Couldn't prepare luaL_pcall errorhandler:\n%s", lua_tostring(_state, -1));
- lua_pop(_state, 1);
-
- return false;
- }
-
- lua_sethook(_state, debugHook, LUA_MASKCALL | LUA_MASKLINE, 0);
-
// Compile Chunk
if (luaL_loadbuffer(_state, chunk, chunkSize, chunkName.c_str())) {
error("Couldn't compile \"%s\": %s", chunkName.c_str(), lua_tostring(_state, -1));