diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-04-26 17:39:38 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-04-26 17:39:38 -0300 |
| commit | 4eb49163c662e7c1546754774acf75b893ea23df (patch) | |
| tree | e7745d5283a0282af13568fc1c008d0adb8f4ce1 /ldblib.c | |
| parent | 79cb336d74697ca38d6d2f2068781086cfaa9076 (diff) | |
| download | lua-4eb49163c662e7c1546754774acf75b893ea23df.tar.gz lua-4eb49163c662e7c1546754774acf75b893ea23df.tar.bz2 lua-4eb49163c662e7c1546754774acf75b893ea23df.zip | |
error handler in 'lua.c' tries '__tostring' metamethod if error
message is not a string
Diffstat (limited to 'ldblib.c')
| -rw-r--r-- | ldblib.c | 23 |
1 files changed, 10 insertions, 13 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldblib.c,v 1.104 2005/12/29 15:32:11 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.105 2006/09/11 14:07:24 roberto Exp roberto $ |
| 3 | ** Interface from Lua to its debug API | 3 | ** Interface from Lua to its debug API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -319,21 +319,18 @@ static int db_debug (lua_State *L) { | |||
| 319 | #define LEVELS2 10 /* size of the second part of the stack */ | 319 | #define LEVELS2 10 /* size of the second part of the stack */ |
| 320 | 320 | ||
| 321 | static int db_errorfb (lua_State *L) { | 321 | static int db_errorfb (lua_State *L) { |
| 322 | int level; | 322 | lua_Debug ar; |
| 323 | int firstpart = 1; /* still before eventual `...' */ | 323 | int firstpart = 1; /* still before eventual `...' */ |
| 324 | int arg; | 324 | int arg; |
| 325 | lua_State *L1 = getthread(L, &arg); | 325 | lua_State *L1 = getthread(L, &arg); |
| 326 | lua_Debug ar; | 326 | const char *msg = lua_tostring(L, arg + 1); |
| 327 | if (lua_isnumber(L, arg+2)) { | 327 | int level = (lua_isnumber(L, arg + 2)) ? |
| 328 | level = (int)lua_tointeger(L, arg+2); | 328 | (int)lua_tointeger(L, arg + 2) : |
| 329 | lua_pop(L, 1); | 329 | (L == L1) ? 1 : 0; /* level 0 may be this own function */ |
| 330 | } | 330 | lua_settop(L, ++arg); |
| 331 | else | 331 | if (msg) lua_pushfstring(L, "%s\n", msg); |
| 332 | level = (L == L1) ? 1 : 0; /* level 0 may be this own function */ | 332 | else if (!lua_isnil(L, arg)) /* is there a non-string 'msg'? */ |
| 333 | if (lua_gettop(L) == arg) | 333 | return 1; /* return it untouched */ |
| 334 | lua_pushliteral(L, ""); | ||
| 335 | else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ | ||
| 336 | else lua_pushliteral(L, "\n"); | ||
| 337 | lua_pushliteral(L, "stack traceback:"); | 334 | lua_pushliteral(L, "stack traceback:"); |
| 338 | while (lua_getstack(L1, level++, &ar)) { | 335 | while (lua_getstack(L1, level++, &ar)) { |
| 339 | if (level > LEVELS1 && firstpart) { | 336 | if (level > LEVELS1 && firstpart) { |
