diff options
author | Eugene Sandulenko | 2010-08-21 19:25:37 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2010-10-12 23:09:53 +0000 |
commit | c875856d20f4963f5f20ceb8cf8f71d81b5d6036 (patch) | |
tree | 98e380a42f07301fa5fff7dd5547e4ae42c72064 /engines/sword25/script | |
parent | 4d678fc3b834d455f29f0f5734d9794969485db3 (diff) | |
download | scummvm-rg350-c875856d20f4963f5f20ceb8cf8f71d81b5d6036.tar.gz scummvm-rg350-c875856d20f4963f5f20ceb8cf8f71d81b5d6036.tar.bz2 scummvm-rg350-c875856d20f4963f5f20ceb8cf8f71d81b5d6036.zip |
SWORD25: Implemented script tracing
To turn on traces turn on debugchannel 'script' and then use
debug level as a bitmask:
1 - show function calls
2 - show function exits
3 - show every line
svn-id: r53267
Diffstat (limited to 'engines/sword25/script')
-rw-r--r-- | engines/sword25/script/luascript.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/engines/sword25/script/luascript.cpp b/engines/sword25/script/luascript.cpp index f3b98a5c16..c6508c325f 100644 --- a/engines/sword25/script/luascript.cpp +++ b/engines/sword25/script/luascript.cpp @@ -39,6 +39,9 @@ // ----------------------------------------------------------------------------- #include "common/array.h" +#include "common/debug-channels.h" + +#include "sword25/sword25.h" #include "sword25/package/packagemanager.h" #include "sword25/script/luascript.h" #include "sword25/script/luabindhelper.h" @@ -92,6 +95,13 @@ int PanicCB(lua_State *L) { BS_LOG_ERRORLN("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); +} } // ----------------------------------------------------------------------------- @@ -139,6 +149,20 @@ bool LuaScriptEngine::Init() { luaopen_pluto(m_State); lua_pop(m_State, 1); + // Initialize debugging callback + if (DebugMan.isDebugChannelEnabled(kDebugScript)) { + int mask = 0; + if (gDebugLevel == 1) + mask |= LUA_MASKCALL; + if (gDebugLevel == 2) + mask |= LUA_MASKRET; + if (gDebugLevel == 4) + mask |= LUA_MASKLINE; + + if (mask != 0) + lua_sethook(m_State, debugHook, mask, 0); + } + BS_LOGLN("Lua initialized."); return true; |