Skip to content

Instantly share code, notes, and snippets.

@idleberg
Last active September 8, 2022 09:33
Show Gist options
  • Save idleberg/44a0607c9132e03284dd0a564e5af6c5 to your computer and use it in GitHub Desktop.
Save idleberg/44a0607c9132e03284dd0a564e5af6c5 to your computer and use it in GitHub Desktop.
RLE decoder that supports Pico-8's subset of Lua
-- Helper function to repeat string
function rep(char, multiplier)
local out = ""
for i=1, multiplier do
out = out..char
end
return out
end
-- RLE Decoder
function drle(data)
local decode, count, i = "", "", 1
while i <= #data do
local char = sub(data, i, i)
if type(tonum(char)) then
count = count..char
else
multiplier = tonum(count) or 1
decode = decode..rep(char, multiplier)
count = ""
end
i = i + 1
end
return decode
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment