lua-users home
lua-l archive

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


I don't think this functionality is readily available in Lua out of the box. Neither am I missing it and it doesn't strike me like a very common case either. You could probably implement your "reset" using C. Or you could accommodate for the lack of this functionality in your engine design and find another solution that, I suspect, is out there.  

AB

-----Original Message-----
From: Benoit Germain [mailto:bgermain@ubisoft.fr]
Sent: Tuesday, February 04, 2003 3:50 AM
To: Multiple recipients of list
Subject: does anyone else miss a coroutine.reset() feature ?

Hi.

I am implementing a "mode" mechanism, where each mode is a table that
contains a coroutine, plus some transition rules to swap from one mode to
another. The "mode engine" checks the current mode's transition rules, and
determines a new mode, if applicable. If the mode changes, I want the new
mode to start at the beginning of its body (and not where is was interrupted
the laste time is was used), whereas if the mode is unchanged, I want it to
resume where it yielded last time it was called.
The latter is easy to do, this is all what coroutines are about. But the
former is not possible unless I dump the current coroutine wrapper and
create a fresh one. I would like to avoid this, because it implies the
creation of a new collectable object each time a mode changes. Since I work
on a game project where GC hit must be kept as low as possible, it would be
much better for me if there were a coroutine.reset() call, that would
restore the coroutine to a state identical to what is obtained after a
coroutine.wrap() call.

Is this feasible, and more important, something that seems useful to the
coroutine users ?

Cheers,

Benoit.