[latex3-commits] [git/LaTeX3-latex3-luaotfload] modules: Replace luaotfload.log with a luaotfload-log table (f5923e4)

Marcel Fabian Krüger tex at 2krueger.de
Sat May 23 14:56:29 CEST 2020


Repository : https://github.com/latex3/luaotfload
On branch  : modules
Link       : https://github.com/latex3/luaotfload/commit/f5923e4f10db5914ab64491c6406614d1bd785f9

>---------------------------------------------------------------

commit f5923e4f10db5914ab64491c6406614d1bd785f9
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Fri May 22 19:33:05 2020 +0200

    Replace luaotfload.log with a luaotfload-log table


>---------------------------------------------------------------

f5923e4f10db5914ab64491c6406614d1bd785f9
 src/luaotfload-auxiliary.lua     |  3 +-
 src/luaotfload-colors.lua        |  3 +-
 src/luaotfload-configuration.lua |  8 ++---
 src/luaotfload-database.lua      |  5 ++-
 src/luaotfload-diagnostics.lua   |  2 +-
 src/luaotfload-features.lua      |  7 ++--
 src/luaotfload-init.lua          |  7 ++--
 src/luaotfload-letterspace.lua   |  2 +-
 src/luaotfload-loaders.lua       |  2 +-
 src/luaotfload-log.lua           |  6 ++--
 src/luaotfload-main.lua          | 76 +++++++++++++++++-----------------------
 src/luaotfload-parsers.lua       |  3 +-
 src/luaotfload-resolvers.lua     |  2 +-
 src/luaotfload-tool.lua          |  9 +++--
 14 files changed, 58 insertions(+), 77 deletions(-)

diff --git a/src/luaotfload-auxiliary.lua b/src/luaotfload-auxiliary.lua
index 62ef5d5..9fb91db 100644
--- a/src/luaotfload-auxiliary.lua
+++ b/src/luaotfload-auxiliary.lua
@@ -18,8 +18,7 @@ end
 
 
 luaotfload                  = luaotfload or { }
-local log                   = luaotfload.log
-local logreport             = log.report
+local logreport             = require'luaotfload-log'.report
 local fonthashes            = fonts.hashes
 local encodings             = fonts.encodings
 local identifiers           = fonthashes.identifiers
diff --git a/src/luaotfload-colors.lua b/src/luaotfload-colors.lua
index 070fe86..881314f 100644
--- a/src/luaotfload-colors.lua
+++ b/src/luaotfload-colors.lua
@@ -31,7 +31,7 @@ explanation: http://tug.org/pipermail/luatex/2013-May/004305.html
 
 --doc]]--
 
-local logreport             = luaotfload and luaotfload.log.report or print
+local logreport             = require "luaotfload-log".report
 
 local nodedirect            = node.direct
 local newnode               = nodedirect.new
@@ -398,7 +398,6 @@ function luaotfload.set_colorhandler(cb)
 end
 
 return function ()
-    logreport = luaotfload.log.report
     if not fonts then
         logreport ("log", 0, "color",
                    "OTF mechanisms missing -- did you forget to \z
diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua
index 36bb31d..a419387 100644
--- a/src/luaotfload-configuration.lua
+++ b/src/luaotfload-configuration.lua
@@ -61,9 +61,10 @@ local file                    = file
 local filejoin                = file.join
 local filereplacesuffix       = file.replacesuffix
 
-local logreport               = print -- overloaded later
-local getwritablepath         = luaotfload.fontloader.caches.getwritablepath
+local log                     = require'luaotfload-log'
+local logreport               = log.report
 
+local getwritablepath         = luaotfload.fontloader.caches.getwritablepath
 
 local config_parser -- set later during init
 local stripslashes  -- set later during init
@@ -346,7 +347,7 @@ end
 
 local function set_loglevel ()
   if luaotfload then
-    luaotfload.log.set_loglevel (config.luaotfload.run.log_level)
+    log.set_loglevel (config.luaotfload.run.log_level)
     return true
   end
   return false
@@ -1012,7 +1013,6 @@ end
 
 return function ()
   config.luaotfload = { }
-  logreport         = luaotfload.log.report
   local parsers     = luaotfload.parsers
   config_parser     = parsers.config
   stripslashes      = parsers.stripslashes
diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua
index 062ce56..6fdfc91 100644
--- a/src/luaotfload-database.lua
+++ b/src/luaotfload-database.lua
@@ -125,8 +125,8 @@ end
 local lpeg                     = require "lpeg"
 local P, lpegmatch         = lpeg.P, lpeg.match
 
-local log                      = luaotfload.log
-local logreport                = log and log.report or print -- overriden later on
+local log                      = require "luaotfload-log"
+local logreport                = log.report
 local report_status            = log.names_status
 local report_status_start      = log.names_status_start
 local report_status_stop       = log.names_status_stop
@@ -3818,7 +3818,6 @@ return function ()
     --- we need to put some fallbacks into place for when running
     --- as a script
     if not fonts then return false end
-    logreport       = luaotfload.log.report
     local fonts     = fonts
     fonts.names     = fonts.names or names
     fonts.formats   = fonts.formats or { }
diff --git a/src/luaotfload-diagnostics.lua b/src/luaotfload-diagnostics.lua
index c90aa0f..e7ee76c 100644
--- a/src/luaotfload-diagnostics.lua
+++ b/src/luaotfload-diagnostics.lua
@@ -57,7 +57,7 @@ local lpeg                     = require "lpeg"
 local C, Cg, Ct                = lpeg.C, lpeg.Cg, lpeg.Ct
 local lpegmatch                = lpeg.match
 
-local report                   = luaotfload.log.report
+local report                   = require "luaotfload-log".report
 local function out (...)
     report (false, 0, "diagnose", ...)
 end
diff --git a/src/luaotfload-features.lua b/src/luaotfload-features.lua
index 59fe42d..ce4c32e 100644
--- a/src/luaotfload-features.lua
+++ b/src/luaotfload-features.lua
@@ -46,11 +46,13 @@ local otf               = handlers.otf
 local config            = config or { luaotfload = { run = { } } }
 
 local as_script         = true
-local normalize         = function () end
+local normalize
 
 if config.luaotfload.run.live ~= false then
     normalize = otf.features.normalize
     as_script = false
+else
+    function normalize() end
 end
 
 --[[HH (font-xtx) --
@@ -62,8 +64,7 @@ function definers.getspecification(str)
     return "", str, "", ":", str
 end
 
-local log              = luaotfload.log
-local report           = log.report
+local report           = require'luaotfload-log'.report
 
 local stringgsub       = string.gsub
 local stringformat     = string.format
diff --git a/src/luaotfload-init.lua b/src/luaotfload-init.lua
index 1cc5823..1ee646b 100644
--- a/src/luaotfload-init.lua
+++ b/src/luaotfload-init.lua
@@ -44,8 +44,8 @@ local lfsisdir     = lfs.isdir
 
 --doc]]--
 
-local log        --- filled in after loading the log module
-local logreport  --- filled in after loading the log module
+local log = require'luaotfload-log'
+local logreport = log.report
 
 --[[doc--
 
@@ -237,9 +237,6 @@ local function init_main(early_hook)
 
   --doc]]--
 
-  luaotfload.loaders.luaotfload "log"
-  log       = luaotfload.log
-  logreport = log.report
   log.set_loglevel (default_log_level)
 
   logreport ("log", 4, "init", "Concealing callback.register().")
diff --git a/src/luaotfload-letterspace.lua b/src/luaotfload-letterspace.lua
index c013a3f..4549701 100644
--- a/src/luaotfload-letterspace.lua
+++ b/src/luaotfload-letterspace.lua
@@ -20,7 +20,7 @@ end
 --- This code diverged quite a bit from its origin in Context. Please
 --- do *not* report bugs on the Context list.
 
-local logreport          = luaotfload.log.report
+local logreport          = require "luaotfload-log".report
 
 local getmetatable       = getmetatable
 local setmetatable       = setmetatable
diff --git a/src/luaotfload-loaders.lua b/src/luaotfload-loaders.lua
index 02dd835..2afecd6 100644
--- a/src/luaotfload-loaders.lua
+++ b/src/luaotfload-loaders.lua
@@ -24,7 +24,7 @@ end
 if not lualibs    then error "this module requires Luaotfload" end
 if not luaotfload then error "this module requires Luaotfload" end
 
-local logreport = luaotfload.log and luaotfload.log.report or print
+local logreport = require "luaotfload-log".report
 
 local function lua_reader (specification)
   local fullname = specification.resolved
diff --git a/src/luaotfload-log.lua b/src/luaotfload-log.lua
index 8013109..6299acf 100644
--- a/src/luaotfload-log.lua
+++ b/src/luaotfload-log.lua
@@ -29,9 +29,7 @@ because we lack a user interface to toggle per-subsystem tracing.
 local module_name       = "luaotfload" --- prefix for messages
 local debug             = debug
 
-luaotfload              = luaotfload or { }
-luaotfload.log          = luaotfload.log or { }
-local log               = luaotfload.log
+local log               = {}
 
 local ioopen            = io.open
 local iowrite           = io.write
@@ -391,4 +389,6 @@ local function texioreporter (message)
 end
 
 texio.reporter = texioreporter
+
+return log
 --- vim:shiftwidth=4:expandtab:ft=lua
diff --git a/src/luaotfload-main.lua b/src/luaotfload-main.lua
index 2d2e122..932c154 100644
--- a/src/luaotfload-main.lua
+++ b/src/luaotfload-main.lua
@@ -34,10 +34,9 @@ end
 
 local osgettimeofday              = os.gettimeofday
 config                            = config     or { }
-luaotfload                        = luaotfload or { }
-local luaotfload                  = luaotfload
-luaotfload.log                    = luaotfload.log or { }
-local logreport
+local luaotfload                  = luaotfload or { }
+_ENV.luaotfload                   = luaotfload
+local logreport                   = require "luaotfload-log".report --- Enable logging as soon as possible
 luaotfload.version                = ProvidesLuaModule.version
 luaotfload.loaders                = { }
 luaotfload.fontloader_package     = "reference"    --- default: from current Context
@@ -112,31 +111,23 @@ local type             = type
 --doc]]--
 
 local function make_loader_name (prefix, name)
-    local msg = luaotfload.log and luaotfload.log.report
-             or function (stream, lvl, cat, ...)
-                 if lvl > 1 then --[[not pressing]] return end
-                 texio.write_nl ("log",
-                                 string.format ("luaotfload | %s : ",
-                                                tostring (cat)))
-                 texio.write (string.format (...))
-             end
     if not name then
-        msg ("both", 0, "load",
-             "Fatal error: make_loader_name (%q, %q).",
-             tostring (prefix), tostring (name))
+        logreport ("both", 0, "load",
+                   "Fatal error: make_loader_name (%q, %q).",
+                   tostring (prefix), tostring (name))
         return "dummy-name"
     end
     name = tostring (name)
     if prefix == false then
-        msg ("log", 9, "load",
-             "No prefix requested, passing module name %q unmodified.",
-             name)
+        logreport ("log", 9, "load",
+                   "No prefix requested, passing module name %q unmodified.",
+                   name)
         return tostring (name) .. ".lua"
     end
     prefix = tostring (prefix)
-    msg ("log", 9, "load",
-         "Composing module name from constituents %s, %s.",
-         prefix, name)
+    logreport ("log", 9, "load",
+               "Composing module name from constituents %s, %s.",
+               prefix, name)
     return prefix .. "-" .. name .. ".lua"
 end
 
@@ -155,17 +146,16 @@ local function make_loader (prefix, load_helper)
         timing_info.t_load [name] = t_end - t_0
         if not ok then
             io.write "\n"
-            local msg = luaotfload.log and luaotfload.log.report or print
-            msg ("both", 0, "load", "FATAL ERROR")
-            msg ("both", 0, "load", "  × Failed to load %q module %q.",
-                 tostring (prefix), tostring (name))
+            logreport ("both", 0, "load", "FATAL ERROR")
+            logreport ("both", 0, "load", "  × Failed to load %q module %q.",
+                       tostring (prefix), tostring (name))
             local lines = string.split (data, "\n\t")
             if not lines then
-                msg ("both", 0, "load", "  × Error message: %q", data)
+                logreport ("both", 0, "load", "  × Error message: %q", data)
             else
-                msg ("both", 0, "load", "  × Error message:")
+                logreport ("both", 0, "load", "  × Error message:")
                 for i = 1, #lines do
-                    msg ("both", 0, "load", "    × %q.", lines [i])
+                    logreport ("both", 0, "load", "    × %q.", lines [i])
                 end
             end
             io.write "\n\n"
@@ -188,9 +178,9 @@ end
 --doc]]--
 
 local function dummy_loader (name)
-    luaotfload.log.report ("log", 3, "load",
-                           "Skipping module %q on purpose.",
-                           name)
+    logreport ("log", 3, "load",
+               "Skipping module %q on purpose.",
+               name)
 end
 
 local context_environment = setmetatable({}, {__index = _G})
@@ -204,22 +194,22 @@ local function context_isolated_load(name)
 end
 
 local function context_loader (name, path)
-    luaotfload.log.report ("log", 3, "load",
-                           "Loading module %q from Context.",
-                           name)
+    logreport ("log", 3, "load",
+               "Loading module %q from Context.",
+               name)
     local t_0 = osgettimeofday ()
     local modname = make_loader_name (false, name)
     local modpath = modname
     if path then
         if lfs.isdir (path) then
-            luaotfload.log.report ("log", 3, "load",
-                                   "Prepending path %q.",
-                                   path)
+            logreport ("log", 3, "load",
+                       "Prepending path %q.",
+                       path)
             modpath = file.join (path, modname)
         else
-            luaotfload.log.report ("both", 0, "load",
-                                   "Non-existant path %q specified, ignoring.",
-                                   path)
+            logreport ("both", 0, "load",
+                       "Non-existant path %q specified, ignoring.",
+                       path)
         end
     end
     local ret = context_isolated_load (modpath)
@@ -231,8 +221,8 @@ local function context_loader (name, path)
         --- yields a non-zero exit code. This isn’t per se indicating that
         --- something isn’t right, but against HH’s coding practices. We’ll
         --- silently ignore this ever happening on lower log levels.
-        luaotfload.log.report ("log", 4, "load",
-                               "Module %q returned %q.", modname, ret)
+        logreport ("log", 4, "load",
+                   "Module %q returned %q.", modname, ret)
     end
     return ret
 end
@@ -296,8 +286,6 @@ luaotfload.main = function ()
 
     local init      = loadmodule "init" --- fontloader initialization
     init (function ()
-
-        logreport = luaotfload.log.report
         initialize "parsers"         --- fonts.conf and syntax
         initialize "configuration"   --- configuration options
     end)
diff --git a/src/luaotfload-parsers.lua b/src/luaotfload-parsers.lua
index c2ac6f8..7c991d0 100644
--- a/src/luaotfload-parsers.lua
+++ b/src/luaotfload-parsers.lua
@@ -40,7 +40,7 @@ local filedirname       = file.dirname
 local io                = io
 local ioopen            = io.open
 
-local logreport         = print
+local logreport         = require "luaotfload-log".report
 
 local string            = string
 local stringsub         = string.sub
@@ -780,7 +780,6 @@ local parse_config      = Ct (ini_sections)
 --doc]=]--
 
 return function ()
-  logreport = luaotfload.log.report
   luaotfload.parsers = {
     --- parameters
     traversal_maxdepth    = traversal_maxdepth,
diff --git a/src/luaotfload-resolvers.lua b/src/luaotfload-resolvers.lua
index 7e8d15b..8747b02 100644
--- a/src/luaotfload-resolvers.lua
+++ b/src/luaotfload-resolvers.lua
@@ -49,7 +49,7 @@ local stringformat        = string.format
 local filesuffix          = file.suffix
 local fileremovesuffix    = file.removesuffix
 local luatexbase          = luatexbase
-local logreport           = luaotfload.log.report
+local logreport           = require "luaotfload-log".report
 
 --[[doc--
 
diff --git a/src/luaotfload-tool.lua b/src/luaotfload-tool.lua
index 3f0c872..8265b68 100755
--- a/src/luaotfload-tool.lua
+++ b/src/luaotfload-tool.lua
@@ -184,13 +184,13 @@ end
 
 require "alt_getopt"
 
-loadmodule "log"           --- this populates the luaotfload.log.* namespace
+local log = require "luaotfload-log"
 loadmodule "parsers"       --- fonts.conf, configuration, and request syntax
 loadmodule "configuration" --- configuration file handling
 loadmodule "database"
 loadmodule "resolvers"     --- Font lookup
 
-local logreport
+local logreport = log.report
 
 local function init_modules ()
     --- NB we don’t command the logger at this point.
@@ -215,7 +215,6 @@ local function init_modules ()
             return false
         end
     end
-    logreport = luaotfload.log.report
     return ret
 end
 
@@ -752,7 +751,7 @@ local actions = { } --- (jobspec -> (bool * bool)) list
 function actions.loglevel (job)
     local lvl = job.log_level
     if lvl then
-        luaotfload.log.set_loglevel(lvl)
+        log.set_loglevel(lvl)
         logreport ("info", 3, "util", "Setting the log level to %d.", lvl)
         logreport ("log", 2, "util", "Lua=%q", _VERSION)
     end
@@ -1506,7 +1505,7 @@ local function process_cmdline ( ) -- unit -> jobspec
         elseif v == "log" then
             local str = optarg[n]
             if str then
-                finalizers = luaotfload.log.set_logout(str, finalizers)
+                finalizers = log.set_logout(str, finalizers)
             end
         elseif v == "find" then
             action_pending["query"] = true





More information about the latex3-commits mailing list.