lua-users home
lua-l archive

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


> On Feb 23, 2015, at 1:44 PM, Paul K <paul@zerobrane.com> wrote:
> 
> >> could a conforming implementation have them be yieldable?
> > Yes.
> 
> >> (Also why are they not yieldable in the reference implementation?)
> > It does not seem to be a good cost-benefit approach. Making them yieldable will probably make them more complex and slower in the "normal" case.
> 
> I'm curious as to what changes at the C level are required to make them yieldable. For example, is it possible to make Lpeg handling of callback functions (Cmt and /func) yieldable?
> 
> Paul.
> 

The problem is that yieldable functions lose their stack on a yield (because of long jumps), and have to keep all function state in an auxiliary data structure that is then passed by Lua to a “continuation” function. Converting simple functions to this model is a little messy but not too hard (you move all local state and variables into the structure), but it gets much messier with recursive functions, since you have to simulate the recursion stack within the continuation state. it can be done, but it’s not nice.

—Tim