** Executes a return hook for Lua and C functions and sets/corrects ** 'oldpc'. (Note that this correction is needed by the line hook, so it ** is done even when return hooks are off.) */
| 385 | ** is done even when return hooks are off.) |
| 386 | */ |
| 387 | static void rethook (lua_State *L, CallInfo *ci, int nres) { |
| 388 | if (L->hookmask & LUA_MASKRET) { /* is return hook on? */ |
| 389 | StkId firstres = L->top.p - nres; /* index of first result */ |
| 390 | int delta = 0; /* correction for vararg functions */ |
| 391 | int ftransfer; |
| 392 | if (isLua(ci)) { |
| 393 | Proto *p = ci_func(ci)->p; |
| 394 | if (p->is_vararg) |
| 395 | delta = ci->u.l.nextraargs + p->numparams + 1; |
| 396 | } |
| 397 | ci->func.p += delta; /* if vararg, back to virtual 'func' */ |
| 398 | ftransfer = cast(unsigned short, firstres - ci->func.p); |
| 399 | luaD_hook(L, LUA_HOOKRET, -1, ftransfer, nres); /* call it */ |
| 400 | ci->func.p -= delta; |
| 401 | } |
| 402 | if (isLua(ci = ci->previous)) |
| 403 | L->oldpc = pcRel(ci->u.l.savedpc, ci_func(ci)->p); /* set 'oldpc' */ |
| 404 | } |
| 405 | |
| 406 | |
| 407 | /* |
no test coverage detected