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.

My understanding is:

The continuation solves the second problem by requiring C programmers manually separate the code before and after a yield into the "normal call" and the "finish function". However, it does NOT seem to me that we have to have a continuation to solve the first problem - "A yield is not allowed when there are multiple Lua fragments and C fragments interleaved on the stack (i.e. the virtual logical stack)." As long as Lua requires a yield/call/pcall occurs only at the immediate prior to return-from-C-to-Lua, the problem is purely of internal VM implementation, requiring no change of API.

So my questions,

Why should we have pcallk/callk retain the old constraint (i.e. error of yield cross metatable/C-call) when continuation is NULL? If I always invoke pall at immediately before return-to-Lua, set continuation to NULL would be exactly what I want. No I have to craft a no-op finish function and pass it to pcallk.

I don't want to challenge the current behavior because crafting an no-op is not a big deal and I understand when the API is out, it's not fully revokable considering compatibility. What I want to know is whether this is just a consideration of stricter back-compatibility or has other consideration I have seen.

Thanks,
Dong