lua-users home
lua-l archive

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

On 11/06/2014 21:44, Paige DePol wrote:
On Jun 11, 2014, at 9:57 AM, Roberto Ierusalimschy <> wrote:

Perhaps what you are saying is that as there are no symbolic
constants in Lua, it is not possible to generate optimized switch
statements for all but the simplest scenario where the switch cases
are literals?
Exactly. (These cases are not only simplest, but usually considered bad
code. If we add a switch optimized only for literals, its impact in code
standards for Lua would be a tragedy...)

-- Roberto
Perhaps you could elaborate on this point a bit as I feel I am missing something here. Under C switch statements require literal values yet switch statements are widely used and, as far as I know, the use of which is not considered bad code.

In which way does adding symbolic constants allow the optimising of switch statements? How would adding a switch optimised for literals badly impact the code standards for Lua?

Obviously, as I have created a switch patch for Lua (based on computed gotos) I have an interest in understanding the points being raised here! ;)


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})

Too bad you can't do something like this:

goto switch
goto exit
t = {function() goto something end, function() goto somethingElse end}