lua-users home
lua-l archive

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


I agree the two points are the same in that a yield/resume must have a
right continuation. But the reason why I made the separation of the
problems is that I do not think the continuation has to be in the form
of a C function-pointer.

I think the continuation could be a virtual one defined by some
"rules." After all, Lua 5.1 has already done so for the old
lua_yield(...), where the continuation is a no-op and the rule is "a
yield be called only when immediately before returning-from-C-to-Lua",
and C-function form is also a rule-based continuation (comparing to a
"real" continuation - stack plus program counter).

So my mental experiment is to have that rule expand to
lua_call/lua_pcall. Would you think that is an idea making sense? Not
for a real proposal but just want to straighten my understanding for
further thought.

Dong



2012/11/21 Roberto Ierusalimschy <roberto@inf.puc-rio.br>:

>
> 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
>