diff options
author | Hans Hagen <pragma@wxs.nl> | 2012-08-11 11:43:00 +0200 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2012-08-11 11:43:00 +0200 |
commit | 7585ddb948c962d7cb485463b54b52d0925b26b2 (patch) | |
tree | e3b691c6b69cd46c4fb7ca8a444e215acf894062 /scripts | |
parent | fda5a913473511bc21c6424069fcbd520d12b6f0 (diff) | |
download | context-7585ddb948c962d7cb485463b54b52d0925b26b2.tar.gz |
beta 2012.08.11 11:43
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/context/lua/mtxrun.lua | 53 | ||||
-rw-r--r-- | scripts/context/stubs/mswin/mtxrun.lua | 53 | ||||
-rwxr-xr-x | scripts/context/stubs/unix/mtxrun | 53 |
3 files changed, 117 insertions, 42 deletions
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 3045b6866..f65c8c0ac 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -2962,6 +2962,11 @@ end file.isreadable = file.is_readable -- depricated file.iswritable = file.is_writable -- depricated +function file.size(name) + local a = attributes(name) + return a and a.size or 0 +end + -- todo: lpeg \\ / .. does not save much local checkedsplit = string.checkedsplit @@ -4877,6 +4882,7 @@ utilities.report = logs and logs.reporter("system") or print local tracestripping = false local forcestupidcompile = true luautilities.stripcode = true +luautilities.alwaysstripcode = false -- saves 1 meg on 7 meg compressed format file (2012.08.12) luautilities.nofstrippedchunks = 0 luautilities.nofstrippedbytes = 0 @@ -4962,7 +4968,7 @@ end -- ... end of borrowed code. local function strippedbytecode(code,forcestrip,name) - if forcestrip and luautilities.stripcode then + if (forcestrip and luautilities.stripcode) or luautilities.alwaysstripcode then return strip_code_pc(code,name) else return code, 0 @@ -4972,8 +4978,16 @@ end luautilities.stripbytecode = strip_code_pc luautilities.strippedbytecode = strippedbytecode +local function fatalerror(name) + utilities.report(format("fatal error in %q",name or "unknown")) +end + +-- quite subtle ... doing this wrong incidentally can give more bytes + + function luautilities.loadedluacode(fullname,forcestrip,name) -- quite subtle ... doing this wrong incidentally can give more bytes + name = name or fullname local code = loadfile(fullname) if code then code() @@ -4983,34 +4997,45 @@ function luautilities.loadedluacode(fullname,forcestrip,name) forcestrip = forcestrip(fullname) end if forcestrip then - local code, n = strip_code_pc(dump(code,name or fullname)) + local code, n = strip_code_pc(dump(code,name)) return loadstring(code), n + elseif luautilities.alwaysstripcode then + return loadstring(strip_code_pc(dump(code),name)) else return code, 0 end + elseif luautilities.alwaysstripcode then + return loadstring(strip_code_pc(dump(code),name)) else return code, 0 end end -function luautilities.strippedloadstring(str,forcestrip,name) -- better inline - if forcestrip and luautilities.stripcode then - local code, n = strip_code_pc(dump(loadstring(str)),name) - return loadstring(code), n - else - return loadstring(str) +function luautilities.strippedloadstring(code,forcestrip,name) -- not executed + local n = 0 + if (forcestrip and luautilities.stripcode) or luautilities.alwaysstripcode then + code = loadstring(code) + if not code then + fatalerror(name) + end + code, n = strip_code_pc(dump(code),name) end + return loadstring(code), n end local function stupidcompile(luafile,lucfile,strip) - local data = io.loaddata(luafile) - if data and data ~= "" then - data = dump(loadstring(data)) + local code = io.loaddata(luafile) + if code and code ~= "" then + code = loadstring(code) + if not code then + fatalerror() + end + code = dump(code) if strip then - data = strippedbytecode(data,true,luafile) -- last one is reported + code = strippedbytecode(code,true,luafile) -- last one is reported end - if data and data ~= "" then - io.savedata(lucfile,data) + if code and code ~= "" then + io.savedata(lucfile,code) end end end diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 3045b6866..f65c8c0ac 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -2962,6 +2962,11 @@ end file.isreadable = file.is_readable -- depricated file.iswritable = file.is_writable -- depricated +function file.size(name) + local a = attributes(name) + return a and a.size or 0 +end + -- todo: lpeg \\ / .. does not save much local checkedsplit = string.checkedsplit @@ -4877,6 +4882,7 @@ utilities.report = logs and logs.reporter("system") or print local tracestripping = false local forcestupidcompile = true luautilities.stripcode = true +luautilities.alwaysstripcode = false -- saves 1 meg on 7 meg compressed format file (2012.08.12) luautilities.nofstrippedchunks = 0 luautilities.nofstrippedbytes = 0 @@ -4962,7 +4968,7 @@ end -- ... end of borrowed code. local function strippedbytecode(code,forcestrip,name) - if forcestrip and luautilities.stripcode then + if (forcestrip and luautilities.stripcode) or luautilities.alwaysstripcode then return strip_code_pc(code,name) else return code, 0 @@ -4972,8 +4978,16 @@ end luautilities.stripbytecode = strip_code_pc luautilities.strippedbytecode = strippedbytecode +local function fatalerror(name) + utilities.report(format("fatal error in %q",name or "unknown")) +end + +-- quite subtle ... doing this wrong incidentally can give more bytes + + function luautilities.loadedluacode(fullname,forcestrip,name) -- quite subtle ... doing this wrong incidentally can give more bytes + name = name or fullname local code = loadfile(fullname) if code then code() @@ -4983,34 +4997,45 @@ function luautilities.loadedluacode(fullname,forcestrip,name) forcestrip = forcestrip(fullname) end if forcestrip then - local code, n = strip_code_pc(dump(code,name or fullname)) + local code, n = strip_code_pc(dump(code,name)) return loadstring(code), n + elseif luautilities.alwaysstripcode then + return loadstring(strip_code_pc(dump(code),name)) else return code, 0 end + elseif luautilities.alwaysstripcode then + return loadstring(strip_code_pc(dump(code),name)) else return code, 0 end end -function luautilities.strippedloadstring(str,forcestrip,name) -- better inline - if forcestrip and luautilities.stripcode then - local code, n = strip_code_pc(dump(loadstring(str)),name) - return loadstring(code), n - else - return loadstring(str) +function luautilities.strippedloadstring(code,forcestrip,name) -- not executed + local n = 0 + if (forcestrip and luautilities.stripcode) or luautilities.alwaysstripcode then + code = loadstring(code) + if not code then + fatalerror(name) + end + code, n = strip_code_pc(dump(code),name) end + return loadstring(code), n end local function stupidcompile(luafile,lucfile,strip) - local data = io.loaddata(luafile) - if data and data ~= "" then - data = dump(loadstring(data)) + local code = io.loaddata(luafile) + if code and code ~= "" then + code = loadstring(code) + if not code then + fatalerror() + end + code = dump(code) if strip then - data = strippedbytecode(data,true,luafile) -- last one is reported + code = strippedbytecode(code,true,luafile) -- last one is reported end - if data and data ~= "" then - io.savedata(lucfile,data) + if code and code ~= "" then + io.savedata(lucfile,code) end end end diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 3045b6866..f65c8c0ac 100755 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -2962,6 +2962,11 @@ end file.isreadable = file.is_readable -- depricated file.iswritable = file.is_writable -- depricated +function file.size(name) + local a = attributes(name) + return a and a.size or 0 +end + -- todo: lpeg \\ / .. does not save much local checkedsplit = string.checkedsplit @@ -4877,6 +4882,7 @@ utilities.report = logs and logs.reporter("system") or print local tracestripping = false local forcestupidcompile = true luautilities.stripcode = true +luautilities.alwaysstripcode = false -- saves 1 meg on 7 meg compressed format file (2012.08.12) luautilities.nofstrippedchunks = 0 luautilities.nofstrippedbytes = 0 @@ -4962,7 +4968,7 @@ end -- ... end of borrowed code. local function strippedbytecode(code,forcestrip,name) - if forcestrip and luautilities.stripcode then + if (forcestrip and luautilities.stripcode) or luautilities.alwaysstripcode then return strip_code_pc(code,name) else return code, 0 @@ -4972,8 +4978,16 @@ end luautilities.stripbytecode = strip_code_pc luautilities.strippedbytecode = strippedbytecode +local function fatalerror(name) + utilities.report(format("fatal error in %q",name or "unknown")) +end + +-- quite subtle ... doing this wrong incidentally can give more bytes + + function luautilities.loadedluacode(fullname,forcestrip,name) -- quite subtle ... doing this wrong incidentally can give more bytes + name = name or fullname local code = loadfile(fullname) if code then code() @@ -4983,34 +4997,45 @@ function luautilities.loadedluacode(fullname,forcestrip,name) forcestrip = forcestrip(fullname) end if forcestrip then - local code, n = strip_code_pc(dump(code,name or fullname)) + local code, n = strip_code_pc(dump(code,name)) return loadstring(code), n + elseif luautilities.alwaysstripcode then + return loadstring(strip_code_pc(dump(code),name)) else return code, 0 end + elseif luautilities.alwaysstripcode then + return loadstring(strip_code_pc(dump(code),name)) else return code, 0 end end -function luautilities.strippedloadstring(str,forcestrip,name) -- better inline - if forcestrip and luautilities.stripcode then - local code, n = strip_code_pc(dump(loadstring(str)),name) - return loadstring(code), n - else - return loadstring(str) +function luautilities.strippedloadstring(code,forcestrip,name) -- not executed + local n = 0 + if (forcestrip and luautilities.stripcode) or luautilities.alwaysstripcode then + code = loadstring(code) + if not code then + fatalerror(name) + end + code, n = strip_code_pc(dump(code),name) end + return loadstring(code), n end local function stupidcompile(luafile,lucfile,strip) - local data = io.loaddata(luafile) - if data and data ~= "" then - data = dump(loadstring(data)) + local code = io.loaddata(luafile) + if code and code ~= "" then + code = loadstring(code) + if not code then + fatalerror() + end + code = dump(code) if strip then - data = strippedbytecode(data,true,luafile) -- last one is reported + code = strippedbytecode(code,true,luafile) -- last one is reported end - if data and data ~= "" then - io.savedata(lucfile,data) + if code and code ~= "" then + io.savedata(lucfile,code) end end end |