lua-users home
lua-l archive

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

On Thu, Jun 26, 2014 at 6:55 AM, Paige DePol <> wrote:
> On Jun 11, 2014, at 3:29 AM, Axel Kittenberger <> wrote:
>> But a switch statement in most script languages (like in Javascript) is syntactic sugar for if/else! That has always been the argument from the Lua team to why there is no switch statement in Lua. Not like for example in C where it is in fact a computed goto.
> I have created a switch statement patch[1] for Lua, it uses a jump table (aka computed goto) and is considerably faster than the standard if/else structures... however, applying it to vanilla Lua does present one large issue.
> Lua itself has no support for symbolic constants, thus the case values of the switch statement my patch adds have to be literal constants. This leads to the use of magic numbers which hurts overall code quality.
> This, I believe, is one of the major reasons Lua does not yet have a switch statement. Without symbolic constants any switch statement added to vanilla Lua could only ever be syntactic sugar for an if/else chain.

I always assumed it was because a table of functions is as good as a
switch statement...