lua-users home
lua-l archive

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


> I have a question on the new "continuation" parameter and the behaviors
> controlled by it.
> 
> I think the yield-in-C in Lua 5.2 solves two separated problems in Lua 5.1:
> 
> - A yield is not allowed when there are multiple Lua fragments and C
> fragments interleaved on the stack (i.e. the virtual logical stack).
> - A yield is unresumable when it occurs in the middle of a piece of C code.

These two points are mostly the same thing. A "yield" in Lua is
multilevel.  When A calls B that calls C that yields, the three
functions (A, B, and C) yield. For instance, from the point of view of
A, to call B->C->yield has the same effect as to call yield directly.
In both cases we have to save its activation record outside the C stack
to allow the function to continue later, when yield (or B->C->yield)
returns.

So, the restriction is exactly the same in your two points: if there is
any C function without a continuation in the stack (no matter whether
it is the top function or interleaved with other calls), a yield is
unresumable, because there is no way to resume that C function later.
If all C functions in the stack have a continuation, then we can yield
safely.

-- Roberto