diff options
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 45 |
1 files changed, 35 insertions, 10 deletions
@@ -1,11 +1,12 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 1.118 2002/06/06 18:17:33 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.119 2002/06/13 13:39:55 roberto Exp roberto $ |
3 | ** Debug Interface | 3 | ** Debug Interface |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
6 | 6 | ||
7 | 7 | ||
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <string.h> | ||
9 | 10 | ||
10 | #include "lua.h" | 11 | #include "lua.h" |
11 | 12 | ||
@@ -510,18 +511,42 @@ void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) { | |||
510 | } | 511 | } |
511 | 512 | ||
512 | 513 | ||
514 | static void addinfo (lua_State *L, int internal) { | ||
515 | CallInfo *ci = (internal) ? L->ci : L->ci - 1; | ||
516 | const char *msg = svalue(L->top - 1); | ||
517 | if (strchr(msg, '\n')) return; /* message already `formatted' */ | ||
518 | if (!isLmark(ci)) { /* no Lua code? */ | ||
519 | luaO_pushfstring(L, "%s\n", msg); /* no extra info */ | ||
520 | } | ||
521 | else { /* add file:line information */ | ||
522 | char buff[LUA_IDSIZE]; | ||
523 | int line = currentline(L, ci); | ||
524 | luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); | ||
525 | luaO_pushfstring(L, "%s:%d: %s\n", buff, line, msg); | ||
526 | } | ||
527 | } | ||
528 | |||
529 | |||
530 | void luaG_errormsg (lua_State *L, int internal) { | ||
531 | const TObject *errfunc; | ||
532 | if (ttype(L->top - 1) == LUA_TSTRING) | ||
533 | addinfo(L, internal); | ||
534 | errfunc = luaH_getstr(hvalue(registry(L)), luaS_new(L, LUA_TRACEBACK)); | ||
535 | if (ttype(errfunc) != LUA_TNIL) { /* is there an error function? */ | ||
536 | setobj(L->top, errfunc); /* push function */ | ||
537 | setobj(L->top + 1, L->top - 1); /* push error message */ | ||
538 | L->top += 2; | ||
539 | luaD_call(L, L->top - 2, 1); /* call error function? */ | ||
540 | } | ||
541 | luaD_throw(L, LUA_ERRRUN); | ||
542 | } | ||
543 | |||
544 | |||
513 | void luaG_runerror (lua_State *L, const char *fmt, ...) { | 545 | void luaG_runerror (lua_State *L, const char *fmt, ...) { |
514 | const char *msg; | ||
515 | va_list argp; | 546 | va_list argp; |
516 | va_start(argp, fmt); | 547 | va_start(argp, fmt); |
517 | msg = luaO_pushvfstring(L, fmt, argp); | 548 | luaO_pushvfstring(L, fmt, argp); |
518 | va_end(argp); | 549 | va_end(argp); |
519 | if (isLmark(L->ci)) { | 550 | luaG_errormsg(L, 1); |
520 | char buff[LUA_IDSIZE]; | ||
521 | int line = currentline(L, L->ci); | ||
522 | luaO_chunkid(buff, getstr(getluaproto(L->ci)->source), LUA_IDSIZE); | ||
523 | msg = luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); | ||
524 | } | ||
525 | luaD_error(L, msg, LUA_ERRRUN); | ||
526 | } | 551 | } |
527 | 552 | ||