lua-users home
lua-l archive

Re: The meaning of 'sugar' [Forked from Re: Why do we have ipairs?]

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


It was thus said that the Great Thiago L. once stated:
> 
> Switch statement without fallthru and stuff:
> And yeah it doesn't support return and stuff and is slow and stuff but 
> there's probably a way to work around that...
> t = setmetatable({ function(...) end, etc }, {__index = function(t,...) 
> <default case> end})
> t[v]()
 local t
 t = 
 {
 'one' = function() stuff() t.two() end,
 'two' = function() otherstuff() end,
 'three' = function() morestuff() end,
 'four' = function() yetmore() t.five() end,
 'five' = function() otherthings() end,
 }
 t[switchvar]()
 Notice how one and four "fall thorugh" to the following cases.
 
> Too bad you can't do something like this:
> 
> goto switch
> ::something::
> <stuff>
> ::somethingElse::
> <morestuff>
> goto exit
> ::switch::
> t = {function() goto something end, function() goto somethingElse end}
> t[v]()
> ::exit::
 Oooh, I'm having flashbacks to BASIC. I don't think I ever wrote assembly
code this bad ...
 -spc (There's a reason GOTO has a bad rap)

AltStyle によって変換されたページ (->オリジナル) /