lua-users home
lua-l archive

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


On Mon, Mar 22, 2010 at 7:47 AM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
> If a Lua hook yields, a resume should resume the Lua hook itself, not
> the Lua function that hooked, so the C hook should be saved.
>
> It is not difficult to allow the Lua hook to hook the original
> Lua function (e.g., by returning a specific value).

I've tried a few things along these lines but without much luck. I
think the main problem is just that I don't have a good understanding
of how yields and resumes operate.

The first thing I tried was changing the lua_call to lua_callk in
'hookf', as I mentioned before, and using coroutine.yield in the lua
hook. That caused an access violation when the Lua hook function
returned. The second thing I tried was adding lua_yield below lua_call
in 'hookf', as a trial run of the "yield based on hook return value"
idea. But every time I use coroutine.resume on the coroutine, it just
calls the Lua hook again. This might be obvious, since I called
debug.sethook with a count of 1, but the coroutine never ends. If I
have a print statement in the coroutine, it's never reached. I never
get "cannot resume dead coroutine".

Hence, I figure that yield/resume do something I'm not expecting, or
don't understand. I'd appreciate a simple example of how to use
lua_yield in a C hook function, if at all possible!

(And on a point of aesthetics, I find the idea of yielding based on a
hook's return value to feel rather un-Lua-y. I'd rather be able to
call coroutine.yield from the Lua hook, but I'll take what I can get.)

~Jonathan