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