lua-users home
lua-l archive

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

We're *not* considering adding a case statement for Lua right now, but I once
saw a syntax that seemed ok. I think it was in a toy language (or maybe it was

CASE a + b DO             Selection is done with a case
  0 => b := b * b         statement.  The selector may be a
       END                variable or an expression.  Each
  1 => b := b + a         branch begins with 1 constant
       a := a + 1         followed by '=>' and the statements
       END                to execute.  The first branch with a
  ELSE a := a + 1         constant matching the selector is
       b := 0             executed.  An optional ELSE clause
END                       may be the last branch.  If no branch
                          matches, control passes to the
                          statement following the CASE.

If not yacc conflicts exist, I'd probably go for the simpler

CASE a + b DO
  0 : b = b * b
  1 :  b = b + a
       a = a + 1
  ELSE a = a + 1 
       b = 0

In any case (no pun intended), anyone is allowed to add statements to Lua,
*as long as they do not distribute the variant and still call it Lua*.