Я использую это с мета-таблицами, чтобы имитировать enumTypes
local enumType_MT = {
__newindex = function (t, k, v)
if t [k] then
print ('redeclaring enum type ' .. k .. ' not permited')
else
rawset (t, k, {})
local c
for c = 1, #v do
rawset (t [k], v[c], c)
rawset (t[k], c, v[c])
end
end
end
}
local myEnumTypes = {}
setmetatable( myEnumTypes, enumType_MT )
myEnumTypes ['foo'] = {'brick_A', 'brick_B', 'brick_C'}
myEnumTypes ['doo'] = {'brick_E', 'brick_F', 'brick_G'}
myVar = myEnumTypes['foo'].brick_A
print (myVar) -- outputs 1
myVar = myEnumTypes['foo']['brick_C']
print (myVar) -- outputs 3
myVar = myEnumTypes['foo'][2]
print (myVar) -- outputs 'brick_B'
myVar = myEnumTypes['doo'].brick_A
print (myVar) -- outputs nil as brick_A not in doo
myVar = myEnumTypes['doo']['brick_C']
print (myVar) -- outputs nil as brick_C not in doo
myVar = myEnumTypes['doo'][2]
print (myVar) -- outputs 'brick_F'