[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: mutually exclusive table entries
- From: Wesley Smith <wesley.hoke@...>
- Date: Tue, 12 May 2009 15:28:31 -0700
Hi list,
I hit upon a construct using tables trying to solve the problem of how
to represent mutually exclusive values in a straightforward manner
without relying on control flow statements or function definitions. I
use this mostly in Lua scripts that represent data of some kind, which
motivates the desire to rely solely on tables. In the code below,
it's for holding platform-dependent data such as compilation flags
used by gcc on various platforms. I haven't run across code like this
before, so I thought I'd pass the idea along.
{
-- set the field flags according to the value held in OS
flags = ({
OSX = {
-- OSX flags
},
LINUX = {
-- Linux flags
},
WIN32 = {
-- Windows flags
},
})[OS]
}
wes