[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Turning an entire script into a coroutine
- From: PA <petite.abeille@...>
- Date: Sun, 13 Feb 2005 14:08:03 +0100
On Feb 13, 2005, at 13:57, Michael Abbott wrote:
This doesn't appear possible by what I can tell because the yield()
would need to know what coroutine this script is in relation to (a
script is not a coroutine right?).
I'm fairly new to Lua as well. And even more so to the weird but
wonderful world of coroutines :)
That said, this is what I'm doing presently:
- I have a generic 'Task' object which 'wraps' any given object in a
- The 'tasks' register themselves with a 'runloop' which enumerator
through all the coroutines to give them a chance to run.
- When a 'task' is running, it's underlying object 'run' method is
invoked with the 'task' passed as an argument.
As an example, here is the 'run' method of a 'timer' objects which
invokes another object from time to time:
this.run = function( aTask )
if ( os.clock() - clock() >= this.interval() )
this.target().run( aTask, this )
until this.shouldRepeat() == false
PA, Onnay Equitursay