From 4cece439e86d9c653947452b50ed8bcdfdae3d69 Mon Sep 17 00:00:00 2001 From: Joel Barr Date: Mon, 27 Nov 2023 13:50:17 -0700 Subject: [PATCH] Fixed a bug where a missing Lua func would hit 2 error cases --- src/core/tracker.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/tracker.cpp b/src/core/tracker.cpp index 73f73acd..5dca52ff 100644 --- a/src/core/tracker.cpp +++ b/src/core/tracker.cpp @@ -98,6 +98,13 @@ static int RunLuaFunction_inner(lua_State *L, const std::string name) lua_sethook(L, lua_timeout_hook, LUA_MASKCOUNT, exec_limit); auto res = lua_pcall(L, argc, 1, -argc-2); lua_sethook(L, nullptr, 0, 0); + + if (res != LUA_OK) { + auto err = lua_tostring(L, -1); + fprintf(stderr, "Error running %s:\n%s\n", name.c_str(), err ? err : "Unknown error"); + lua_pop(L, 2); // error object, lua_error_handler + } + return res; } @@ -116,9 +123,7 @@ int Tracker::runLuaFunction(lua_State* L, const std::string name, int &out) { int callStatus = RunLuaFunction_inner(L, name); if (callStatus != LUA_OK) { - auto err = lua_tostring(L, -1); - fprintf(stderr, "Error running %s:\n%s\n", name.c_str(), err ? err : "Unknown error"); - lua_pop(L, 2); // error object, lua_error_handler + // RunLuaFunction_inner handles popping the stack in case of errors return callStatus; }