lua-users home
lua-l archive

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


On Wed, Jun 11, 2014 at 10:13 PM, Ross Bencina <rossb-lists@audiomulch.com> 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

--
Sent from my Game Boy.