lua-users home
lua-l archive

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

On Sun, Mar 21, 2010 at 7:40 AM, Roberto Ierusalimschy
<> wrote:
>> I'm not following. You're saying I can't use coroutine.yield() from a
>> Lua hook function, but I can use its equivalent from a C hook
>> function?
> Yes.
> Note that the hook system does not use "Lua functions", but a special
> kind of C function (lua_Hook). The Lua debug library uses a standard
> lua_Hook function that calls your Lua function, and this call is not
> yieldable.
> -- Roberto

Okay, I understand now. Looking back through the list archives, I note
(happily) that others have had the same preemptive threading idea.
I've also gone into the Lua 5.2 source myself and tinkered with it,
changing the lua_call in the 'hookf' function to a lua_callk. It did
actually successfully yield, but once it left the lua hook function,
an access violation occurred. (Due to a typo, I noticed that the
access violation didn't happen if an error occurred within the hook
function after being resumed. Interesting!)

I'm getting more and more curious as I experiment further. From a
technical, low-level standpoint, what exactly prevents Lua hooks from
becoming yieldable? I'd just like to patch my own copy, if at all