1
0
pretty/table_type.lua

26 lines
734 B
Lua
Raw Normal View History

2017-07-17 19:33:11 +00:00
-- TODO: I don't like to have such tiny modules. Either merge into another
-- module or provide the funtionallity with another approach.
--------------------------------------------------------------------------------
-- Enum
local enum_metatable = {
__tostring = function (e) return 'Enum:' .. e.name or 'Enum: no name' end,
__concat = function (a, b) return tostring(a) .. tostring(b) end,
}
local function enum (t)
local e = {}
for _, v in ipairs(t) do
e[v] = setmetatable({ name = v }, enum_metatable)
end
return e
end
--------------------------------------------------------------------------------
local TABLE_TYPE = enum { 'EMPTY', 'SEQUENCE', 'STRING_MAP', 'PURE_MAP', 'MIXED', 'SET' }
return TABLE_TYPE