squish.lua

branch
lua5.2
changeset 95
828e814152e0
parent 91
4608c7c025e5
child 98
61085789b12b
equal deleted inserted replaced
94:cf209451be5f 95:828e814152e0
2 2
3 -- Initialise LuaRocks if present 3 -- Initialise LuaRocks if present
4 pcall(require, "luarocks.require"); 4 pcall(require, "luarocks.require");
5 5
6 local short_opts = { v = "verbose", vv = "very_verbose", o = "output", q = "quiet", qq = "very_quiet", g = "debug" } 6 local short_opts = { v = "verbose", vv = "very_verbose", o = "output", q = "quiet", qq = "very_quiet", g = "debug" }
7 local opts = { use_http = false }; 7 local opts = { use_http = false, module_compat = not not _ENV };
8 8
9 for _, opt in ipairs(arg) do 9 for _, opt in ipairs(arg) do
10 if opt:match("^%-") then 10 if opt:match("^%-") then
11 local name = opt:match("^%-%-?([^%s=]+)()") 11 local name = opt:match("^%-%-?([^%s=]+)()")
12 name = (short_opts[name] or name):gsub("%-+", "_"); 12 name = (short_opts[name] or name):gsub("%-+", "_");
266 end 266 end
267 if data then 267 if data then
268 data = data:gsub("^#[^\r\n]*\r?\n", ""); -- Remove shebang if any (or we can't concat) 268 data = data:gsub("^#[^\r\n]*\r?\n", ""); -- Remove shebang if any (or we can't concat)
269 if not opts.debug then 269 if not opts.debug then
270 f:write("package.preload['", modulename, "'] = (function (...)\n"); 270 f:write("package.preload['", modulename, "'] = (function (...)\n");
271 if opts.module_compat then
272 f:write [[
273 local _ENV = _ENV;
274 local function module(name, ...)
275 local t = package.loaded[name] or _ENV[name] or { _NAME = name };
276 package.loaded[name] = t;
277 for i = 1, select("#", ...) do
278 (select(i, ...))(t);
279 end
280 _ENV = t;
281 _M = t;
282 return t;
283 end
284 ]];
285 end
271 f:write(data); 286 f:write(data);
272 f:write(" end)\n"); 287 f:write(" end)\n");
273 else 288 else
274 f:write("package.preload['", modulename, "'] = assert(loadstring(\n"); 289 f:write("package.preload['", modulename, "'] = assert(loadstring(\n");
275 f:write(("%q\n"):format(data)); 290 f:write(("%q\n"):format(data));

mercurial