mirror of
https://git.shadowkat.net/izaya/OC-PsychOS2.git
synced 2024-11-21 11:35:44 -05:00
add some simple minification filters to preproc, which can shrink the kernel significantly
This commit is contained in:
parent
ad99c438b3
commit
ff7ec50a94
@ -1,4 +1,4 @@
|
||||
local preproc = require "preproc"
|
||||
--local tA = {...}
|
||||
|
||||
preproc.minify = true
|
||||
preproc(...)
|
||||
|
31
preproc.lua
31
preproc.lua
@ -82,11 +82,40 @@ function preproc.directives.includepkglib(package, file, name) -- string string
|
||||
return string.format("package.loaded['%s'] = (function()\n%s\nend)()", name, preproc.directives.includepkgfile(package, file))
|
||||
end
|
||||
|
||||
local minify = true
|
||||
local minifyFilters = {
|
||||
{"%-%-%[%[.-%]%]",""},
|
||||
{"%-%-.-\n","\n"},
|
||||
{"\n[ \t]+","\n"},
|
||||
{"%s?%.%.%s?",".."},
|
||||
{"%s?==%s?","=="},
|
||||
{"%s?~=%s?","~="},
|
||||
{"%s?>=%s?",">="},
|
||||
{"%s?<=%s?","<="},
|
||||
{"%s?>%s?",">"},
|
||||
{"%s?<%s?","<"},
|
||||
{"%s?=%s?","="},
|
||||
{"%s?,%s?",","},
|
||||
{",\n",","},
|
||||
{"\n\n+","\n"},
|
||||
{"[ \t]\n","\n"},
|
||||
{"%{%s+","{"},
|
||||
{"%s+%}","}"}
|
||||
}
|
||||
|
||||
return setmetatable(preproc,{__call=function(_,...)
|
||||
local tA = {...}
|
||||
local out = table.remove(tA,#tA)
|
||||
local f,e = io.open(out,"wb")
|
||||
if not f then error("unable to open file "..out..": "..e) end
|
||||
f:write(preproc.preproc(table.unpack(tA)))
|
||||
local out = preproc.preproc(table.unpack(tA))
|
||||
if preproc.minify then
|
||||
local olen = #out
|
||||
for k,v in ipairs(minifyFilters) do
|
||||
out = out:gsub(v[1],v[2])
|
||||
end
|
||||
print(olen, #out)
|
||||
end
|
||||
f:write(out)
|
||||
f:close()
|
||||
end})
|
||||
|
Loading…
Reference in New Issue
Block a user