1
0
pretty/common.lua

27 lines
782 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 functionality with another approach.
2017-07-17 19:33:11 +00:00
--------------------------------------------------------------------------------
-- 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
--------------------------------------------------------------------------------
return {
TABLE_TYPE = enum { 'EMPTY', 'SEQUENCE', 'STRING_MAP', 'PURE_MAP', 'MIXED', 'SET' },
DISPLAY = { HIDE = 1, SMALL = 2, INLINE = 3, EXPAND = 4 },
}