diff options
author | Mike Pall <mike> | 2012-02-13 20:08:29 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2012-02-13 20:08:29 +0100 |
commit | ff7139493196f8b43bc8912a9ea33d4d5e169796 (patch) | |
tree | c392953f617103e27a20487853c3d3a9baa26e12 /src | |
parent | 8e524d437e2e5e3a1d27351c0e18e97181c56328 (diff) | |
download | luajit-ff7139493196f8b43bc8912a9ea33d4d5e169796.tar.gz luajit-ff7139493196f8b43bc8912a9ea33d4d5e169796.tar.bz2 luajit-ff7139493196f8b43bc8912a9ea33d4d5e169796.zip |
From Lua 5.2: Try __tostring metamethod on non-string error messages.
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 | ||