diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/luajit.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/luajit.c b/src/luajit.c index 0860248b..ecf4ef26 100644 --- a/src/luajit.c +++ b/src/luajit.c | |||
| @@ -93,8 +93,13 @@ static int report(lua_State *L, int status) | |||
| 93 | 93 | ||
| 94 | static int traceback(lua_State *L) | 94 | static int traceback(lua_State *L) |
| 95 | { | 95 | { |
| 96 | if (!lua_isstring(L, 1)) /* 'message' not a string? */ | 96 | if (!lua_isstring(L, 1)) { /* Non-string error object? Try metamethod. */ |
| 97 | return 1; /* keep it intact */ | 97 | if (lua_isnoneornil(L, 1) || |
| 98 | !luaL_callmeta(L, 1, "__tostring") || | ||
| 99 | !lua_isstring(L, -1)) | ||
| 100 | return 1; /* Return non-string error object. */ | ||
| 101 | lua_remove(L, 1); /* Replace object by result of __tostring metamethod. */ | ||
| 102 | } | ||
| 98 | lua_getfield(L, LUA_GLOBALSINDEX, "debug"); | 103 | lua_getfield(L, LUA_GLOBALSINDEX, "debug"); |
| 99 | if (!lua_istable(L, -1)) { | 104 | if (!lua_istable(L, -1)) { |
| 100 | lua_pop(L, 1); | 105 | lua_pop(L, 1); |
| @@ -105,9 +110,9 @@ static int traceback(lua_State *L) | |||
| 105 | lua_pop(L, 2); | 110 | lua_pop(L, 2); |
| 106 | return 1; | 111 | return 1; |
| 107 | } | 112 | } |
| 108 | lua_pushvalue(L, 1); /* pass error message */ | 113 | lua_pushvalue(L, 1); /* Push error message. */ |
| 109 | lua_pushinteger(L, 2); /* skip this function and traceback */ | 114 | lua_pushinteger(L, 2); /* Skip this function and debug.traceback(). */ |
| 110 | lua_call(L, 2, 1); /* call debug.traceback */ | 115 | lua_call(L, 2, 1); /* Call debug.traceback(). */ |
| 111 | return 1; | 116 | return 1; |
| 112 | } | 117 | } |
| 113 | 118 | ||
