This commit is contained in:
2024-03-16 02:35:53 -04:00
parent 22cce63ef4
commit fc2f6589ec

View File

@@ -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)