summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/luat-run.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/luat-run.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/luat-run.lua137
1 files changed, 109 insertions, 28 deletions
diff --git a/Master/texmf-dist/tex/context/base/luat-run.lua b/Master/texmf-dist/tex/context/base/luat-run.lua
index b64a99fc6b8..51856640d2d 100644
--- a/Master/texmf-dist/tex/context/base/luat-run.lua
+++ b/Master/texmf-dist/tex/context/base/luat-run.lua
@@ -6,36 +6,44 @@ if not modules then modules = { } end modules ['luat-run'] = {
license = "see context related readme files"
}
-local format, rpadd = string.format, string.rpadd
+local format = string.format
+local insert = table.insert
-main = main or { }
+local trace_lua_dump = false trackers.register("system.dump", function(v) trace_lua_dump = v end)
+local trace_temp_files = false trackers.register("system.tempfiles", function(v) trace_temp_files = v end)
-local start_actions = { }
-local stop_actions = { }
+local report_lua = logs.reporter("system","lua")
+local report_tempfiles = logs.reporter("resolvers","tempfiles")
-function main.register_start_actions(...) table.insert(start_actions, ...) end
-function main.register_stop_actions (...) table.insert(stop_actions, ...) end
+luatex = luatex or { }
+local luatex = luatex
-main.show_tex_stat = main.show_tex_stat or function() end
-main.show_job_stat = main.show_job_stat or statistics.show_job_stat
+local startactions = { }
+local stopactions = { }
-function main.start()
+function luatex.registerstartactions(...) insert(startactions, ...) end
+function luatex.registerstopactions (...) insert(stopactions, ...) end
+
+luatex.showtexstat = luatex.showtexstat or function() end
+luatex.showjobstat = luatex.showjobstat or statistics.showjobstat
+
+local function start_run()
if logs.start_run then
logs.start_run()
end
- for _, action in next, start_actions do
- action()
+ for i=1,#startactions do
+ startactions[i]()
end
end
-function main.stop()
- for _, action in next, stop_actions do
- action()
+local function stop_run()
+ for i=1,#stopactions do
+ stopactions[i]()
end
- if main.show_job_stat then
+ if luatex.showjobstat then
statistics.show(logs.report_job_stat)
end
- if main.show_tex_stat then
+ if luatex.showtexstat then
for k,v in next, status.list() do
logs.report_tex_stat(k,v)
end
@@ -45,30 +53,103 @@ function main.stop()
end
end
-function main.start_shipout_page()
+local function start_shipout_page()
logs.start_page_number()
end
-function main.stop_shipout_page()
+local function stop_shipout_page()
logs.stop_page_number()
end
-function main.report_output_pages()
+local function report_output_pages()
end
-function main.report_output_log()
+local function report_output_log()
+end
+
+--~ local function show_open()
+--~ end
+
+--~ local function show_close()
+--~ end
+
+local function pre_dump_actions()
+ lua.finalize(trace_lua_dump and report_lua or nil)
+ statistics.reportstorage("log")
+ -- statistics.savefmtstatus("\jobname","\contextversion","context.tex")
end
-- this can be done later
-callbacks.register('start_run', main.start, "actions performed at the beginning of a run")
-callbacks.register('stop_run', main.stop, "actions performed at the end of a run")
+callbacks.register('start_run', start_run, "actions performed at the beginning of a run")
+callbacks.register('stop_run', stop_run, "actions performed at the end of a run")
+
+--~ callbacks.register('show_open', show_open, "actions performed when opening a file")
+--~ callbacks.register('show_close', show_close, "actions performed when closing a file")
-callbacks.register('report_output_pages', main.report_output_pages, "actions performed when reporting pages")
-callbacks.register('report_output_log', main.report_output_log, "actions performed when reporting log file")
+callbacks.register('report_output_pages', report_output_pages, "actions performed when reporting pages")
+callbacks.register('report_output_log', report_output_log, "actions performed when reporting log file")
-callbacks.register('start_page_number', main.start_shipout_page, "actions performed at the beginning of a shipout")
-callbacks.register('stop_page_number', main.stop_shipout_page, "actions performed at the end of a shipout")
+callbacks.register('start_page_number', start_shipout_page, "actions performed at the beginning of a shipout")
+callbacks.register('stop_page_number', stop_shipout_page, "actions performed at the end of a shipout")
-callbacks.register('process_input_buffer', false, "actions performed when reading data")
-callbacks.register('process_output_buffer', false, "actions performed when writing data")
+callbacks.register('process_input_buffer', false, "actions performed when reading data")
+callbacks.register('process_output_buffer', false, "actions performed when writing data")
+
+callbacks.register("pre_dump", pre_dump_actions, "lua related finalizers called before we dump the format") -- comes after \everydump
+
+-- an example:
+
+local tempfiles = { }
+
+function luatex.registertempfile(name,extrasuffix)
+ if extrasuffix then
+ name = name .. ".mkiv-tmp" -- maybe just .tmp
+ end
+ if trace_temp_files and not tempfiles[name] then
+ report_tempfiles("registering temporary file: %s",name)
+ end
+ tempfiles[name] = true
+ return name
+end
+
+function luatex.cleanuptempfiles()
+ for name, _ in next, tempfiles do
+ if trace_temp_files then
+ report_tempfiles("removing temporary file: %s",name)
+ end
+ os.remove(name)
+ end
+ tempfiles = { }
+end
+
+luatex.registerstopactions(luatex.cleanuptempfiles)
+
+-- for the moment here
+
+local synctex = false
+
+local report_system = logs.reporter("system")
+
+directives.register("system.synctex", function(v)
+ synctex = v
+ if v then
+ report_system("synctex functionality is enabled!")
+ else
+ report_system("synctex functionality is disabled!")
+ end
+ -- current this is bugged:
+ tex.synctex = synctex and 1 or 0
+ -- so for the moment we need:
+ if synctex then
+ tex.print("\\normalsynctex\\plusone")
+ else
+ tex.print("\\normalsynctex\\zerocount")
+ end
+end)
+
+statistics.register("synctex tracing",function()
+ if synctex or tex.synctex > 0 then
+ return "synctex has been enabled (extra log file generated)"
+ end
+end)