lua-users home
lua-l archive

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


Oh, cool Peter. I know I need to 'rtfm' before I get carried away with these questions (hope I haven't annoyed anyone yet)... but just one more before I do that, please:

    Can the args to coroutine.yield be used to determine which coro should be run next?

Thanks!

On Sat, Apr 25, 2009 at 8:42 AM, Peter Cawley <lua@corsix.org> wrote:
On Sat, Apr 25, 2009 at 4:24 PM, Phoenix Sol <phoenix@burninglabs.com> wrote:
> Is it safe to assume that it would be relatively easy to implement
> 'message-passing-style-scheduling' in lua, where one coroutine yields to
> another by passing a message to it? (without accumulating stack frames?!)

coroutine.yield can be passed whatever arguments you want, which
become additional return values of the call to coroutine.resume which
caused the coroutine to run. This allows for a coroutine to pass
values as it yields. Also note that extra arguments to
coroutine.resume will become the return values of coroutine.yield in
the resumed coroutine, allowing you to pass values as you resume.