diff options
Diffstat (limited to 'Master/texmf-dist/tex/luatex/lualibs/lualibs-util-lua.lua')
-rw-r--r-- | Master/texmf-dist/tex/luatex/lualibs/lualibs-util-lua.lua | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-lua.lua b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-lua.lua index b3346006c94..1f531ef48e2 100644 --- a/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-lua.lua +++ b/Master/texmf-dist/tex/luatex/lualibs/lualibs-util-lua.lua @@ -10,16 +10,17 @@ if not modules then modules = { } end modules ['util-lua'] = { -- we will remove the 5.1 code some day soon local rep, sub, byte, dump, format = string.rep, string.sub, string.byte, string.dump, string.format -local load, loadfile, type = load, loadfile, type +local load, loadfile, type, collectgarbage = load, loadfile, type, collectgarbage utilities = utilities or {} utilities.lua = utilities.lua or { } local luautilities = utilities.lua local report_lua = logs.reporter("system","lua") +local report_mem = logs.reporter("system","lua memory") local tracestripping = false -local forcestupidcompile = true -- use internal bytecode compiler +local tracememory = false 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 @@ -41,7 +42,7 @@ luautilities.suffixes = { -- environment.loadpreprocessedfile can be set to a preprocessor -local function register(name) +local function register(name) -- makes no sense runtime if tracestripping then report_lua("stripped bytecode from %a",name or "unknown") end @@ -71,12 +72,15 @@ end -- quite subtle ... doing this wrong incidentally can give more bytes -function luautilities.loadedluacode(fullname,forcestrip,name) +function luautilities.loadedluacode(fullname,forcestrip,name,macros) -- quite subtle ... doing this wrong incidentally can give more bytes name = name or fullname + if macros then + macros = lua.macros + end local code, message - if environment.loadpreprocessedfile then - code, message = environment.loadpreprocessedfile(fullname) + if macros then + code, message = macros.loaded(fullname,true,false) else code, message = loadfile(fullname) end @@ -103,19 +107,27 @@ function luautilities.loadedluacode(fullname,forcestrip,name) end end -function luautilities.strippedloadstring(code,forcestrip,name) -- not executed +function luautilities.strippedloadstring(code,name,forcestrip) -- not executed local code, message = load(code) if not code then report_lua("loading of file %a failed:\n\t%s",name,message or "no message") end if forcestrip and luautilities.stripcode or luautilities.alwaysstripcode then register(name) - return load(dump(code,true)), 0 -- not yet executes + return load(dump(code,true)), 0 -- not yet executed else return code, 0 end end +function luautilities.loadstring(code,name) -- not executed + local code, message = load(code) + if not code then + report_lua("loading of file %a failed:\n\t%s",name,message or "no message") + end + return code, 0 +end + function luautilities.compile(luafile,lucfile,cleanup,strip,fallback) -- defaults: cleanup=false strip=true report_lua("compiling %a into %a",luafile,lucfile) os.remove(lucfile) @@ -176,3 +188,24 @@ setmetatable(finalizers, { function luautilities.registerfinalizer(f) finalizers[#finalizers+1] = f end + +function luautilities.checkmemory(previous,threshold,trace) -- threshold in MB + local current = collectgarbage("count") + if previous then + local checked = (threshold or 64)*1024 + local delta = current - previous + if current - previous > checked then + collectgarbage("collect") + local afterwards = collectgarbage("count") + if trace or tracememory then + report_mem("previous %r MB, current %r MB, delta %r MB, threshold %r MB, afterwards %r MB", + previous/1024,current/1024,delta/1024,threshold,afterwards) + end + return afterwards + elseif trace or tracememory then + report_mem("previous %r MB, current %r MB, delta %r MB, threshold %r MB", + previous/1024,current/1024,delta/1024,threshold) + end + end + return current +end |