Skip to content

Instantly share code, notes, and snippets.

@idleberg

idleberg/rle_dec.lua

Last active Apr 6, 2021
Embed
What would you like to do?
Pico-8 RLE Decoder
-- 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