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 | |
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
-rw-r--r-- | engines/sword25/script/luascript.cpp | 24 | ||||
-rw-r--r-- | engines/sword25/sword25.cpp | 3 |
2 files changed, 27 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; diff --git a/engines/sword25/sword25.cpp b/engines/sword25/sword25.cpp index a1f3eb0f46..5a4e2bebad 100644 --- a/engines/sword25/sword25.cpp +++ b/engines/sword25/sword25.cpp @@ -33,6 +33,7 @@ */ #include "common/config-manager.h" +#include "common/debug-channels.h" #include "engines/util.h" #include "sword25/sword25.h" @@ -55,6 +56,8 @@ void LogToStdout(const char *Message) { Sword25Engine::Sword25Engine(OSystem *syst, const ADGameDescription *gameDesc): Engine(syst), _gameDescription(gameDesc) { + + DebugMan.addDebugChannel(kDebugScript, "Script", "Script debug level"); } Sword25Engine::~Sword25Engine() { |