diff options
| -rw-r--r-- | ldo.c | 36 | ||||
| -rw-r--r-- | ldo.h | 4 |
2 files changed, 20 insertions, 20 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.173 2017/11/21 14:17:35 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.174 2017/11/23 16:35:54 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 | */ |
| @@ -297,6 +297,14 @@ static void callhook (lua_State *L, CallInfo *ci, int istail) { | |||
| 297 | } | 297 | } |
| 298 | 298 | ||
| 299 | 299 | ||
| 300 | static void rethook (lua_State *L, CallInfo *ci) { | ||
| 301 | if (L->hookmask & LUA_MASKRET) /* is return hook on? */ | ||
| 302 | luaD_hook(L, LUA_HOOKRET, -1); /* call it */ | ||
| 303 | if (isLua(ci->previous)) | ||
| 304 | L->oldpc = ci->previous->u.l.savedpc; /* update 'oldpc' */ | ||
| 305 | } | ||
| 306 | |||
| 307 | |||
| 300 | /* | 308 | /* |
| 301 | ** Check whether __call metafield of 'func' is a function. If so, put | 309 | ** Check whether __call metafield of 'func' is a function. If so, put |
| 302 | ** it in stack below original 'func' so that 'luaD_call' can call | 310 | ** it in stack below original 'func' so that 'luaD_call' can call |
| @@ -323,8 +331,8 @@ StkId luaD_tryfuncTM (lua_State *L, StkId func) { | |||
| 323 | ** expressions, multiple results for tail calls/single parameters) | 331 | ** expressions, multiple results for tail calls/single parameters) |
| 324 | ** separated. | 332 | ** separated. |
| 325 | */ | 333 | */ |
| 326 | static int moveresults (lua_State *L, StkId firstResult, StkId res, | 334 | static void moveresults (lua_State *L, StkId firstResult, StkId res, |
| 327 | int nres, int wanted) { | 335 | int nres, int wanted) { |
| 328 | switch (wanted) { /* handle typical cases separately */ | 336 | switch (wanted) { /* handle typical cases separately */ |
| 329 | case 0: break; /* nothing to move */ | 337 | case 0: break; /* nothing to move */ |
| 330 | case 1: { /* one result needed */ | 338 | case 1: { /* one result needed */ |
| @@ -339,7 +347,7 @@ static int moveresults (lua_State *L, StkId firstResult, StkId res, | |||
| 339 | for (i = 0; i < nres; i++) /* move all results to correct place */ | 347 | for (i = 0; i < nres; i++) /* move all results to correct place */ |
| 340 | setobjs2s(L, res + i, firstResult + i); | 348 | setobjs2s(L, res + i, firstResult + i); |
| 341 | L->top = res + nres; | 349 | L->top = res + nres; |
| 342 | return 0; /* wanted == LUA_MULTRET */ | 350 | return; |
| 343 | } | 351 | } |
| 344 | default: { | 352 | default: { |
| 345 | int i; | 353 | int i; |
| @@ -357,7 +365,6 @@ static int moveresults (lua_State *L, StkId firstResult, StkId res, | |||
| 357 | } | 365 | } |
| 358 | } | 366 | } |
| 359 | L->top = res + wanted; /* top points after the last result */ | 367 | L->top = res + wanted; /* top points after the last result */ |
| 360 | return 1; | ||
| 361 | } | 368 | } |
| 362 | 369 | ||
| 363 | 370 | ||
| @@ -366,22 +373,15 @@ static int moveresults (lua_State *L, StkId firstResult, StkId res, | |||
| 366 | ** moves current number of results to proper place; returns 0 iff call | 373 | ** moves current number of results to proper place; returns 0 iff call |
| 367 | ** wanted multiple (variable number of) results. | 374 | ** wanted multiple (variable number of) results. |
| 368 | */ | 375 | */ |
| 369 | int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) { | 376 | void luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) { |
| 370 | StkId res; | 377 | if (L->hookmask) { |
| 371 | int wanted = ci->nresults; | 378 | ptrdiff_t fr = savestack(L, firstResult); /* hook may change stack */ |
| 372 | if (L->hookmask & (LUA_MASKRET | LUA_MASKLINE)) { | 379 | rethook(L, ci); |
| 373 | if (L->hookmask & LUA_MASKRET) { | 380 | firstResult = restorestack(L, fr); |
| 374 | ptrdiff_t fr = savestack(L, firstResult); /* hook may change stack */ | ||
| 375 | luaD_hook(L, LUA_HOOKRET, -1); | ||
| 376 | firstResult = restorestack(L, fr); | ||
| 377 | } | ||
| 378 | if (isLua(ci->previous)) | ||
| 379 | L->oldpc = ci->previous->u.l.savedpc; | ||
| 380 | } | 381 | } |
| 381 | res = ci->func; /* res == final position of 1st result */ | ||
| 382 | L->ci = ci->previous; /* back to caller */ | 382 | L->ci = ci->previous; /* back to caller */ |
| 383 | /* move results to proper place */ | 383 | /* move results to proper place */ |
| 384 | return moveresults(L, firstResult, res, nres, wanted); | 384 | moveresults(L, firstResult, ci->func, nres, ci->nresults); |
| 385 | } | 385 | } |
| 386 | 386 | ||
| 387 | 387 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.h,v 2.34 2017/11/21 14:18:03 roberto Exp roberto $ | 2 | ** $Id: ldo.h,v 2.35 2017/11/23 16:35:54 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 | */ |
| @@ -53,7 +53,7 @@ LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); | |||
| 53 | LUAI_FUNC StkId luaD_tryfuncTM (lua_State *L, StkId func); | 53 | LUAI_FUNC StkId luaD_tryfuncTM (lua_State *L, StkId func); |
| 54 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, | 54 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, |
| 55 | ptrdiff_t oldtop, ptrdiff_t ef); | 55 | ptrdiff_t oldtop, ptrdiff_t ef); |
| 56 | LUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, | 56 | LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, |
| 57 | int nres); | 57 | int nres); |
| 58 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); | 58 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); |
| 59 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); | 59 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); |
