[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Select (Switch) Case statement
- From: Eric Tetz <erictetz@...>
- Date: Wed, 1 Sep 2004 11:05:11 -0700
Asko Kauppi wrote:
> But it wouldn't hurt, either.
Well, it *would* make the language bigger -- without adding anything that can't
already be done just as easily and efficiently via if-elseif-else.
If they're going to be adding any major syntactical elements to Lua, I want
infix binary operators. ;)
Michael Roth wrote:
> local case, default = switch(i)
>
> if case(2) then
> print("two")
> end
I don't understand how that is preferable to:
if i == 2 then
print("two")
end
Mark Hamburg wrote:
> The problem with that version is that it builds the switch table every time.
YASS (Yet Another Switch Statement):
function switch(n, ...)
for i=1,arg.n do
if n == arg[i][1] then
arg[i][2]()
break
end
end
end
function case(n,f)
return {n,f}
end
...
switch( action,
case( DOG_BARK, function()
print("Arf!!!")
end),
case( DOG_BITE, function()
print("Chomp!")
end),
case( DOG_SLEEP, function()
print("Zzzzzz...")
end)
)