Last active
September 8, 2022 09:33
-
-
Save idleberg/44a0607c9132e03284dd0a564e5af6c5 to your computer and use it in GitHub Desktop.
RLE decoder that supports Pico-8's subset of Lua
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
-- 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