Перечисления

Инициализация типов

-- No enum type: a table of constants
local PreciousMetal = {Platinum = 1, Gold = 2,
                       Silver = 3}
local Season = {Summer = 0, Fall = 1,
                Winter = 2, Spring = 3}

-- Names in a list, numbers from the position
local Planet = {}
local names = {"Mercury", "Venus", "Earth"}
for index, name in ipairs(names) do
  Planet[name] = index
end

local gold = PreciousMetal.Gold
-- gold = 2
local fall = Season.Fall
-- fall = 1
local earth = Planet.Earth
-- earth = 3

-- Reverse table: from a number back to the name
local season_names = {}
for name, value in pairs(Season) do
  season_names[value] = name
end
local fall_name = season_names[fall]
-- fall_name = Fall

print("gold = " .. gold)
print("fall = " .. fall)
print("earth = " .. earth)
print("fall_name = " .. fall_name)