lua-users home
lua-l archive

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


Yielding from hooks is an experimental feature of Lua 5.0. You can only
do this in C, as hooks must be written in C. Also, you can only yield
in a line or a count hook; you cannot yield inside a call or a return
hook. This facility is not intended for "regular" programs.

Currently there is no "standard" way to prevent an invalid yield if
the hook is called inside a metamethod or a "for" iterator function,
although there is no risk of yielding inside a C function (as a C
function never calls line/count hooks). One way to avoid the problem
is to avoid writing metamethods and iterators in Lua... (Notice that
metamethods and iterators written in C present no problems.)

Also, a yield from a hook does not return values to its resume. You
should not modify the stack of a thread while it is suspended in such
way (unlike regular yields, where you can remove the returned values and
later push other values).

-- Roberto