Skip to main content

Enum

Roblox Lua Enum library for supporting custom Enum types. Much of the API is based off of EnumExtender. The key difference between this library and ExumExtender is values of EnumItems can be assigned to anything rather than being limited to numbers.

Enums created under the same name will overwrite previous Enums. Custom Enums take priority over Roblox Enums.


API#

  • Enums
    • Enums.new(enumName: string, enumItems: List|Dictionary): Enum
    • Enums:GetStandardEnums(): Enums
    • Enums:FromValue(enumName: string, enumValue: any): EnumItem
    • Enums:Find(enumName: string): Enum
  • Enum
    • Enums:GetEnumItems(): {EnumItem}
  • EnumItem
    • stringName
    • anyValue
    • EnumEnumType

Examples#

local Enum = require(script.Parent.Enum)
print(Enum) --> Enumsprint(Enum.KeyCode) --> KeyCodeprint(Enum.KeyCode.W) --> Enum.KeyCode.Wprint(Enum.KeyCode.W.Name) --> Wprint(Enum.KeyCode.W.Value) --> 119print(Enum.KeyCode.W.EnumType) --> KeyCode
local TestEnum = Enum.new(    "TestEnum",    {        Foo = 0,        Bar = 1,    })print(Enum.TestEnum == TestEnum) --> true
print(Enum.TestEnum) --> TestEnumprint(Enum.TestEnum.Foo) --> Enum.TestEnum.Fooprint(Enum.TestEnum.Foo.Name) --> Fooprint(Enum.TestEnum.Foo.Value) --> 0 print(Enum.TestEnum.Foo.EnumType) --> TestEnum
print(Enum.TestEnum.Bar) --> Enum.TestEnum.Barprint(Enum.TestEnum.Bar.Name) --> Barprint(Enum.TestEnum.Bar.Value) --> 1print(Enum.TestEnum.Bar.EnumType) --> TestEnum
print(Enum.TestEnum:GetEnumItems())

This style of defining arguments is supported for compatability with EnumExtender.

local TestEnum = Enum.new(    "TestEnum",    {        [0] = Foo,        [1] = Bar,    })