[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: fun with coroutines
- From: Benoit Germain <bgermain@...>
- Date: Thu, 31 Oct 2002 09:26:03 +0100
That's fine with me. My concern was mainly with the functionality, not the
way it is implemented. As I am no lua core expert, I relinquish the
implementation part gracefully. My modification will remain in my copy of
5.0-alpha until 5.0-beta is released though :-)
> -----Original Message-----
> From: Thatcher Ulrich [mailto:tu@tulrich.com]
> Sent: mercredi 30 octobre 2002 20:09
> To: Multiple recipients of list
> Subject: Re: fun with coroutines
>
>
> On Oct 30, 2002 at 06:15 +0100, Benoit Germain wrote:
> >
> > I have made some modifications to lua-5.0-alpha that enable a script
> > to call a coroutine with different arguments at each frame. My use
> > is the following: the coroutine body takes as arguments a system
> > date and a time delta since the previous date it was
> > called. Obviously these values change at each call, and I did not
> > want the overhead of putting them in a table being the real (and
> > constant) argument of the coroutine.
> >
> > The changes are relatively small. Is there a possibility to have
> > them added to the 5.0-beta release if I provide a suitable patch
> > file ?
>
> If I may butt in... this seems like useful functionality, but it
> doesn't seem very "clean" to me, to modify existing parameters in a
> stealthy way. As an alternative, would it be possible to have yield()
> return values explicitly, which are passed by the resume call?
>
> E.g., modifying an ealier example you gave:
>
> function f(a,b,c)
> while true
> do
> print ( a .. b .. c )
> a, b, c = coroutine . yield ( )
> end
> end
>
> c = coroutine . create (f)
>
> c("lua ","is ","great!") -- call f() with these args
> --> lua is great!
> c("Alex Barros ", "is ", "great!") -- yield() inside f()
> returns the provided args
> --> Alex Barros is great!
> c() -- yield() inside f() returns no values
> --> attempt to concat a nil value
>
> It seems that this would probably be as efficient, and clearer in the
> code, and certainly easier to explain in documentation. This also
> makes it possible for your coroutine function to call sub-functions
> that call yield, and get the information you want.
>
> --
> Thatcher Ulrich
> http://tulrich.com
>