aboutsummaryrefslogtreecommitdiff
path: root/ldebug.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldebug.c')
-rw-r--r--ldebug.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/ldebug.c b/ldebug.c
index 553af071..100b9b7a 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.137 2017/11/03 17:22:54 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.138 2017/11/03 19:33:22 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*/
@@ -146,14 +146,17 @@ LUA_API int lua_gethookcount (lua_State *L) {
146 146
147LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) { 147LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
148 int status; 148 int status;
149 CallInfo *ci; 149 StkId func;
150 if (level < 0) return 0; /* invalid (negative) level */ 150 if (level < 0) return 0; /* invalid (negative) level */
151 lua_lock(L); 151 lua_lock(L);
152 for (ci = L->ci; level > 0 && ci != &L->base_ci; ci = ci->previous) 152 for (func = L->func;
153 level > 0 && func->stkci.previous != 0;
154 func -= func->stkci.previous)
153 level--; 155 level--;
154 if (level == 0 && ci != &L->base_ci) { /* level found? */ 156 if (level == 0 && func->stkci.previous != 0) { /* level found? */
155 status = 1; 157 status = 1;
156 ar->i_ci = ci; 158 ar->i_actf = func - L->stack;
159 ar->i_actL = L;
157 } 160 }
158 else status = 0; /* no such level */ 161 else status = 0; /* no such level */
159 lua_unlock(L); 162 lua_unlock(L);
@@ -181,9 +184,10 @@ static StkId findcalled (lua_State *L, StkId caller) {
181} 184}
182 185
183 186
184static const char *findlocal (lua_State *L, StkId stkf, int n, 187static const char *findlocal (lua_State *L, const lua_Debug *ar,
185 StkId *pos) { 188 int n, StkId *pos) {
186 const char *name = NULL; 189 const char *name = NULL;
190 StkId stkf = ar->i_actL->stack + ar->i_actf;
187 if (isLua(stkf)) { 191 if (isLua(stkf)) {
188 name = luaF_getlocalname(ci_func(stkf)->p, n, currentpc(stkf)); 192 name = luaF_getlocalname(ci_func(stkf)->p, n, currentpc(stkf));
189 } 193 }
@@ -210,7 +214,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
210 } 214 }
211 else { /* active function; get information through 'ar' */ 215 else { /* active function; get information through 'ar' */
212 StkId pos = NULL; /* to avoid warnings */ 216 StkId pos = NULL; /* to avoid warnings */
213 name = findlocal(L, ar->i_ci->func, n, &pos); 217 name = findlocal(L, ar, n, &pos);
214 if (name) { 218 if (name) {
215 setobjs2s(L, L->top, pos); 219 setobjs2s(L, L->top, pos);
216 api_incr_top(L); 220 api_incr_top(L);
@@ -225,7 +229,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
225 StkId pos = NULL; /* to avoid warnings */ 229 StkId pos = NULL; /* to avoid warnings */
226 const char *name; 230 const char *name;
227 lua_lock(L); 231 lua_lock(L);
228 name = findlocal(L, ar->i_ci->func, n, &pos); 232 name = findlocal(L, ar, n, &pos);
229 if (name) { 233 if (name) {
230 setobjs2s(L, pos, L->top - 1); 234 setobjs2s(L, pos, L->top - 1);
231 L->top--; /* pop value */ 235 L->top--; /* pop value */
@@ -361,7 +365,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
361 L->top--; /* pop function */ 365 L->top--; /* pop function */
362 } 366 }
363 else { 367 else {
364 stkf = ar->i_ci->func; 368 stkf = ar->i_actL->stack + ar->i_actf;
365 func = s2v(stkf); 369 func = s2v(stkf);
366 lua_assert(ttisfunction(func)); 370 lua_assert(ttisfunction(func));
367 } 371 }