diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-08-08 17:08:41 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-08-08 17:08:41 -0300 |
| commit | 9998082839bfffe01d7b614ab61ad35629a2c356 (patch) | |
| tree | 3722acbcdda6fff4bdccc059c443618a59978726 | |
| parent | 08da48a73ce9ec8d0672c45f67ff32650e937477 (diff) | |
| download | lua-9998082839bfffe01d7b614ab61ad35629a2c356.tar.gz lua-9998082839bfffe01d7b614ab61ad35629a2c356.tar.bz2 lua-9998082839bfffe01d7b614ab61ad35629a2c356.zip | |
external messages add their own extra information
| -rw-r--r-- | lapi.c | 4 | ||||
| -rw-r--r-- | lauxlib.c | 18 | ||||
| -rw-r--r-- | lauxlib.h | 3 | ||||
| -rw-r--r-- | lbaselib.c | 13 | ||||
| -rw-r--r-- | ldebug.c | 17 | ||||
| -rw-r--r-- | ldebug.h | 4 |
6 files changed, 40 insertions, 19 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.209 2002/08/06 18:54:18 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.210 2002/08/07 14:24:24 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -695,7 +695,7 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { | |||
| 695 | LUA_API int lua_error (lua_State *L) { | 695 | LUA_API int lua_error (lua_State *L) { |
| 696 | lua_lock(L); | 696 | lua_lock(L); |
| 697 | api_checknelems(L, 1); | 697 | api_checknelems(L, 1); |
| 698 | luaG_errormsg(L, 0); | 698 | luaG_errormsg(L); |
| 699 | lua_unlock(L); | 699 | lua_unlock(L); |
| 700 | return 0; /* to avoid warnings */ | 700 | return 0; /* to avoid warnings */ |
| 701 | } | 701 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.81 2002/08/06 17:26:45 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.82 2002/08/06 18:01:50 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -62,11 +62,27 @@ static void tag_error (lua_State *L, int narg, int tag) { | |||
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | 64 | ||
| 65 | LUALIB_API void luaL_where (lua_State *L, int level) { | ||
| 66 | lua_Debug ar; | ||
| 67 | if (lua_getstack(L, level, &ar)) { /* check function at level */ | ||
| 68 | lua_getinfo(L, "Snl", &ar); /* get info about it */ | ||
| 69 | if (ar.currentline > 0) { /* is there info? */ | ||
| 70 | lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline); | ||
| 71 | return; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | lua_pushliteral(L, ""); /* else, no information available... */ | ||
| 75 | } | ||
| 76 | |||
| 77 | |||
| 65 | LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { | 78 | LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { |
| 66 | va_list argp; | 79 | va_list argp; |
| 67 | va_start(argp, fmt); | 80 | va_start(argp, fmt); |
| 81 | luaL_where(L, 1); | ||
| 68 | lua_pushvfstring(L, fmt, argp); | 82 | lua_pushvfstring(L, fmt, argp); |
| 69 | va_end(argp); | 83 | va_end(argp); |
| 84 | lua_pushliteral(L, "\n"); | ||
| 85 | lua_concat(L, 3); | ||
| 70 | return lua_error(L); | 86 | return lua_error(L); |
| 71 | } | 87 | } |
| 72 | 88 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.h,v 1.50 2002/06/25 19:15:21 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.51 2002/07/01 19:23:58 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -44,6 +44,7 @@ LUALIB_API void luaL_check_stack (lua_State *L, int space, const char *msg); | |||
| 44 | LUALIB_API void luaL_check_type (lua_State *L, int narg, int t); | 44 | LUALIB_API void luaL_check_type (lua_State *L, int narg, int t); |
| 45 | LUALIB_API void luaL_check_any (lua_State *L, int narg); | 45 | LUALIB_API void luaL_check_any (lua_State *L, int narg); |
| 46 | 46 | ||
| 47 | LUALIB_API void luaL_where (lua_State *L, int level); | ||
| 47 | LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...); | 48 | LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...); |
| 48 | 49 | ||
| 49 | LUALIB_API int luaL_findstring (const char *name, | 50 | LUALIB_API int luaL_findstring (const char *name, |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.95 2002/08/06 18:01:50 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.96 2002/08/06 18:54:18 roberto Exp roberto $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -75,7 +75,16 @@ static int luaB_tonumber (lua_State *L) { | |||
| 75 | 75 | ||
| 76 | 76 | ||
| 77 | static int luaB_error (lua_State *L) { | 77 | static int luaB_error (lua_State *L) { |
| 78 | int level = luaL_opt_int(L, 2, 1); | ||
| 78 | luaL_check_any(L, 1); | 79 | luaL_check_any(L, 1); |
| 80 | if (!lua_isstring(L, 1) || level == 0) | ||
| 81 | lua_pushvalue(L, 1); /* propagate error mesage without changes */ | ||
| 82 | else { /* add extra information */ | ||
| 83 | luaL_where(L, level); | ||
| 84 | lua_pushvalue(L, 1); | ||
| 85 | lua_pushliteral(L, "\n"); | ||
| 86 | lua_concat(L, 3); | ||
| 87 | } | ||
| 79 | return lua_error(L); | 88 | return lua_error(L); |
| 80 | } | 89 | } |
| 81 | 90 | ||
| @@ -285,7 +294,7 @@ static int luaB_unpack (lua_State *L) { | |||
| 285 | lua_rawget(L, 1); | 294 | lua_rawget(L, 1); |
| 286 | n = (lua_isnumber(L, -1)) ? (int)lua_tonumber(L, -1) : -1; | 295 | n = (lua_isnumber(L, -1)) ? (int)lua_tonumber(L, -1) : -1; |
| 287 | for (i=0; i<n || n==-1; i++) { /* push arg[1...n] */ | 296 | for (i=0; i<n || n==-1; i++) { /* push arg[1...n] */ |
| 288 | luaL_check_stack(L, 1, "table too big to unpack"); | 297 | luaL_check_stack(L, LUA_MINSTACK, "table too big to unpack"); |
| 289 | lua_rawgeti(L, 1, i+1); | 298 | lua_rawgeti(L, 1, i+1); |
| 290 | if (n == -1) { /* no explicit limit? */ | 299 | if (n == -1) { /* no explicit limit? */ |
| 291 | if (lua_isnil(L, -1)) { /* stop at first `nil' element */ | 300 | if (lua_isnil(L, -1)) { /* stop at first `nil' element */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.c,v 1.129 2002/08/07 14:35:55 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 1.130 2002/08/07 19:22:39 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 | */ |
| @@ -518,13 +518,10 @@ int luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) { | |||
| 518 | } | 518 | } |
| 519 | 519 | ||
| 520 | 520 | ||
| 521 | static void addinfo (lua_State *L, int internal) { | 521 | static void addinfo (lua_State *L, const char *msg) { |
| 522 | const char *msg = svalue(L->top - 1); | ||
| 523 | CallInfo *ci = L->ci; | 522 | CallInfo *ci = L->ci; |
| 524 | if (!internal && ci > L->base_ci) ci--; | ||
| 525 | if (strchr(msg, '\n')) return; /* message already `formatted' */ | ||
| 526 | if (!isLua(ci)) { /* no Lua code? */ | 523 | if (!isLua(ci)) { /* no Lua code? */ |
| 527 | luaO_pushfstring(L, "%s\n", msg); /* no extra info */ | 524 | luaO_pushfstring(L, "%s\n", msg); /* no extra info; just add '\n' */ |
| 528 | } | 525 | } |
| 529 | else { /* add file:line information */ | 526 | else { /* add file:line information */ |
| 530 | char buff[LUA_IDSIZE]; | 527 | char buff[LUA_IDSIZE]; |
| @@ -535,9 +532,7 @@ static void addinfo (lua_State *L, int internal) { | |||
| 535 | } | 532 | } |
| 536 | 533 | ||
| 537 | 534 | ||
| 538 | void luaG_errormsg (lua_State *L, int internal) { | 535 | void luaG_errormsg (lua_State *L) { |
| 539 | if (ttisstring(L->top - 1)) | ||
| 540 | addinfo(L, internal); | ||
| 541 | if (L->errfunc != 0) { /* is there an error handling function? */ | 536 | if (L->errfunc != 0) { /* is there an error handling function? */ |
| 542 | StkId errfunc = restorestack(L, L->errfunc); | 537 | StkId errfunc = restorestack(L, L->errfunc); |
| 543 | if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR); | 538 | if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR); |
| @@ -553,8 +548,8 @@ void luaG_errormsg (lua_State *L, int internal) { | |||
| 553 | void luaG_runerror (lua_State *L, const char *fmt, ...) { | 548 | void luaG_runerror (lua_State *L, const char *fmt, ...) { |
| 554 | va_list argp; | 549 | va_list argp; |
| 555 | va_start(argp, fmt); | 550 | va_start(argp, fmt); |
| 556 | luaO_pushvfstring(L, fmt, argp); | 551 | addinfo(L, luaO_pushvfstring(L, fmt, argp)); |
| 557 | va_end(argp); | 552 | va_end(argp); |
| 558 | luaG_errormsg(L, 1); | 553 | luaG_errormsg(L); |
| 559 | } | 554 | } |
| 560 | 555 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldebug.h,v 1.27 2002/08/06 15:32:22 roberto Exp roberto $ | 2 | ** $Id: ldebug.h,v 1.28 2002/08/06 18:01:50 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 | */ |
| @@ -27,7 +27,7 @@ void luaG_concaterror (lua_State *L, StkId p1, StkId p2); | |||
| 27 | void luaG_aritherror (lua_State *L, StkId p1, const TObject *p2); | 27 | void luaG_aritherror (lua_State *L, StkId p1, const TObject *p2); |
| 28 | int luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2); | 28 | int luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2); |
| 29 | void luaG_runerror (lua_State *L, const char *fmt, ...); | 29 | void luaG_runerror (lua_State *L, const char *fmt, ...); |
| 30 | void luaG_errormsg (lua_State *L, int internal); | 30 | void luaG_errormsg (lua_State *L); |
| 31 | int luaG_checkcode (const Proto *pt); | 31 | int luaG_checkcode (const Proto *pt); |
| 32 | 32 | ||
| 33 | 33 | ||
