mirror of
https://github.com/love2d/love.git
synced 2026-08-14 01:20:56 +02:00
Add traceback information to the error string generated if a thread causes a Lua error.
--HG-- branch : minor
This commit is contained in:
@@ -130,6 +130,31 @@ void luax_printstack(lua_State *L)
|
||||
std::cout << i << " - " << luaL_typename(L, i) << std::endl;
|
||||
}
|
||||
|
||||
int luax_traceback(lua_State *L)
|
||||
{
|
||||
if (!lua_isstring(L, 1)) // 'message' not a string?
|
||||
return 1; // keep it intact
|
||||
|
||||
lua_getfield(L, LUA_GLOBALSINDEX, "debug");
|
||||
if (!lua_istable(L, -1))
|
||||
{
|
||||
lua_pop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_getfield(L, -1, "traceback");
|
||||
if (!lua_isfunction(L, -1))
|
||||
{
|
||||
lua_pop(L, 2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_pushvalue(L, 1); // pass error message
|
||||
lua_pushinteger(L, 2); // skip this function and traceback
|
||||
lua_call(L, 2, 1); // call debug.traceback
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool luax_isarrayoftables(lua_State *L, int idx)
|
||||
{
|
||||
if (!lua_istable(L, idx))
|
||||
|
||||
Reference in New Issue
Block a user