diff options
Diffstat (limited to 'tex/context/base/trac-set.lua')
-rw-r--r-- | tex/context/base/trac-set.lua | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/tex/context/base/trac-set.lua b/tex/context/base/trac-set.lua index 9dc5dd9da..6f91e25f7 100644 --- a/tex/context/base/trac-set.lua +++ b/tex/context/base/trac-set.lua @@ -17,10 +17,11 @@ local allocate = utilities.storage.allocate utilities = utilities or { } local utilities = utilities -utilities.setters = utilities.setters or { } -local setters = utilities.setters -local data = { } -- maybe just local +local setters = utilities.setters or { } +utilities.setters = setters + +local data = { } -- We can initialize from the cnf file. This is sort of tricky as -- later defined setters also need to be initialized then. If set @@ -235,15 +236,8 @@ end local enable, disable, register, list, show = setters.enable, setters.disable, setters.register, setters.list, setters.show -local write_nl = texio and texio.write_nl or print - -local function report(setter,...) - local report = logs and logs.report - if report then - report(setter.name,...) - else -- fallback, as this module is loaded before the logger - write_nl(format("%-15s : %s\n",setter.name,format(...))) - end +function setters.report(setter,...) + print(format("%-15s : %s\n",setter.name,format(...))) end local function default(setter,name) @@ -261,14 +255,14 @@ function setters.new(name) -- we could use foo:bar syntax (but not used that oft setter = { data = allocate(), -- indexed, but also default and value fields name = name, - report = function(...) report (setter,...) end, - enable = function(...) enable (setter,...) end, - disable = function(...) disable (setter,...) end, - register = function(...) register(setter,...) end, - list = function(...) list (setter,...) end, - show = function(...) show (setter,...) end, - default = function(...) return default (setter,...) end, - value = function(...) return value (setter,...) end, + report = function(...) setters.report (setter,...) end, + enable = function(...) enable (setter,...) end, + disable = function(...) disable (setter,...) end, + register = function(...) register(setter,...) end, + list = function(...) list (setter,...) end, + show = function(...) show (setter,...) end, + default = function(...) return default (setter,...) end, + value = function(...) return value (setter,...) end, } data[name] = setter return setter @@ -278,9 +272,9 @@ trackers = setters.new("trackers") directives = setters.new("directives") experiments = setters.new("experiments") -local t_enable, t_disable, t_report = trackers .enable, trackers .disable, trackers .report -local d_enable, d_disable, d_report = directives .enable, directives .disable, directives .report -local e_enable, e_disable, e_report = experiments.enable, experiments.disable, experiments.report +local t_enable, t_disable = trackers .enable, trackers .disable +local d_enable, d_disable = directives .enable, directives .disable +local e_enable, e_disable = experiments.enable, experiments.disable -- nice trick: we overload two of the directives related functions with variants that -- do tracing (itself using a tracker) .. proof of concept @@ -290,28 +284,28 @@ local trace_experiments = false local trace_experiments = false trackers.regist function directives.enable(...) if trace_directives then - d_report("enabling: % t",{...}) + directives.report("enabling: % t",{...}) end d_enable(...) end function directives.disable(...) if trace_directives then - d_report("disabling: % t",{...}) + directives.report("disabling: % t",{...}) end d_disable(...) end function experiments.enable(...) if trace_experiments then - e_report("enabling: % t",{...}) + experiments.report("enabling: % t",{...}) end e_enable(...) end function experiments.disable(...) if trace_experiments then - e_report("disabling: % t",{...}) + experiments.report("disabling: % t",{...}) end e_disable(...) end @@ -319,11 +313,19 @@ end -- a useful example directives.register("system.nostatistics", function(v) - statistics.enable = not v + if statistics then + statistics.enable = not v + else + -- forget about it + end end) directives.register("system.nolibraries", function(v) - libraries = nil -- we discard this tracing for security + if libraries then + libraries = nil -- we discard this tracing for security + else + -- no libraries defined + end end) -- experiment |