aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/ldo.c b/ldo.c
index 86e77f97..970b890b 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.170 2017/11/07 13:25:26 roberto Exp roberto $ 2** $Id: ldo.c,v 2.171 2017/11/13 12:26:30 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -159,12 +159,16 @@ int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
159static void correctstack (lua_State *L, StkId oldstack) { 159static void correctstack (lua_State *L, StkId oldstack) {
160 CallInfo *ci; 160 CallInfo *ci;
161 UpVal *up; 161 UpVal *up;
162 if (L->stack == oldstack)
163 return; /* stack address did not change */
162 L->top = (L->top - oldstack) + L->stack; 164 L->top = (L->top - oldstack) + L->stack;
163 for (up = L->openupval; up != NULL; up = up->u.open.next) 165 for (up = L->openupval; up != NULL; up = up->u.open.next)
164 up->v = s2v((uplevel(up) - oldstack) + L->stack); 166 up->v = s2v((uplevel(up) - oldstack) + L->stack);
165 for (ci = L->ci; ci != NULL; ci = ci->previous) { 167 for (ci = L->ci; ci != NULL; ci = ci->previous) {
166 ci->top = (ci->top - oldstack) + L->stack; 168 ci->top = (ci->top - oldstack) + L->stack;
167 ci->func = (ci->func - oldstack) + L->stack; 169 ci->func = (ci->func - oldstack) + L->stack;
170 if (isLua(ci))
171 ci->u.l.trap = 1; /* signal to update 'trap' in 'luaV_execute' */
168 } 172 }
169} 173}
170 174
@@ -277,13 +281,18 @@ void luaD_hook (lua_State *L, int event, int line) {
277 281
278 282
279static void callhook (lua_State *L, CallInfo *ci) { 283static void callhook (lua_State *L, CallInfo *ci) {
280 int hook = LUA_HOOKCALL; 284 int hook;
285 ci->u.l.trap = 1;
286 if (!(L->hookmask & LUA_MASKCALL))
287 return; /* some other hook */
281 ci->u.l.savedpc++; /* hooks assume 'pc' is already incremented */ 288 ci->u.l.savedpc++; /* hooks assume 'pc' is already incremented */
282 if (isLua(ci->previous) && 289 if (isLua(ci->previous) &&
283 GET_OPCODE(*(ci->previous->u.l.savedpc - 1)) == OP_TAILCALL) { 290 GET_OPCODE(*(ci->previous->u.l.savedpc - 1)) == OP_TAILCALL) {
284 ci->callstatus |= CIST_TAIL; 291 ci->callstatus |= CIST_TAIL;
285 hook = LUA_HOOKTAILCALL; 292 hook = LUA_HOOKTAILCALL;
286 } 293 }
294 else
295 hook = LUA_HOOKCALL;
287 luaD_hook(L, hook, -1); 296 luaD_hook(L, hook, -1);
288 ci->u.l.savedpc--; /* correct 'pc' */ 297 ci->u.l.savedpc--; /* correct 'pc' */
289} 298}
@@ -430,7 +439,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
430 lua_assert(ci->top <= L->stack_last); 439 lua_assert(ci->top <= L->stack_last);
431 ci->u.l.savedpc = p->code; /* starting point */ 440 ci->u.l.savedpc = p->code; /* starting point */
432 ci->callstatus = CIST_LUA; 441 ci->callstatus = CIST_LUA;
433 if (L->hookmask & LUA_MASKCALL) 442 if (L->hookmask)
434 callhook(L, ci); 443 callhook(L, ci);
435 return 0; 444 return 0;
436 } 445 }