Skip to content

Instantly share code, notes, and snippets.

@neilpopham
Last active August 21, 2018 13:57
Show Gist options
  • Save neilpopham/8cfe7538b0c70d54ae3e8584cb9ec0e5 to your computer and use it in GitHub Desktop.
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)
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