From 3deb0fe178f36e44e06a8d3e5d023c794c3ab980 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Thu, 20 Apr 2017 19:11:44 +1000 Subject: [PATCH] add a standalone optomisation program, strip.lua --- strip.lua | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 strip.lua diff --git a/strip.lua b/strip.lua new file mode 100644 index 0000000..cb8e3db --- /dev/null +++ b/strip.lua @@ -0,0 +1,41 @@ +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",""}, +{"coroutine%.","C."}, +{"table%.","T."}, +} +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 +print("\nBefore: "..sl.."\nAfter: "..tostring(ss:len()).."\n"..tostring(no).." optimisations made.\n") + +f=io.open(tA[2],"wb") +f:write(ss) +f:close() +