Last active
June 17, 2017 18:30
-
-
Save DarkWiiPlayer/0a0a13f735a5121f8787ce1a1ce48e9b to your computer and use it in GitHub Desktop.
This file contains 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
#!/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