diff options
Diffstat (limited to 'ldo.c')
| -rw-r--r-- | ldo.c | 30 |
1 files changed, 14 insertions, 16 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.188 2018/01/28 13:39:52 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.189 2018/01/29 16:21:35 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 | */ |
| @@ -294,19 +294,21 @@ void luaD_hook (lua_State *L, int event, int line) { | |||
| 294 | } | 294 | } |
| 295 | 295 | ||
| 296 | 296 | ||
| 297 | static void hookcall (lua_State *L, CallInfo *ci, int istail) { | 297 | /* |
| 298 | int hook; | 298 | ** Executes a call hook for Lua functions. This function is called |
| 299 | ci->u.l.trap = 1; | 299 | ** whenever 'hookmask' is not zero, so it checks whether call hooks are |
| 300 | if (!(L->hookmask & LUA_MASKCALL)) | 300 | ** active. Also, this function can be called when resuming a function, |
| 301 | return; /* some other hook */ | 301 | ** so it checks whether the function is in its first instruction. |
| 302 | */ | ||
| 303 | void luaD_hookcall (lua_State *L, CallInfo *ci) { | ||
| 304 | Proto *p = clLvalue(s2v(ci->func))->p; | ||
| 305 | int hook = (ci->callstatus & CIST_TAIL) ? LUA_HOOKTAILCALL : LUA_HOOKCALL; | ||
| 306 | ci->u.l.trap = 1; /* there may be other hooks */ | ||
| 307 | if (!(L->hookmask & LUA_MASKCALL) || /* some other hook? */ | ||
| 308 | ci->u.l.savedpc != p->code) /* not 1st instruction? */ | ||
| 309 | return; /* don't call hook */ | ||
| 302 | L->top = ci->top; /* prepare top */ | 310 | L->top = ci->top; /* prepare top */ |
| 303 | ci->u.l.savedpc++; /* hooks assume 'pc' is already incremented */ | 311 | ci->u.l.savedpc++; /* hooks assume 'pc' is already incremented */ |
| 304 | if (istail) { | ||
| 305 | ci->callstatus |= CIST_TAIL; | ||
| 306 | hook = LUA_HOOKTAILCALL; | ||
| 307 | } | ||
| 308 | else | ||
| 309 | hook = LUA_HOOKCALL; | ||
| 310 | luaD_hook(L, hook, -1); | 312 | luaD_hook(L, hook, -1); |
| 311 | ci->u.l.savedpc--; /* correct 'pc' */ | 313 | ci->u.l.savedpc--; /* correct 'pc' */ |
| 312 | } | 314 | } |
| @@ -427,8 +429,6 @@ void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int narg1) { | |||
| 427 | L->top = func + narg1; /* set top */ | 429 | L->top = func + narg1; /* set top */ |
| 428 | luaT_adjustvarargs(L, nfixparams, narg1 - 1); | 430 | luaT_adjustvarargs(L, nfixparams, narg1 - 1); |
| 429 | } | 431 | } |
| 430 | if (L->hookmask) | ||
| 431 | hookcall(L, ci, 1); | ||
| 432 | } | 432 | } |
| 433 | 433 | ||
| 434 | 434 | ||
| @@ -483,8 +483,6 @@ void luaD_call (lua_State *L, StkId func, int nresults) { | |||
| 483 | ci->callstatus = 0; | 483 | ci->callstatus = 0; |
| 484 | if (p->is_vararg) | 484 | if (p->is_vararg) |
| 485 | luaT_adjustvarargs(L, nfixparams, narg); /* may invoke GC */ | 485 | luaT_adjustvarargs(L, nfixparams, narg); /* may invoke GC */ |
| 486 | if (L->hookmask) | ||
| 487 | hookcall(L, ci, 0); | ||
| 488 | luaV_execute(L, ci); /* run the function */ | 486 | luaV_execute(L, ci); /* run the function */ |
| 489 | break; | 487 | break; |
| 490 | } | 488 | } |
