Skip to content

Instantly share code, notes, and snippets.

@Mullets-Gavin
Created December 7, 2020 20:04
Show Gist options
  • Save Mullets-Gavin/d0cead4a564a473d706d4e6b5b46028d to your computer and use it in GitHub Desktop.
Save Mullets-Gavin/d0cead4a564a473d706d4e6b5b46028d to your computer and use it in GitHub Desktop.
Lua Option
-- @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