You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
633 B
Lua
34 lines
633 B
Lua
-- https://github.com/Tjakka5/Enum
|
|
|
|
local Enum = {}
|
|
local Meta = {
|
|
__index = function(_, k)
|
|
error("Attempt to index non-existant enum '" .. tostring(k) .. "'.", 2)
|
|
end,
|
|
__newindex = function()
|
|
error("Attempt to write to static enum", 2)
|
|
end,
|
|
}
|
|
|
|
function Enum.new(...)
|
|
local values = {...}
|
|
|
|
if type(values[1]) == "table" then
|
|
values = values[1]
|
|
end
|
|
|
|
local enum = {}
|
|
|
|
for i = 1, #values do
|
|
enum[values[i]] = values[i]
|
|
end
|
|
|
|
return setmetatable(enum, Meta)
|
|
end
|
|
|
|
return setmetatable(Enum, {
|
|
__call = function(_, ...)
|
|
return Enum.new(...)
|
|
end,
|
|
})
|