lua-users home
lua-l archive

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


Hi,

David Jones wrote:
> On Aug 05, 2005, at 11:19, Mike Pall wrote:
> >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?

Yes, it would raise an error.

> If so, do you have a recommended workaround?

Use Coco. It allows you to yield from pretty much anywhere.

Note that hooks are turned off for __gc, so AFAIK the above
approach is safe.

Bye,
     Mike