diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-05-22 14:45:56 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-05-22 14:45:56 -0300 |
| commit | 6142e663e4d3180d2afaea50bd0978a040f518a4 (patch) | |
| tree | 55d789eb4fa54dba3bf936b7f9ea5751ad4742fa | |
| parent | 6dc20ff293239efd59ec8be7d14a31af084e28d5 (diff) | |
| download | lua-6142e663e4d3180d2afaea50bd0978a040f518a4.tar.gz lua-6142e663e4d3180d2afaea50bd0978a040f518a4.tar.bz2 lua-6142e663e4d3180d2afaea50bd0978a040f518a4.zip | |
reuse of 'addinfo' by lexical errors
| -rw-r--r-- | ldebug.c | 29 | ||||
| -rw-r--r-- | ldebug.h | 4 | ||||
| -rw-r--r-- | llex.c | 7 |
3 files changed, 21 insertions, 19 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 2.113 2015/03/11 16:10:41 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.114 2015/03/28 19:14:47 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 | */ |
| @@ -599,19 +599,16 @@ l_noret luaG_ordererror (lua_State *L, const TValue *p1, const TValue *p2) { | |||
| 599 | } | 599 | } |
| 600 | 600 | ||
| 601 | 601 | ||
| 602 | static void addinfo (lua_State *L, const char *msg) { | 602 | /* add src:line information to 'msg' */ |
| 603 | CallInfo *ci = L->ci; | 603 | const char *luaG_addinfo (lua_State *L, const char *msg, TString *src, |
| 604 | if (isLua(ci)) { /* is Lua code? */ | 604 | int line) { |
| 605 | char buff[LUA_IDSIZE]; /* add file:line information */ | 605 | char buff[LUA_IDSIZE]; |
| 606 | int line = currentline(ci); | 606 | if (src) |
| 607 | TString *src = ci_func(ci)->p->source; | 607 | luaO_chunkid(buff, getstr(src), LUA_IDSIZE); |
| 608 | if (src) | 608 | else { /* no source available; use "?" instead */ |
| 609 | luaO_chunkid(buff, getstr(src), LUA_IDSIZE); | 609 | buff[0] = '?'; buff[1] = '\0'; |
| 610 | else { /* no source available; use "?" instead */ | ||
| 611 | buff[0] = '?'; buff[1] = '\0'; | ||
| 612 | } | ||
| 613 | luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); | ||
| 614 | } | 610 | } |
| 611 | return luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); | ||
| 615 | } | 612 | } |
| 616 | 613 | ||
| 617 | 614 | ||
| @@ -628,10 +625,14 @@ l_noret luaG_errormsg (lua_State *L) { | |||
| 628 | 625 | ||
| 629 | 626 | ||
| 630 | l_noret luaG_runerror (lua_State *L, const char *fmt, ...) { | 627 | l_noret luaG_runerror (lua_State *L, const char *fmt, ...) { |
| 628 | CallInfo *ci = L->ci; | ||
| 629 | const char *msg; | ||
| 631 | va_list argp; | 630 | va_list argp; |
| 632 | va_start(argp, fmt); | 631 | va_start(argp, fmt); |
| 633 | addinfo(L, luaO_pushvfstring(L, fmt, argp)); | 632 | msg = luaO_pushvfstring(L, fmt, argp); /* format message */ |
| 634 | va_end(argp); | 633 | va_end(argp); |
| 634 | if (isLua(ci)) /* if Lua function, add source:line information */ | ||
| 635 | luaG_addinfo(L, msg, ci_func(ci)->p->source, currentline(ci)); | ||
| 635 | luaG_errormsg(L); | 636 | luaG_errormsg(L); |
| 636 | } | 637 | } |
| 637 | 638 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.h,v 2.12 2014/11/10 14:46:05 roberto Exp roberto $ | 2 | ** $Id: ldebug.h,v 2.13 2015/03/11 16:10:41 roberto Exp roberto $ |
| 3 | ** Auxiliary functions from Debug Interface module | 3 | ** Auxiliary functions from Debug Interface module |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -30,6 +30,8 @@ LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, | |||
| 30 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, | 30 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, |
| 31 | const TValue *p2); | 31 | const TValue *p2); |
| 32 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); | 32 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); |
| 33 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, | ||
| 34 | TString *src, int line); | ||
| 33 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); | 35 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); |
| 34 | LUAI_FUNC void luaG_traceexec (lua_State *L); | 36 | LUAI_FUNC void luaG_traceexec (lua_State *L); |
| 35 | 37 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 2.91 2015/03/28 19:14:47 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.92 2015/04/03 18:41:57 roberto Exp roberto $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -16,6 +16,7 @@ | |||
| 16 | #include "lua.h" | 16 | #include "lua.h" |
| 17 | 17 | ||
| 18 | #include "lctype.h" | 18 | #include "lctype.h" |
| 19 | #include "ldebug.h" | ||
| 19 | #include "ldo.h" | 20 | #include "ldo.h" |
| 20 | #include "lgc.h" | 21 | #include "lgc.h" |
| 21 | #include "llex.h" | 22 | #include "llex.h" |
| @@ -106,9 +107,7 @@ static const char *txtToken (LexState *ls, int token) { | |||
| 106 | 107 | ||
| 107 | 108 | ||
| 108 | static l_noret lexerror (LexState *ls, const char *msg, int token) { | 109 | static l_noret lexerror (LexState *ls, const char *msg, int token) { |
| 109 | char buff[LUA_IDSIZE]; | 110 | msg = luaG_addinfo(ls->L, msg, ls->source, ls->linenumber); |
| 110 | luaO_chunkid(buff, getstr(ls->source), LUA_IDSIZE); | ||
| 111 | msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); | ||
| 112 | if (token) | 111 | if (token) |
| 113 | luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token)); | 112 | luaO_pushfstring(ls->L, "%s near %s", msg, txtToken(ls, token)); |
| 114 | luaD_throw(ls->L, LUA_ERRSYNTAX); | 113 | luaD_throw(ls->L, LUA_ERRSYNTAX); |
