[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: cooperative multitasking
- From: Philippe Lhoste <PhiLho@...>
- Date: Fri, 7 Jun 2002 18:39:31 +0200 (MEST)
> coroutine.create(f) creates a coroutine (that part is easy ;-). From
> the point of view of Lua, a coroutine is a function. When you call that
> function, "f" (the coroutine "body") starts execution (as if you have
> called "f" directly).
> However, at any point during its execution, "f" may call
> "coroutine.yield(...)". (Actually, not only "f", but any function called
> by "f".) At that point, the coroutine stops its execution, and control
> goes back to the call to "f" (that is, to the caller it is as if "f"
> has returned). But when the caller calls the coroutine again, it continues
> its execution from the point where it has yielded. That is, "yield"
> suspends the execution of the coroutine, which can be resumed later.
Amazing, not only I understood your explainations, but I think I also
understood the "primes" example. Thanks for answering so quickly and for your
cristal clear explanations, as usual.
Stop me if I say something stupid, but is seems that f is not only a
function, but also a closure. Ie. in your example, n is frozen.
So your program just divide all numbers by all numbers and output those
Mmm, that's not so simple, x is dynamic, ouch...
OK, I will study your code more, even if I understand the bases of
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
GMX - Die Kommunikationsplattform im Internet.