Some thoughts on what might be wrong. You pass L for lua_pcall , and LuaErrorReport gets State() . They can work with different lua_State , which can happen, as in the context of a coroutine. If this is intentional, at least indicate why this is being done.
lua_pushvalue inside LuaErrorReport also looks suspicious. How do you know that the bottom value on the stack contains the message you are reporting? This function is called from other functions that can accumulate more values ββon the stack. I would either change this to
lua_pushvalue(L, -3);
or
lua_pushstring(L, msg);
Finally, you should also consider passing debug.traceback as an error function in lua_pcall to get a more meaningful stacktrace error message. Sort of:
void LUA::PerformCall(int return_amount) { lua_getglobal(L, "debug"); lua_getfield(L, -1, "traceback"); lua_remove(L, -2); int errindex = -p_iArgCount - 2; lua_insert(L, errindex); int error = lua_pcall(L, p_iArgCount, return_amount, errindex);
And get rid of the debug.trace call in LuaErrorReport .
source share