[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Switch Tables
- From: "McMorris, Patrick" <pmcmorris@...>
- Date: Thu, 2 Aug 2007 16:38:11 -0700
This will handle the else case but I don't believe that it handles the x
< 10 case correctly.
Patrick
-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Anders Bergh
Sent: Thursday, August 02, 2007 2:16 PM
To: Lua list
Subject: Re: Switch Tables
On 8/2/07, W. C. Bubel <inmatarian@gmail.com> wrote:
> However, I'm wondering what the table construction might be for a if
> series such as this
> if x < 10 then a()
> elseif x == 11 then b()
> elseif x == 12 then c()
> else d() end
>
I suppose you could use a metatable:
switch = setmetatable({[10]=a, [11]=b, [12]=c}, {__index = function()
return d end})
switch[x]()
--
Anders