lua-users home
lua-l archive

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


> It's not the same, though. Apart from having to reorder my logic to suit
> the restrictions of the language, which is always a pain, there's a
> performance hit in that shared state has to be accessed via upvalues
> rather than locals, which are considerably more expensive --- not just
> to access, but also to create individual closures for each state in your
> state machine. Say you have a state-machine based parser for network
> packets. You have two choices: construct and then discard potentially
> hundreds of closures for every packet, or restructure the entire state
> machine not to need shared state. One's slow, the other's inconvenient.


Is that really true?  I'm not sure I buy it.  Why can't you use
coroutines with locals and and infinite loop to implement your state
machine?  I've done this in many situations and have never had the
need for upvalues.

wes