[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Switch/Case statements revisited (using tables?)
- From: "Javier Guerra" <javier@...>
- Date: Wed, 7 Nov 2007 14:19:49 -0500
On 11/7/07, Tim Johnson <tim@johnsons-web.com> wrote:
> 3)Can one use a lua table to "dispatch" one of a list of alternative
> choices. Would such an approach be "messy"? ....
sure, i do this all the time (and i'm sure many others).
also, since in Lua functions are really anonymous (unlike Python), it
doesn't pollute any namespace (the table itself is the namespace)
-- easy to write...
local dispatch = {
start = function (x) .... end,
continue = function (x) ..... end,
.....
}
dispatch[state](x) -- and easy to call!
--
Javier