aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-02-17 17:29:29 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-02-17 17:29:29 -0200
commit422318f6777d8d3bac13ade797d9c8eaa38686b6 (patch)
tree5cfabc21fcebb714daf237bff783fe9630e70582 /ldo.c
parent49dae52d0808776f5861eb33efa1d13b05e44512 (diff)
downloadlua-422318f6777d8d3bac13ade797d9c8eaa38686b6.tar.gz
lua-422318f6777d8d3bac13ade797d9c8eaa38686b6.tar.bz2
lua-422318f6777d8d3bac13ade797d9c8eaa38686b6.zip
two new fields 'fTransfer'/'nTransfer' in 'lua_Debug' structure
(for information about values being given and returned in function calls)
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/ldo.c b/ldo.c
index f797df29..6acd2f64 100644
--- a/ldo.c
+++ b/ldo.c
@@ -267,9 +267,11 @@ void luaD_inctop (lua_State *L) {
267** called. (Both 'L->hook' and 'L->hookmask', which triggers this 267** called. (Both 'L->hook' and 'L->hookmask', which triggers this
268** function, can be changed asynchronously by signals.) 268** function, can be changed asynchronously by signals.)
269*/ 269*/
270void luaD_hook (lua_State *L, int event, int line) { 270void luaD_hook (lua_State *L, int event, int line,
271 int fTransfer, int nTransfer) {
271 lua_Hook hook = L->hook; 272 lua_Hook hook = L->hook;
272 if (hook && L->allowhook) { /* make sure there is a hook */ 273 if (hook && L->allowhook) { /* make sure there is a hook */
274 int mask = CIST_HOOKED;
273 CallInfo *ci = L->ci; 275 CallInfo *ci = L->ci;
274 ptrdiff_t top = savestack(L, L->top); 276 ptrdiff_t top = savestack(L, L->top);
275 ptrdiff_t ci_top = savestack(L, ci->top); 277 ptrdiff_t ci_top = savestack(L, ci->top);
@@ -277,11 +279,16 @@ void luaD_hook (lua_State *L, int event, int line) {
277 ar.event = event; 279 ar.event = event;
278 ar.currentline = line; 280 ar.currentline = line;
279 ar.i_ci = ci; 281 ar.i_ci = ci;
282 if (nTransfer != 0) {
283 mask |= CIST_TRAN; /* 'ci' has transfer information */
284 ci->u2.transferinfo.fTransfer = fTransfer;
285 ci->u2.transferinfo.nTransfer = nTransfer;
286 }
280 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ 287 luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
281 if (L->top + LUA_MINSTACK > ci->top) 288 if (L->top + LUA_MINSTACK > ci->top)
282 ci->top = L->top + LUA_MINSTACK; 289 ci->top = L->top + LUA_MINSTACK;
283 L->allowhook = 0; /* cannot call hooks inside a hook */ 290 L->allowhook = 0; /* cannot call hooks inside a hook */
284 ci->callstatus |= CIST_HOOKED; 291 ci->callstatus |= mask;
285 lua_unlock(L); 292 lua_unlock(L);
286 (*hook)(L, &ar); 293 (*hook)(L, &ar);
287 lua_lock(L); 294 lua_lock(L);
@@ -289,7 +296,7 @@ void luaD_hook (lua_State *L, int event, int line) {
289 L->allowhook = 1; 296 L->allowhook = 1;
290 ci->top = restorestack(L, ci_top); 297 ci->top = restorestack(L, ci_top);
291 L->top = restorestack(L, top); 298 L->top = restorestack(L, top);
292 ci->callstatus &= ~CIST_HOOKED; 299 ci->callstatus &= ~mask;
293 } 300 }
294} 301}
295 302
@@ -301,16 +308,18 @@ void luaD_hook (lua_State *L, int event, int line) {
301*/ 308*/
302void luaD_hookcall (lua_State *L, CallInfo *ci) { 309void luaD_hookcall (lua_State *L, CallInfo *ci) {
303 int hook = (ci->callstatus & CIST_TAIL) ? LUA_HOOKTAILCALL : LUA_HOOKCALL; 310 int hook = (ci->callstatus & CIST_TAIL) ? LUA_HOOKTAILCALL : LUA_HOOKCALL;
311 Proto *p;
304 if (!(L->hookmask & LUA_MASKCALL)) /* some other hook? */ 312 if (!(L->hookmask & LUA_MASKCALL)) /* some other hook? */
305 return; /* don't call hook */ 313 return; /* don't call hook */
314 p = clLvalue(s2v(ci->func))->p;
306 L->top = ci->top; /* prepare top */ 315 L->top = ci->top; /* prepare top */
307 ci->u.l.savedpc++; /* hooks assume 'pc' is already incremented */ 316 ci->u.l.savedpc++; /* hooks assume 'pc' is already incremented */
308 luaD_hook(L, hook, -1); 317 luaD_hook(L, hook, -1, 1, p->numparams);
309 ci->u.l.savedpc--; /* correct 'pc' */ 318 ci->u.l.savedpc--; /* correct 'pc' */
310} 319}
311 320
312 321
313static void rethook (lua_State *L, CallInfo *ci) { 322static void rethook (lua_State *L, CallInfo *ci, StkId firstres, int nres) {
314 int delta = 0; 323 int delta = 0;
315 if (isLuacode(ci)) { 324 if (isLuacode(ci)) {
316 Proto *p = clLvalue(s2v(ci->func))->p; 325 Proto *p = clLvalue(s2v(ci->func))->p;
@@ -320,8 +329,10 @@ static void rethook (lua_State *L, CallInfo *ci) {
320 L->top = ci->top; /* correct top */ 329 L->top = ci->top; /* correct top */
321 } 330 }
322 if (L->hookmask & LUA_MASKRET) { /* is return hook on? */ 331 if (L->hookmask & LUA_MASKRET) { /* is return hook on? */
332 int fTransfer;
323 ci->func += delta; /* if vararg, back to virtual 'func' */ 333 ci->func += delta; /* if vararg, back to virtual 'func' */
324 luaD_hook(L, LUA_HOOKRET, -1); /* call it */ 334 fTransfer = cast(unsigned short, firstres - ci->func);
335 luaD_hook(L, LUA_HOOKRET, -1, fTransfer, nres); /* call it */
325 ci->func -= delta; 336 ci->func -= delta;
326 } 337 }
327 if (isLua(ci->previous)) 338 if (isLua(ci->previous))
@@ -396,7 +407,7 @@ static void moveresults (lua_State *L, StkId firstResult, StkId res,
396void luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) { 407void luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, int nres) {
397 if (L->hookmask) { 408 if (L->hookmask) {
398 ptrdiff_t fr = savestack(L, firstResult); /* hook may change stack */ 409 ptrdiff_t fr = savestack(L, firstResult); /* hook may change stack */
399 rethook(L, ci); 410 rethook(L, ci, firstResult, nres);
400 firstResult = restorestack(L, fr); 411 firstResult = restorestack(L, fr);
401 } 412 }
402 L->ci = ci->previous; /* back to caller */ 413 L->ci = ci->previous; /* back to caller */
@@ -458,8 +469,10 @@ void luaD_call (lua_State *L, StkId func, int nresults) {
458 ci->top = L->top + LUA_MINSTACK; 469 ci->top = L->top + LUA_MINSTACK;
459 ci->func = func; 470 ci->func = func;
460 lua_assert(ci->top <= L->stack_last); 471 lua_assert(ci->top <= L->stack_last);
461 if (L->hookmask & LUA_MASKCALL) 472 if (L->hookmask & LUA_MASKCALL) {
462 luaD_hook(L, LUA_HOOKCALL, -1); 473 int narg = cast_int(L->top - func) - 1;
474 luaD_hook(L, LUA_HOOKCALL, -1, 1, narg);
475 }
463 lua_unlock(L); 476 lua_unlock(L);
464 n = (*f)(L); /* do the actual call */ 477 n = (*f)(L); /* do the actual call */
465 lua_lock(L); 478 lua_lock(L);