Skip to content

Commit

Permalink
Fixed a bug where a missing Lua func would hit 2 error cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JBarrows authored and black-sliver committed Nov 28, 2023
1 parent 6456742 commit 4cece43
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/core/tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 4cece43

Please sign in to comment.