Last active
August 30, 2021 19:17
-
-
Save lucasmz-dev/5a3f95bab3ba7a8d67e27743e2c49899 to your computer and use it in GitHub Desktop.
Enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local Enum = {} | |
function Enum:__index(enumObjectName) | |
error(enumObjectName.. " is not a valid EnumItem from".. self._name, 2) | |
end | |
function Enum:__newindex() | |
error("You cannot add new members to an Enum. -".. self._name, 2) | |
end | |
function Enum.new(enumName, members) | |
local self = { | |
_name = enumName | |
} | |
for enumObjectName in ipairs(members) do | |
self[enumObjectName] = enumObjectName | |
end | |
return setmetatable(self, Enum) | |
end | |
return Enum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment