Skip to content

Commit 85417c8

Browse files
committed
Try to send Lua function name when error
1 parent bd72f36 commit 85417c8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

engine/core/script/LuaFunctionBase.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,17 @@ void LuaFunctionBase::call(int args, int results) {
8181
#ifdef SUPERNOVA_CRASH_GUARD
8282
auto& crashHandler = FunctionSubscribeGlobal::getCrashHandler();
8383
if (crashHandler) {
84-
crashHandler("Lua Error", error);
84+
std::string funcName = "Lua Script Error";
85+
86+
// Try to get the actual function name from the call stack
87+
lua_Debug ar;
88+
if (lua_getstack(m_vm, 0, &ar) && lua_getinfo(m_vm, "n", &ar)) {
89+
if (ar.name && strlen(ar.name) > 0) {
90+
funcName = ar.name;
91+
}
92+
}
93+
94+
crashHandler(funcName, error);
8595
// Push nil values to satisfy the expected results count
8696
// This prevents stack underflow if the caller tries to retrieve return values
8797
for (int i = 0; i < results; i++) {

0 commit comments

Comments
 (0)