diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-09-25 11:20:37 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-09-25 11:20:37 -0300 |
commit | 8ede2c353cddc8024f75802bb2ab714e334f1f8e (patch) | |
tree | c870e0d4b6a3f4fdee3136eac6e9b7c8462525da /lua.c | |
parent | 6384475ec4112361b0ab27de553e85863464b846 (diff) | |
download | lua-8ede2c353cddc8024f75802bb2ab714e334f1f8e.tar.gz lua-8ede2c353cddc8024f75802bb2ab714e334f1f8e.tar.bz2 lua-8ede2c353cddc8024f75802bb2ab714e334f1f8e.zip |
detail in 'report' + message handler always is called with an
argument + 'report' already handles non-string error messages
Diffstat (limited to 'lua.c')
-rw-r--r-- | lua.c | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.212 2014/06/26 17:08:52 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.213 2014/06/30 19:48:08 roberto Exp roberto $ |
3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -164,9 +164,9 @@ static void l_message (const char *pname, const char *msg) { | |||
164 | */ | 164 | */ |
165 | static int report (lua_State *L, int status) { | 165 | static int report (lua_State *L, int status) { |
166 | if (status != LUA_OK) { | 166 | if (status != LUA_OK) { |
167 | const char *msg = (lua_type(L, -1) == LUA_TSTRING) ? lua_tostring(L, -1) | 167 | const char *msg = (lua_type(L, -1) == LUA_TSTRING) |
168 | : NULL; | 168 | ? lua_tostring(L, -1) |
169 | if (msg == NULL) msg = "(error object is not a string)"; | 169 | : "(error object is not a string)"; |
170 | l_message(progname, msg); | 170 | l_message(progname, msg); |
171 | lua_pop(L, 1); | 171 | lua_pop(L, 1); |
172 | } | 172 | } |
@@ -181,10 +181,9 @@ static int msghandler (lua_State *L) { | |||
181 | const char *msg = lua_tostring(L, 1); | 181 | const char *msg = lua_tostring(L, 1); |
182 | if (msg) /* is error object a string? */ | 182 | if (msg) /* is error object a string? */ |
183 | luaL_traceback(L, L, msg, 1); /* use standard traceback */ | 183 | luaL_traceback(L, L, msg, 1); /* use standard traceback */ |
184 | else if (!lua_isnoneornil(L, 1)) { /* non-string error object? */ | 184 | else /* non-string error object */ |
185 | if (!luaL_callmeta(L, 1, "__tostring")) /* try its 'tostring' metamethod */ | 185 | luaL_callmeta(L, 1, "__tostring"); /* try its 'tostring' metamethod */ |
186 | lua_pushliteral(L, "(no error message)"); | 186 | /* if no metamethod, original object still is in the stack */ |
187 | } /* else no error object, does nothing */ | ||
188 | return 1; | 187 | return 1; |
189 | } | 188 | } |
190 | 189 | ||