lua-users home
lua-l archive

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


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.