lua-users home
lua-l archive

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

On Thu, Jun 11, 2009 at 12:57 PM, David Given <> wrote:
Robert Raschke wrote:

I find using a "machine state" Lua table that you can pass around to be pretty ideal.

This means looking stuff up dynamically from the table, which gives you an order of magnitude performance hit. Table lookups are *slow*. Simply moving the program counter from one bytecode address to another is fast. Plus using table lookups means that (assuming I've understood you correctly), the handler for each state needs to be a function, which means you run into the problem of efficiently sharing data between the handlers.

Yes, indeed. Each state is a function, state transitions are tail calls, and the machine state is passed around as a table. This may be slower than goto with implicit shared state, but not slow enough for me to care in what I'm doing. Especially, since I can read the code and understand it.

From your comments, I must assume you are running in an environment with time constraints short enough to make you need something faster. Just out of interest, what's the problem domain of your state machine?