From 550be4b1f0a71b2d7883cf93a3d6a87c4e2ad86a Mon Sep 17 00:00:00 2001 From: Daid Date: Sun, 6 Feb 2022 14:58:57 +0100 Subject: [PATCH] Fixed https://github.com/daid/EmptyEpsilon/issues/1677 --- src/scriptInterface.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/scriptInterface.cpp b/src/scriptInterface.cpp index 393b5460..7210c7f0 100644 --- a/src/scriptInterface.cpp +++ b/src/scriptInterface.cpp @@ -28,6 +28,28 @@ static int irandom(lua_State* L) /// Generate a random number between the min and max value. REGISTER_SCRIPT_FUNCTION(irandom); +static int traceback(lua_State* L) +{ + string result; + int level = 1; + lua_Debug debug; + while (lua_getstack(L, level++, &debug)) { + lua_getinfo(L, "Slnt", &debug); + result += string(debug.source); + if (debug.currentline > 0) + result += ":" + string(debug.currentline); + if (debug.name && debug.name[0]) + result += ":" + string(debug.name); + result += "\n"; + } + lua_pushstring(L, result.c_str()); + return 1; +} +// traceback() +// Returns a string containing a list of function calls up to the current point. +// useful for debugging and error reporting. +REGISTER_SCRIPT_FUNCTION(traceback); + static int destroyScript(lua_State* L) { ScriptObject* obj = static_cast(lua_touserdata(L, lua_upvalueindex(1)));