33-- License, v. 2.0. If a copy of the MPL was not distributed with this
44-- file, You can obtain one at https://mozilla.org/MPL/2.0/.
55
6- local luacomp = {}
7-
8- if arg and arg [0 ] == " luacomp" then
9- _G .luacomp = luacomp
6+ local function dprint (...)
7+ local args = {... }
8+ for i = 1 , # args do
9+ args [i ] = tostring (args [i ])
10+ end
11+ if (false ) then
12+ io.stderr :write (" DEBUG\t " .. table.concat (args ," \t " )," \n " )
13+ end
1014end
1115
12- local directives = {}
13-
16+ local stat = require ( " posix.sys.stat " )
17+ local dirent = require ( " posix.dirent " )
1418local unistd = require (" posix.unistd" )
1519
1620local function lc_error (name , msg )
@@ -30,14 +34,26 @@ local function lc_warning(name, msg)
3034 end
3135end
3236
37+ local luacomp = {}
38+ local directives = {}
39+
40+ -- #include "src/shell_var.lua"
41+ -- #include "src/luacomp_vars.lua"
42+ -- #include "src/directive_provider.lua"
43+ -- #include "src/cfg/minifier_providers.lua"
44+
45+ @[[ if not svar.get("LIBLUACOMP") then]]
46+ _G .luacomp = luacomp
47+ @[[ end]]
48+
3349function luacomp .error (msg )
34- local inf = debug.getinfo (1 )
50+ local inf = debug.getinfo (2 )
3551 local name = (inf and inf .short_src :match (" [^/]+$" ):gsub (" ^[=@]" , " " )) or " luacomp"
3652 lc_error (name , msg )
3753end
3854
3955function luacomp .warning (msg )
40- local inf = debug.getinfo (1 )
56+ local inf = debug.getinfo (2 )
4157 local name = (inf and inf .short_src :match (" [^/]+$" ):gsub (" ^[=@]" , " " )) or " luacomp"
4258 lc_warning (name , msg )
4359end
4662-- #include "src/generator2.lua"
4763
4864function luacomp .process_file (file , fname , dry )
65+ @[[ if not svar.get("LIBLUACOMP") then]]
4966 io.stderr :write (" PROC\t " , fname , " \n " )
67+ @[[ end]]
5068 if type (file ) == " string" then
5169 file = io.open (file , " r" )
5270 end
@@ -64,4 +82,22 @@ function luacomp.process_string(str, name, dry)
6482 end
6583 -- error("TODO: implement generation")
6684 return generator .run_gcode (name , gcode )
67- end
85+ end
86+
87+ function luacomp .run_minifier (minifier , code )
88+ local min = providers [minifier ]
89+ if not minifier then
90+ lc_error (" luacomp" , " Postprocessor " .. minifier .. " not found!" )
91+ -- io.stderr:write("ERROR: Postprocessor `"..args.minifier.."' not found!\n")
92+ -- os.exit(1)
93+ end
94+ local rcode , err = min (code )
95+ if (not rcode ) then
96+ lc_error (args .minifier , " Postprocessor error:\n " .. err )
97+ end
98+ return rcode
99+ end
100+
101+ @[[ if svar.get("LIBLUACOMP") then]]
102+ return luacomp
103+ @[[ end]]
0 commit comments