mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 15:14:08 +00:00
From Lua 5.2: Try __tostring metamethod on non-string error messages.
This commit is contained in:
parent
8e524d437e
commit
ff71394931
15
src/luajit.c
15
src/luajit.c
@ -93,8 +93,13 @@ static int report(lua_State *L, int status)
|
||||
|
||||
static int traceback(lua_State *L)
|
||||
{
|
||||
if (!lua_isstring(L, 1)) /* 'message' not a string? */
|
||||
return 1; /* keep it intact */
|
||||
if (!lua_isstring(L, 1)) { /* Non-string error object? Try metamethod. */
|
||||
if (lua_isnoneornil(L, 1) ||
|
||||
!luaL_callmeta(L, 1, "__tostring") ||
|
||||
!lua_isstring(L, -1))
|
||||
return 1; /* Return non-string error object. */
|
||||
lua_remove(L, 1); /* Replace object by result of __tostring metamethod. */
|
||||
}
|
||||
lua_getfield(L, LUA_GLOBALSINDEX, "debug");
|
||||
if (!lua_istable(L, -1)) {
|
||||
lua_pop(L, 1);
|
||||
@ -105,9 +110,9 @@ static int traceback(lua_State *L)
|
||||
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 */
|
||||
lua_pushvalue(L, 1); /* Push error message. */
|
||||
lua_pushinteger(L, 2); /* Skip this function and debug.traceback(). */
|
||||
lua_call(L, 2, 1); /* Call debug.traceback(). */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user