lua-users home
lua-l archive

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


On Tuesday 06 November 2007, steve donovan wrote:
> Hi guys,
>
> This is obviously a perenial topic, since there's a wiki page dedicated to
> it:
>
> http://lua-users.org/wiki/SwitchStatement
>
 I haven't written any lua code yet, so I hope I'm not being so presumptious
 as to contribute:
 I have a background (among others) in C/C++, rebol and python.
 1)I frequently use python dictionaries to "dispatch" alternative choices.
    Such choice must be a functions as a value for keys and must all
    have the same parameters.
    example: dispatch = {"start":func1,"review":func2,"finish":func3"}
    and the execution is dispatch[key](args). And the fall thru can be
    a KeyError trap.
2)Rebol is "block" oriented and has the ability for code to reference code
   as data ala lisp. So a switch is easily implemented as a native 'select'
  example
 case key[ "start"[;; code here *OR* function call of any argument list]
               "review"[;; some other code or function call]
   ....
3)Can one use a lua table to "dispatch" one of a list of alternative
choices. Would such an approach be "messy"? ....
Hope I'm being clear here.
Thanks
Tim