lua-users home
lua-l archive

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


>From reading the C source, it looks something like this (not sure on it,
only looked at it very briefly):

A function can call lua_yield() to setup the lua state/stack, then the C
function would return.  When the Lua coroutine ran again, it would
re-run the C function, but the state (that it previously ran, plus any
arguments) would be based into it again.

The functionality looks rather convoluted, and not even what I was
looking for - it is not Lua threading, which is all that I want or
need.  I can't even see the point to this coroutine implementation.

On Sat, 2002-03-16 at 17:39, Curt Carpenter wrote:
> Can you explain how that works? Does the yield call inside a registered
> C function not return until some other state yields back to the first
> state? 
> If so, I don't understand how that's possible (without blowing the stack
> out, for example). 
> If not, it's not exactly the same thing.
> 
> Thanks,
> 
> Curt
> 
> -----Original Message-----
> From: Roberto Ierusalimschy [mailto:roberto@inf.puc-rio.br] 
> Sent: Saturday, March 16, 2002 4:14 AM
> To: Multiple recipients of list
> Subject: Re: running LUA code step by step 
> 
> 
> > 1) Fire up new fibers (and call lua_newthread) for new objects which 
> > need their own script execution/stack/lua_state
> > 2) Keep a list of objects that are ready to execute. Loop over all 
> > objects and switch to their fiber.
> > 3) In each object, figure out when they want to yield, either by a 
> > line/call hook, or by a call into a registered C function that 
> > indicates they need to wait (like a call that blocks on something out 
> > of its control).
> > 4) When an object is ready to yield, switch back to the primary fiber.
> > 5) Depending on your needs, have some plan to add objects back to the 
> > ready list. If you want all objects to execute code on every cycle, 
> > then maybe you don't need a ready list, but I use it to mark scripts 
> > that are ready to continue after having some condition met that they 
> > are blocked on.
> 
> You should be able to do exactly the same thing with coroutines in
> Luaw4. (The only drawback is that currently you cannot yield inside a
> linehook; we will correct that. But you can yield inside a registered C
> function that indicates they need to wait.)
> 
> -- Roberto