lua-users home
lua-l archive

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

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 coroutine. - 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: = function( aTask )
if ( os.clock() - clock() >= this.interval() ) then
                       aTask, this )

                until this.shouldRepeat() == false


PA, Onnay Equitursay