Last active
August 21, 2018 13:57
-
-
Save neilpopham/8cfe7538b0c70d54ae3e8584cb9ec0e5 to your computer and use it in GitHub Desktop.
LUA implementation of PICO-8's fset()/fget() functions for use with TIC-80 (maybe)
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
local sprf={} | |
function fget(s,i) | |
if sprf[s+1]==nil then sprf[s+1]=0 end | |
if i==nil then | |
return math.floor(sprf[s+1]) | |
else | |
local b=2^i | |
return sprf[s+1] % (2*b) >= b | |
end | |
end | |
function fset(s,i,b) | |
if b==nil then | |
sprf[s+1]=i | |
else | |
local e | |
if sprf[s+1]==nil then | |
sprf[s+1]=0 | |
e=false | |
else | |
e=fget(s,i) | |
end | |
if (e and not b) or (not e and b) then | |
sprf[s+1]=sprf[s+1]+(b and 2^i or -2^i) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment