This isn’t better than an elseif chain, inside a function passed to this switch module it cannot return to the function where the switch was called, it cannot break out or continue a loop which the switch is used in, and it cannot use the vararg from the function in which the switch was called from. This module also uses if
, so what is the benefit? Just avoiding elseif
chains doesn’t seem like a reason to use something like this, considering it must allocate a temporary object to do the switch (and later free that temporary object) and the previously mentioned things which are impossible inside of an inner function.
If mapping values using a Lua table doesn’t work, then using an array and table.find
should work (because it uses __eq) fine.
Also, what is the problem with elseif
chains?