lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


[ACJ Brouwer <acj.brouwer@citengineering.com>]
> Is it possible to yield from the opcode count
> hook under Lua 5.0 beta?

I was wondering that myself... I haven't tried it yet, but this
chunk of lvm.c makes me suspect that it will work:

[ from lvm.c, lines 388-396 ]

    if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
        (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
      traceexec(L);
      if (L->ci->state & CI_YIELD) {  /* did hook yield? */
        L->ci->u.l.savedpc = pc - 1;
        L->ci->state = CI_YIELD | CI_SAVEDPC;
        return NULL;
      }
    }

However, it looks like lua_yield() will cause a runtime error "attempt to
yield across a metamethod/C-call boundary", presumably if you do just that.
This makes me wonder if it will work as long as the counter doesn't 
roll over inside a metamethod... 

I wonder if a. this can be worked around (if the yield fails, wait and
try again the next time the counter trips -- maybe reduce the count) and
b. if this means that such a technique won't work to avoid potential
long/infinite loops in metamethods.

Brian

-- 
 Brian Swetland ..: | "This patch fixes the Problem of Evil and 
 swetland@frotz.net |  the dangling-else ambiguity." -- acb