aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/sword25/script/luascript.cpp24
-rw-r--r--engines/sword25/sword25.cpp3
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() {