lua-users home
lua-l archive

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


Warning: I'm replying to an 8 month old thread.

On Aug 05, 2005, at 11:19, Mike Pall wrote:

Hi,

David Morris-Oliveros wrote:
It would be similar to the hooks in lua, but rather lua calling the hook
every 5 instructions, i let it execute those 5 instructions, then it
comes back to me.

That's inversion of control. Lua already supports that with the
help of coroutines. And lucky you, you can yield from a count hook
(or line hook).

So from C do a lua_newthread() and then lua_sethook() to install
your count hook. When the hook decides that the timeout is reached
it forces a yield for the coroutine with 'return lua_yield(L, 0)'.

Doesn't this go wrong if the hook tries to yield when we were running a metamethod, or an iterator?

If so, do you have a recommended workaround? There doesn't seem to be any official way to tell if it is safe to lua_yield.

David Jones