OC-PsychOS/strip.lua

40 lines
626 B
Lua
Raw Normal View History

2017-07-30 19:12:10 +10:00
tA={...}
f=io.open(tA[1])
ss=f:read("*a")
f:close()
print("Optimising source")
sl=tostring(ss:len())
no=0
replacements={
{" "," "},
{"\n ","\n"},
{"\n\n","\n"},
{" == ","=="},
{" ~= ","~="},
{" >= ",">="},
{" <= ","<="},
{" > ",">"},
{" < ","<"},
{" = ","="},
{", ",","},
{" %+ ","+"},
{" %- ","-"},
{" %/ ","/"},
{" %* ","*"},
{" \n","\n"},
{"%-%-.-\n",""},
}
for k,v in ipairs(replacements) do
while ss:find(v[1]) ~= nil do
ss=ss:gsub(v[1],v[2])
io.write(".")
no=no+1
end
end
2017-09-13 13:06:17 +10:00
print("\nBefore: "..sl.."\nAfter: "..tostring(ss:len()).."\nDelta: "..tostring(sl-ss:len()))
2017-07-30 19:12:10 +10:00
f=io.open(tA[2],"wb")
f:write(ss)
f:close()