Created
December 7, 2020 20:04
-
-
Save Mullets-Gavin/d0cead4a564a473d706d4e6b5b46028d to your computer and use it in GitHub Desktop.
Lua Option
This file contains hidden or 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
-- @Author: Mullets-Gavin | |
-- @Desc: Option is a custom lightweight version of Rusts' "Option" enum on the lua shared global in Roblox (change to _G outside of Roblox) | |
local Option = {} | |
Option.__index = Option | |
function Option:Match(result: table): boolean | |
if typeof(result.type) == 'string' then | |
return result.type == self.type | |
end | |
return typeof(result.type) == typeof(self.type) | |
end | |
function Option:Set(name: string, type: any): table | |
assert(shared.Option[name] == nil,Loader._Error.."Attempted to overwrite option '"..name.."'") | |
shared.Option[name] = {type = type} | |
return setmetatable(shared.Option[name],Option) | |
end | |
function Option:Get(name: string): table? | |
return shared.Option[name] | |
end | |
shared.Option = Option |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment