lua-users home
lua-l archive

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

On Thu, Jun 12, 2014 at 7:12 PM, Rena <> wrote:
> On Wed, Jun 11, 2014 at 10:13 PM, Ross Bencina <>
> wrote:
>> The problem is in Lua (unless I'm missing something), you don't have
>> symbolic constants, so it's not possible to "compile" the second form to
>> anything better than a sequence of comparisons. If you use Lua variables,
>> their values are not constant, and so could change each time the switch is
>> executed (hence the equivalence to a linear if/else chain).
> Well, Lua *does* have constants:
> switch event.type
>   case 'move' print("I was moved to", event.x, event.y) break
>   case 'resize' print("I was resized to", event.w, event.h) break
>   case else print("I don't know how to deal with", event.type)
> end

And thanks to string interning, these are as fast as integer comparisons.

/s/ Adam