Skip to content

Instantly share code, notes, and snippets.

@DarkWiiPlayer
Last active June 17, 2017 18:30
Show Gist options
  • Save DarkWiiPlayer/0a0a13f735a5121f8787ce1a1ce48e9b to your computer and use it in GitHub Desktop.
Save DarkWiiPlayer/0a0a13f735a5121f8787ce1a1ce48e9b to your computer and use it in GitHub Desktop.
#!/bin/lua
local lib = {}
function lib.pair(init)
local variable = init
return function()
return variable
end, function(value)
variable = value
return true
end
end
function lib.typed(value)
return function()
return value
end, function(new)
if type(value) == type(new) then
value = new
return true
else
return nil, ("Got %s, expected %s"):format(type(new), type(value))
end
end
end
function lib.static(init)
local variable = init
return function()
return variable
end, function()
return nil, "Static variables cannot be set"
end
end
function lib.wrap(pair)
return function(value)
if value then
return pair[2](value)
else
return pair[1]()
end
end
end
return lib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment