diff --git a/src/shared/Enum.lua b/src/shared/Enum.luau similarity index 82% rename from src/shared/Enum.lua rename to src/shared/Enum.luau index 526114e..c53e91c 100644 --- a/src/shared/Enum.lua +++ b/src/shared/Enum.luau @@ -4,7 +4,11 @@ type EnumValue = any type EnumName = string +type MatchResult = any? + +type MatchList_f = {[string]: (...any?) -> MatchResult} type Enums = {[EnumName]: EnumValue} + type EnumsMetadata = { __index: (self: EnumsMetadata, i: EnumName) -> EnumValue?, __newindex: (self: EnumsMetadata, i: EnumName, v: EnumValue) -> () @@ -19,9 +23,6 @@ type CustonEnumsFunctions = { Remove: (Name: EnumName) -> () } -type MatchResult = any? -type MatchList_f = {[string]: (...any?) -> MatchResult} - local CustomEnum = {} :: CustomEnums local EnumMeta = {} :: EnumsMetadata @@ -50,22 +51,28 @@ end CustomEnum.Enums = setmetatable({}, EnumMeta) local function EnumMethods(Enum) - --Branch this out later + --Branch these out later function Enum:Match(Result: string, MatchList: MatchList_f): MatchResult local Return: MatchResult = nil - local b: boolean = false - for MatchEnumName, EnumFunc in MatchList do + for MatchEnumName: string, EnumFunc in MatchList do if MatchEnumName == Result then - Return = EnumFunc() + Return = type(EnumFunc) == "function" and EnumFunc() or EnumFunc break end end - if not Return and MatchList["_"] then + if Return ~= nil and MatchList["_"] then Return = MatchList["_"]() end return Return end + + function Enum:MatchThread(Result: string, MatchList: MatchList_f): (boolean, MatchResult) + task.synchronize() + return coroutine.resume(coroutine.create(function() + return self:Match(Result, MatchList) + end)) + end end function CustomEnum.Create(Name, EnumValue)