diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-10-02 12:46:49 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-10-02 12:46:49 -0300 |
commit | e290bd6760c2fe2586be65bba118c52a6398b492 (patch) | |
tree | 17e91e270d9d6ec7f44e7cfd12af45328c28212b /lauxlib.c | |
parent | dc4232379d79bc4ff5ad16bebf41793bb7ba6deb (diff) | |
download | lua-e290bd6760c2fe2586be65bba118c52a6398b492.tar.gz lua-e290bd6760c2fe2586be65bba118c52a6398b492.tar.bz2 lua-e290bd6760c2fe2586be65bba118c52a6398b492.zip |
in 'luaL_traceback', print correct number of levels even when
initial level is not 1.
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.280 2015/02/03 17:38:24 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.281 2015/06/18 14:23:14 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 | */ |
@@ -33,8 +33,8 @@ | |||
33 | */ | 33 | */ |
34 | 34 | ||
35 | 35 | ||
36 | #define LEVELS1 12 /* size of the first part of the stack */ | 36 | #define LEVELS1 10 /* size of the first part of the stack */ |
37 | #define LEVELS2 10 /* size of the second part of the stack */ | 37 | #define LEVELS2 11 /* size of the second part of the stack */ |
38 | 38 | ||
39 | 39 | ||
40 | 40 | ||
@@ -107,7 +107,7 @@ static void pushfuncname (lua_State *L, lua_Debug *ar) { | |||
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | static int countlevels (lua_State *L) { | 110 | static int lastlevel (lua_State *L) { |
111 | lua_Debug ar; | 111 | lua_Debug ar; |
112 | int li = 1, le = 1; | 112 | int li = 1, le = 1; |
113 | /* find an upper bound */ | 113 | /* find an upper bound */ |
@@ -126,14 +126,16 @@ LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, | |||
126 | const char *msg, int level) { | 126 | const char *msg, int level) { |
127 | lua_Debug ar; | 127 | lua_Debug ar; |
128 | int top = lua_gettop(L); | 128 | int top = lua_gettop(L); |
129 | int numlevels = countlevels(L1); | 129 | int last = lastlevel(L1); |
130 | int mark = (numlevels > LEVELS1 + LEVELS2) ? LEVELS1 : 0; | 130 | int n1 = (last - level > LEVELS1 + LEVELS2) ? LEVELS1 : -1; |
131 | if (msg) lua_pushfstring(L, "%s\n", msg); | 131 | if (msg) |
132 | lua_pushfstring(L, "%s\n", msg); | ||
133 | luaL_checkstack(L, 10, NULL); | ||
132 | lua_pushliteral(L, "stack traceback:"); | 134 | lua_pushliteral(L, "stack traceback:"); |
133 | while (lua_getstack(L1, level++, &ar)) { | 135 | while (lua_getstack(L1, level++, &ar)) { |
134 | if (level == mark) { /* too many levels? */ | 136 | if (n1-- == 0) { /* too many levels? */ |
135 | lua_pushliteral(L, "\n\t..."); /* add a '...' */ | 137 | lua_pushliteral(L, "\n\t..."); /* add a '...' */ |
136 | level = numlevels - LEVELS2; /* and skip to last ones */ | 138 | level = last - LEVELS2 + 1; /* and skip to last ones */ |
137 | } | 139 | } |
138 | else { | 140 | else { |
139 | lua_getinfo(L1, "Slnt", &ar); | 141 | lua_getinfo(L1, "Slnt", &ar); |