summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/lua/mtxrun.lua37
-rw-r--r--scripts/context/stubs/mswin/mtxrun.lua37
-rwxr-xr-xscripts/context/stubs/unix/mtxrun37
3 files changed, 69 insertions, 42 deletions
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index f65c8c0ac..4af1453a1 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -4870,18 +4870,18 @@ if not modules then modules = { } end modules ['util-lua'] = {
license = "see context related readme files"
}
-local rep, sub, byte, dump = string.rep, string.sub, string.byte, string.dump
-local loadstring, loadfile = loadstring, loadfile
+local rep, sub, byte, dump, format = string.rep, string.sub, string.byte, string.dump, string.format
+local loadstring, loadfile, type = loadstring, loadfile, type
utilities = utilities or {}
utilities.lua = utilities.lua or { }
local luautilities = utilities.lua
-utilities.report = logs and logs.reporter("system") or print
+utilities.report = logs and logs.reporter("system") or print -- can be overloaded later
local tracestripping = false
-local forcestupidcompile = true
-luautilities.stripcode = true
+local forcestupidcompile = true -- use internal bytecode compiler
+luautilities.stripcode = true -- support stripping when asked for
luautilities.alwaysstripcode = false -- saves 1 meg on 7 meg compressed format file (2012.08.12)
luautilities.nofstrippedchunks = 0
luautilities.nofstrippedbytes = 0
@@ -5025,6 +5025,7 @@ end
local function stupidcompile(luafile,lucfile,strip)
local code = io.loaddata(luafile)
+ local n = 0
if code and code ~= "" then
code = loadstring(code)
if not code then
@@ -5032,30 +5033,39 @@ local function stupidcompile(luafile,lucfile,strip)
end
code = dump(code)
if strip then
- code = strippedbytecode(code,true,luafile) -- last one is reported
+ code, n = strippedbytecode(code,true,luafile) -- last one is reported
end
if code and code ~= "" then
io.savedata(lucfile,code)
end
end
+ return n
end
+local luac_normal = "texluac -o %q %q"
+local luac_strip = "texluac -s -o %q %q"
+
function luautilities.compile(luafile,lucfile,cleanup,strip,fallback) -- defaults: cleanup=false strip=true
utilities.report("lua: compiling %s into %s",luafile,lucfile)
os.remove(lucfile)
local done = false
+ if strip ~= false then
+ strip = true
+ end
if forcestupidcompile then
fallback = true
+ elseif strip then
+ done = os.spawn(format(luac_strip, lucfile,luafile)) == 0
else
- local command = "-o " .. string.quoted(lucfile) .. " " .. string.quoted(luafile)
- if strip ~= false then
- command = "-s " .. command
- end
- done = os.spawn("texluac " .. command) == 0 -- or os.spawn("luac " .. command) == 0
+ done = os.spawn(format(luac_normal,lucfile,luafile)) == 0
end
if not done and fallback then
- utilities.report("lua: dumping %s into %s (unstripped)",luafile,lucfile)
- stupidcompile(luafile,lucfile,strip)
+ local n = stupidcompile(luafile,lucfile,strip)
+ if n > 0 then
+ utilities.report("lua: %s dumped into %s (%i bytes stripped)",luafile,lucfile,n)
+ else
+ utilities.report("lua: %s dumped into %s (unstripped)",luafile,lucfile)
+ end
cleanup = false -- better see how bad it is
end
if done and cleanup == true and lfs.isfile(lucfile) and lfs.isfile(luafile) then
@@ -5071,7 +5081,6 @@ end
-
end -- of closure
do -- create closure to overcome 200 locals limit
diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua
index f65c8c0ac..4af1453a1 100644
--- a/scripts/context/stubs/mswin/mtxrun.lua
+++ b/scripts/context/stubs/mswin/mtxrun.lua
@@ -4870,18 +4870,18 @@ if not modules then modules = { } end modules ['util-lua'] = {
license = "see context related readme files"
}
-local rep, sub, byte, dump = string.rep, string.sub, string.byte, string.dump
-local loadstring, loadfile = loadstring, loadfile
+local rep, sub, byte, dump, format = string.rep, string.sub, string.byte, string.dump, string.format
+local loadstring, loadfile, type = loadstring, loadfile, type
utilities = utilities or {}
utilities.lua = utilities.lua or { }
local luautilities = utilities.lua
-utilities.report = logs and logs.reporter("system") or print
+utilities.report = logs and logs.reporter("system") or print -- can be overloaded later
local tracestripping = false
-local forcestupidcompile = true
-luautilities.stripcode = true
+local forcestupidcompile = true -- use internal bytecode compiler
+luautilities.stripcode = true -- support stripping when asked for
luautilities.alwaysstripcode = false -- saves 1 meg on 7 meg compressed format file (2012.08.12)
luautilities.nofstrippedchunks = 0
luautilities.nofstrippedbytes = 0
@@ -5025,6 +5025,7 @@ end
local function stupidcompile(luafile,lucfile,strip)
local code = io.loaddata(luafile)
+ local n = 0
if code and code ~= "" then
code = loadstring(code)
if not code then
@@ -5032,30 +5033,39 @@ local function stupidcompile(luafile,lucfile,strip)
end
code = dump(code)
if strip then
- code = strippedbytecode(code,true,luafile) -- last one is reported
+ code, n = strippedbytecode(code,true,luafile) -- last one is reported
end
if code and code ~= "" then
io.savedata(lucfile,code)
end
end
+ return n
end
+local luac_normal = "texluac -o %q %q"
+local luac_strip = "texluac -s -o %q %q"
+
function luautilities.compile(luafile,lucfile,cleanup,strip,fallback) -- defaults: cleanup=false strip=true
utilities.report("lua: compiling %s into %s",luafile,lucfile)
os.remove(lucfile)
local done = false
+ if strip ~= false then
+ strip = true
+ end
if forcestupidcompile then
fallback = true
+ elseif strip then
+ done = os.spawn(format(luac_strip, lucfile,luafile)) == 0
else
- local command = "-o " .. string.quoted(lucfile) .. " " .. string.quoted(luafile)
- if strip ~= false then
- command = "-s " .. command
- end
- done = os.spawn("texluac " .. command) == 0 -- or os.spawn("luac " .. command) == 0
+ done = os.spawn(format(luac_normal,lucfile,luafile)) == 0
end
if not done and fallback then
- utilities.report("lua: dumping %s into %s (unstripped)",luafile,lucfile)
- stupidcompile(luafile,lucfile,strip)
+ local n = stupidcompile(luafile,lucfile,strip)
+ if n > 0 then
+ utilities.report("lua: %s dumped into %s (%i bytes stripped)",luafile,lucfile,n)
+ else
+ utilities.report("lua: %s dumped into %s (unstripped)",luafile,lucfile)
+ end
cleanup = false -- better see how bad it is
end
if done and cleanup == true and lfs.isfile(lucfile) and lfs.isfile(luafile) then
@@ -5071,7 +5081,6 @@ end
-
end -- of closure
do -- create closure to overcome 200 locals limit
diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun
index f65c8c0ac..4af1453a1 100755
--- a/scripts/context/stubs/unix/mtxrun
+++ b/scripts/context/stubs/unix/mtxrun
@@ -4870,18 +4870,18 @@ if not modules then modules = { } end modules ['util-lua'] = {
license = "see context related readme files"
}
-local rep, sub, byte, dump = string.rep, string.sub, string.byte, string.dump
-local loadstring, loadfile = loadstring, loadfile
+local rep, sub, byte, dump, format = string.rep, string.sub, string.byte, string.dump, string.format
+local loadstring, loadfile, type = loadstring, loadfile, type
utilities = utilities or {}
utilities.lua = utilities.lua or { }
local luautilities = utilities.lua
-utilities.report = logs and logs.reporter("system") or print
+utilities.report = logs and logs.reporter("system") or print -- can be overloaded later
local tracestripping = false
-local forcestupidcompile = true
-luautilities.stripcode = true
+local forcestupidcompile = true -- use internal bytecode compiler
+luautilities.stripcode = true -- support stripping when asked for
luautilities.alwaysstripcode = false -- saves 1 meg on 7 meg compressed format file (2012.08.12)
luautilities.nofstrippedchunks = 0
luautilities.nofstrippedbytes = 0
@@ -5025,6 +5025,7 @@ end
local function stupidcompile(luafile,lucfile,strip)
local code = io.loaddata(luafile)
+ local n = 0
if code and code ~= "" then
code = loadstring(code)
if not code then
@@ -5032,30 +5033,39 @@ local function stupidcompile(luafile,lucfile,strip)
end
code = dump(code)
if strip then
- code = strippedbytecode(code,true,luafile) -- last one is reported
+ code, n = strippedbytecode(code,true,luafile) -- last one is reported
end
if code and code ~= "" then
io.savedata(lucfile,code)
end
end
+ return n
end
+local luac_normal = "texluac -o %q %q"
+local luac_strip = "texluac -s -o %q %q"
+
function luautilities.compile(luafile,lucfile,cleanup,strip,fallback) -- defaults: cleanup=false strip=true
utilities.report("lua: compiling %s into %s",luafile,lucfile)
os.remove(lucfile)
local done = false
+ if strip ~= false then
+ strip = true
+ end
if forcestupidcompile then
fallback = true
+ elseif strip then
+ done = os.spawn(format(luac_strip, lucfile,luafile)) == 0
else
- local command = "-o " .. string.quoted(lucfile) .. " " .. string.quoted(luafile)
- if strip ~= false then
- command = "-s " .. command
- end
- done = os.spawn("texluac " .. command) == 0 -- or os.spawn("luac " .. command) == 0
+ done = os.spawn(format(luac_normal,lucfile,luafile)) == 0
end
if not done and fallback then
- utilities.report("lua: dumping %s into %s (unstripped)",luafile,lucfile)
- stupidcompile(luafile,lucfile,strip)
+ local n = stupidcompile(luafile,lucfile,strip)
+ if n > 0 then
+ utilities.report("lua: %s dumped into %s (%i bytes stripped)",luafile,lucfile,n)
+ else
+ utilities.report("lua: %s dumped into %s (unstripped)",luafile,lucfile)
+ end
cleanup = false -- better see how bad it is
end
if done and cleanup == true and lfs.isfile(lucfile) and lfs.isfile(luafile) then
@@ -5071,7 +5081,6 @@ end
-
end -- of closure
do -- create closure to overcome 200 locals limit