[latex3-commits] [git/LaTeX3-latex3-luaotfload] modules: Modulize configuration (32f3266)
Marcel Fabian Krüger
tex at 2krueger.de
Sun May 24 05:23:40 CEST 2020
Repository : https://github.com/latex3/luaotfload
On branch : modules
Link : https://github.com/latex3/luaotfload/commit/32f3266baa73d9fef15230b33290636242a9f290
>---------------------------------------------------------------
commit 32f3266baa73d9fef15230b33290636242a9f290
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Sun May 24 05:23:40 2020 +0200
Modulize configuration
>---------------------------------------------------------------
32f3266baa73d9fef15230b33290636242a9f290
src/luaotfload-colors.lua | 7 ++-
src/luaotfload-configuration.lua | 110 ++++++++++++++++++---------------------
src/luaotfload-database.lua | 36 ++++++-------
src/luaotfload-diagnostics.lua | 8 +--
src/luaotfload-features.lua | 4 +-
src/luaotfload-fontloader.lua | 3 +-
src/luaotfload-loaders.lua | 2 +-
src/luaotfload-main.lua | 3 +-
src/luaotfload-resolvers.lua | 5 +-
src/luaotfload-tool.lua | 38 +++-----------
testfiles/aaaaa-luakern.lvt | 2 +-
11 files changed, 94 insertions(+), 124 deletions(-)
diff --git a/src/luaotfload-colors.lua b/src/luaotfload-colors.lua
index 881314f..ab718c6 100644
--- a/src/luaotfload-colors.lua
+++ b/src/luaotfload-colors.lua
@@ -56,8 +56,6 @@ local setattribute = nodedirect.set_attribute
local stringformat = string.format
local identifiers = fonts.hashes.identifiers
-local add_color_callback --[[ this used to be a global‽ ]]
-
--[[doc--
Color string parser.
--doc]]--
@@ -285,10 +283,11 @@ end
local color_callback_name = "luaotfload.color_handler"
local color_callback_activated = 0
local add_to_callback = luatexbase.add_to_callback
+local config = require 'luaotfload-configuration'
--- unit -> unit
-add_color_callback = function ( )
- color_callback = config.luaotfload.run.color_callback
+local function add_color_callback ( )
+ color_callback = config.run.color_callback
if not color_callback then
color_callback = "post_linebreak_filter"
end
diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua
index b9b702e..e252612 100644
--- a/src/luaotfload-configuration.lua
+++ b/src/luaotfload-configuration.lua
@@ -30,7 +30,7 @@ local stringsub = string.sub
local tableappend = table.append
local tableconcat = table.concat
-local tablecopy = table.copy
+local tablecopy = table.fastcopy
local table = table
local tabletohash = table.tohash
@@ -66,8 +66,9 @@ local logreport = log.report
local getwritablepath = luaotfload.fontloader.caches.getwritablepath
-local config_parser -- set later during init
-local stripslashes -- set later during init
+local parsers = require 'luaotfload-parsers'
+local config_parser = parsers.config
+local stripslashes = parsers.stripslashes
-------------------------------------------------------------------------------
--- SETTINGS
@@ -265,6 +266,8 @@ local default_config = {
},
}
+local config = {}
+
-------------------------------------------------------------------------------
--- RECONFIGURATION TASKS
-------------------------------------------------------------------------------
@@ -283,7 +286,7 @@ local min_terminal_width = 40
--- short status messages, e.g. when building the database
--- online.
local function check_termwidth ()
- if config.luaotfload.misc.termwidth == nil then
+ if config.misc.termwidth == nil then
local tw = 79
if not ( os.type == "windows" --- Assume broken terminal.
or osgetenv "TERM" == "dumb")
@@ -302,7 +305,7 @@ local function check_termwidth ()
logreport ("log", 2, "db", "Assuming 79 cols terminal width.")
end
end
- config.luaotfload.misc.termwidth = tw
+ config.misc.termwidth = tw
end
return true
end
@@ -310,7 +313,7 @@ end
local function set_font_filter ()
local names = fonts.names
if names and names.set_font_filter then
- local formats = config.luaotfload.db.formats
+ local formats = config.db.formats
if not formats or formats == "" then
formats = default_config.db.formats
end
@@ -322,7 +325,7 @@ end
local function set_size_dimension ()
local names = fonts.names
if names and names.set_size_dimension then
- local dim = config.luaotfload.db.designsize_dimen
+ local dim = config.db.designsize_dimen
if not dim or dim == "" then
dim = default_config.db.designsize_dimen
end
@@ -335,7 +338,7 @@ local function set_name_resolver ()
local names = fonts.names
if names and names.resolve_cached then
--- replace the resolver from luatex-fonts
- if config.luaotfload.db.resolver == "cached" then
+ if config.db.resolver == "cached" then
logreport ("both", 2, "cache", "Caching of name: lookups active.")
names.resolvespec = fonts.names.lookup_font_name_cached
else
@@ -347,14 +350,14 @@ end
local function set_loglevel ()
if luaotfload then
- log.set_loglevel (config.luaotfload.run.log_level)
+ log.set_loglevel (config.run.log_level)
return true
end
return false
end
local function build_cache_paths ()
- local paths = config.luaotfload.paths
+ local paths = config.paths
local prefix = getwritablepath (paths.names_dir, "")
if not prefix then
@@ -378,7 +381,7 @@ end
local function set_default_features ()
- local default_features = config.luaotfload.default_features
+ local default_features = config.default_features
luaotfload.features = luaotfload.features or {
global = { },
defaults = { },
@@ -888,16 +891,22 @@ local process_options = function (opts)
return new
end
-local function apply (old, new)
- if not new then
- if not old then
+local function reconfigure()
+ for i = 1, #reconf_tasks do
+ local name, task = unpack (reconf_tasks[i])
+ logreport ("both", 3, "conf", "Launch post-configuration task %q.", name)
+ if not task () then
+ logreport ("both", 0, "conf", "Post-configuration task %q failed.", name)
return false
end
- return tablecopy (old)
- elseif not old then
- return tablecopy (new)
end
- local result = tablecopy (old)
+ return true
+end
+
+local function apply (new, ...)
+ if new == nil then
+ return reconfigure()
+ end
for name, section in next, new do
local t_section = type (section)
if t_section ~= table_t then
@@ -906,26 +915,14 @@ local function apply (old, new)
section, t_section)
--- ignore
else
- local currentsection = result[name]
+ local currentsection = config[name]
for var, val in next, section do
currentsection[var] = val
end
end
end
- result.status = luaotfloadstatus
- return result
-end
-
-local function reconfigure()
- for i = 1, #reconf_tasks do
- local name, task = unpack (reconf_tasks[i])
- logreport ("both", 3, "conf", "Launch post-configuration task %q.", name)
- if not task () then
- logreport ("both", 0, "conf", "Post-configuration task %q failed.", name)
- return false
- end
- end
- return true
+ config.status = luaotfloadstatus
+ return apply (...)
end
local function read (extra)
@@ -960,20 +957,21 @@ local function read (extra)
return ret
end
-local function apply_defaults ()
- local defaults = default_config
- local vars = read ()
+local function apply_defaults (extra, ...)
+ for name, section in next, default_config do
+ config[name] = tablecopy(section)
+ end
+ local vars = read (extra)
--- Side-effects galore ...
- config.luaotfload = apply (defaults, vars)
- return reconfigure ()
+ return apply (vars, ...)
end
local function dump ()
- local sections = table.sortedkeys (config.luaotfload)
+ local sections = table.sortedkeys (config)
local confdata = { }
for i = 1, #sections do
local section = sections[i]
- local vars = config.luaotfload[section]
+ local vars = config[section]
local varnames = table.sortedkeys (vars)
local sformats = formatters[section]
if sformats then
@@ -1011,23 +1009,17 @@ end
--- EXPORTS
-------------------------------------------------------------------------------
-return function ()
- config.luaotfload = { }
- local parsers = require 'luaotfload-parsers'
- config_parser = parsers.config
- stripslashes = parsers.stripslashes
-
- luaotfload.default_config = default_config
- config.actions = {
- read = read,
- apply = apply,
- apply_defaults = apply_defaults,
- reconfigure = reconfigure,
- dump = dump,
- }
- if not apply_defaults () then
- logreport ("log", 0, "load",
- "Configuration unsuccessful: error loading default settings.")
- end
- return true
+setmetatable(config, {
+ __index = {
+ apply = apply_defaults,
+ reconfigure = reconfigure,
+ dump = dump,
+ },
+})
+
+-- luaotfload.default_config = default_config
+if not apply_defaults () then
+ logreport ("log", 0, "load",
+ "Configuration unsuccessful: error loading default settings.")
end
+return config
diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua
index 1fe6990..128b7f6 100644
--- a/src/luaotfload-database.lua
+++ b/src/luaotfload-database.lua
@@ -203,6 +203,7 @@ local unicode = require 'luaotfload-unicode'
local casefold = unicode.casefold
local alphnum_only = unicode.alphnum_only
+local config = require 'luaotfload-configuration'
local parsers = require 'luaotfload-parsers'
local name_index = nil --> upvalue for names.data
@@ -553,7 +554,7 @@ local fuzzy_limit = 1 --- display closest only
--- bool? -> -> bool? -> dbobj option
load_names = function (dry_run, no_rebuild)
local starttime = osgettimeofday ()
- local foundname, data = load_lua_file (config.luaotfload.paths.index_path_lua)
+ local foundname, data = load_lua_file (config.paths.index_path_lua)
if data then
logreport ("log", 0, "db",
@@ -634,7 +635,7 @@ end
--- unit -> unit
local function load_lookups ( )
- local foundname, data = load_lua_file(config.luaotfload.paths.lookup_path_lua)
+ local foundname, data = load_lua_file(config.paths.lookup_path_lua)
if data then
logreport ("log", 0, "cache", "Lookup cache loaded from %s.", foundname)
logreport ("term", 3, "cache",
@@ -755,7 +756,7 @@ lookup_font_file = function (filename)
end
end
- if not fonts_reloaded and config.luaotfload.db.update_live == true then
+ if not fonts_reloaded and config.db.update_live == true then
return reload_db (stringformat ("File not found: %s.", filename),
lookup_font_file,
filename)
@@ -1243,7 +1244,7 @@ lookup_font_name = function (specification)
end
if not resolved then
- if not fonts_reloaded and config.luaotfload.db.update_live == true then
+ if not fonts_reloaded and config.db.update_live == true then
return reload_db (stringformat ("Font %s not found.",
specification.name or "<?>"),
lookup_font_name,
@@ -2277,7 +2278,7 @@ end
--- indicates the number of characters already consumed on the
--- line.
local function truncate_string (str, restrict)
- local tw = config.luaotfload.misc.termwidth
+ local tw = config.misc.termwidth
local wd = tw - restrict
local len = utf8len (str)
if not len then
@@ -2867,7 +2868,7 @@ local function pull_values (entry)
entry.width = style.width
entry.pfmweight = style.pfmweight
- if config.luaotfload.db.strip == true then
+ if config.db.strip == true then
entry.file = nil
entry.names = nil
entry.style = nil
@@ -3146,12 +3147,12 @@ local function collect_font_filenames ()
logreport ("info", 4, "db", "Scanning the filesystem for font files.")
local filenames = { }
- local bisect = config.luaotfload.misc.bisect
- local max_fonts = config.luaotfload.db.max_fonts --- XXX revisit for lua 5.3 wrt integers
+ local bisect = config.misc.bisect
+ local max_fonts = config.db.max_fonts --- XXX revisit for lua 5.3 wrt integers
tableappend (filenames, collect_font_filenames_texmf ())
tableappend (filenames, collect_font_filenames_system ())
- local scan_local = config.luaotfload.db.scan_local == true
+ local scan_local = config.db.scan_local == true
if scan_local then
local localfonts, found = collect_font_filenames_local()
if found then
@@ -3392,8 +3393,7 @@ function update_names(currentnames, force, dry_run)
local n_new = 0
local n_rem = 0
- local conf = config.luaotfload
- if conf.run.live ~= false and conf.db.update_live == false then
+ if config.run.live ~= false and config.db.update_live == false then
logreport ("info", 2, "db", "Skipping database update.")
--- skip all db updates
return currentnames or name_index
@@ -3410,7 +3410,7 @@ function update_names(currentnames, force, dry_run)
"Updating the font names database"
.. (force and " forcefully." or "."))
- if config.luaotfload.db.skip_read == true then
+ if config.db.skip_read == true then
--- the difference to a “dry run” is that we don’t search
--- for font files entirely. we also ignore the “force”
--- parameter since it concerns only the font files.
@@ -3460,7 +3460,7 @@ function update_names(currentnames, force, dry_run)
end
--- pass 3 (optional): collect some stats about the raw font info
- if config.luaotfload.misc.statistics == true then
+ if config.misc.statistics == true then
targetnames.meta.statistics = collect_statistics
(targetnames.mappings)
end
@@ -3511,7 +3511,7 @@ end
--- unit -> bool
function save_lookups()
- local paths = config.luaotfload.paths
+ local paths = config.paths
local luaname, lucname = paths.lookup_path_lua, paths.lookup_path_luc
if fileiswritable (luaname) and fileiswritable (lucname) then
tabletofile (luaname, lookup_cache, true)
@@ -3548,12 +3548,12 @@ do
elseif currentnames.meta and currentnames.meta["local"] then
return false, "table contains local entries"
end
- local paths = config.luaotfload.paths
+ local paths = config.paths
local luaname, lucname = paths.index_path_lua, paths.index_path_luc
if fileiswritable (luaname) and fileiswritable (lucname) then
osremove (lucname)
local gzname = luaname .. ".gz"
- if config.luaotfload.db.compress then
+ if config.db.compress then
local serialized = tableserialize (currentnames, true)
gzipsave (gzname, serialized)
caches.compile (currentnames, "", lucname)
@@ -3671,7 +3671,7 @@ end
local function getwritablecachepath ( )
--- fonts.handlers.otf doesn’t exist outside a Luatex run,
--- so we have to improvise
- local writable = getwritablepath (config.luaotfload.paths.cache_dir, "")
+ local writable = getwritablepath (config.paths.cache_dir, "")
if writable then
return writable
end
@@ -3679,7 +3679,7 @@ end
local function getreadablecachepaths ( )
local readables = caches.getreadablepaths
- (config.luaotfload.paths.cache_dir)
+ (config.paths.cache_dir)
local result = { }
if readables then
for i=1, #readables do
diff --git a/src/luaotfload-diagnostics.lua b/src/luaotfload-diagnostics.lua
index 3433c7f..fe0be0e 100644
--- a/src/luaotfload-diagnostics.lua
+++ b/src/luaotfload-diagnostics.lua
@@ -66,6 +66,8 @@ local parsers = require "luaotfload-parsers"
local stripslashes = parsers.stripslashes
local splitcomma = parsers.splitcomma
+local config = require "luaotfload-configuration"
+
local function check_index (errcnt)
out "================= font names =================="
@@ -109,7 +111,7 @@ end
local function verify_files (errcnt)
out "================ verify files ================="
- local status = config.luaotfload.status
+ local status = config.status
local hashes = status.hashes
local notes = status.notes
if not hashes or #hashes == 0 then
@@ -256,7 +258,7 @@ local function check_conformance (spec, permissions, errcnt)
end
local function init_desired_permissions ()
- local paths = config.luaotfload.paths
+ local paths = config.paths
return {
{ "d", {"r","w"}, function () return caches.getwritablepath ("", "") end },
{ "d", {"r","w"}, paths.prefix },
@@ -654,7 +656,7 @@ local function diagnose (job)
end
if asked.repository == true then
- local status = config.luaotfload.status
+ local status = config.status
check_upstream (status.notes.revision)
asked.repository = nil
end
diff --git a/src/luaotfload-features.lua b/src/luaotfload-features.lua
index 549712b..e9f098b 100644
--- a/src/luaotfload-features.lua
+++ b/src/luaotfload-features.lua
@@ -43,12 +43,12 @@ local handlers = fonts.handlers
local fontidentifiers = fonts.hashes and fonts.hashes.identifiers
local otf = handlers.otf
-local config = config or { luaotfload = { run = { } } }
+local config = require "luaotfload-configuration"
local as_script = true
local normalize
-if config.luaotfload.run.live ~= false then
+if config.run.live ~= false then
normalize = otf.features.normalize
as_script = false
else
diff --git a/src/luaotfload-fontloader.lua b/src/luaotfload-fontloader.lua
index 70085f1..043c4aa 100644
--- a/src/luaotfload-fontloader.lua
+++ b/src/luaotfload-fontloader.lua
@@ -344,8 +344,7 @@ local function init_main(early_hook)
--doc]]--
- local fontloader = config.luaotfload and config.luaotfload.run.fontloader
- or "reference"
+ local fontloader = require'luaotfload-configuration'.run.fontloader or "reference"
fontloader = tostring (fontloader)
if fontloader == "reference" then
diff --git a/src/luaotfload-loaders.lua b/src/luaotfload-loaders.lua
index 2afecd6..ec1ed10 100644
--- a/src/luaotfload-loaders.lua
+++ b/src/luaotfload-loaders.lua
@@ -224,7 +224,7 @@ local install_callbacks = function ()
create_callback ("luaotfload.patch_font", "simple", dummy_function)
create_callback ("luaotfload.patch_font_unsafe", "simple", dummy_function)
purge_define_font ()
- local definer = config.luaotfload.run.definer or "patch"
+ local definer = require'luaotfload-configuration'.run.definer or "patch"
local selected_definer = definers[definer]
luaotfload.define_font = selected_definer
luatexbase.add_to_callback ("define_font",
diff --git a/src/luaotfload-main.lua b/src/luaotfload-main.lua
index 2d046fb..2d6db61 100644
--- a/src/luaotfload-main.lua
+++ b/src/luaotfload-main.lua
@@ -181,7 +181,6 @@ luaotfload.main = function ()
local init = loadmodule "fontloader" --- fontloader initialization
init (function ()
- initialize "configuration" --- configuration options
end)
initialize "loaders" --- Font loading; callbacks
@@ -191,7 +190,7 @@ luaotfload.main = function ()
local init_resolvers = loadmodule "resolvers" --- Font lookup
init_resolvers ()
- if not config.actions.reconfigure () then
+ if not require "luaotfload-configuration".reconfigure () then
logreport ("log", 0, "load", "Post-configuration hooks failed.")
end
diff --git a/src/luaotfload-resolvers.lua b/src/luaotfload-resolvers.lua
index 8747b02..c9e01c4 100644
--- a/src/luaotfload-resolvers.lua
+++ b/src/luaotfload-resolvers.lua
@@ -50,6 +50,7 @@ local filesuffix = file.suffix
local fileremovesuffix = file.removesuffix
local luatexbase = luatexbase
local logreport = require "luaotfload-log".report
+local config = require "luaotfload-configuration"
--[[doc--
@@ -109,7 +110,7 @@ end
local function resolve_name (specification)
local resolver = fonts.names.lookup_font_name_cached
- if config.luaotfload.run.resolver == "normal" then
+ if config.run.resolver == "normal" then
resolver = fonts.names.lookup_font_name
end
local resolved, subfont = resolver (specification)
@@ -218,7 +219,7 @@ local default_anon_sequence = {
}
local function resolve_anon (specification)
- return resolve_sequence (config.luaotfload.run.anon_sequence, specification)
+ return resolve_sequence (config.run.anon_sequence, specification)
end
--[[doc--
diff --git a/src/luaotfload-tool.lua b/src/luaotfload-tool.lua
index f1da05b..b53970d 100755
--- a/src/luaotfload-tool.lua
+++ b/src/luaotfload-tool.lua
@@ -88,23 +88,6 @@ string.quoted = string.quoted or function (str)
return string.format("%q",str)
end
---[[doc--
-
- XXX:
- Creating the config table will be moved to the common
- initialization when the times comes.
-
---doc]]--
-
-config = config or { }
-local config = config
-config.luaotfload = config.luaotfload or { }
-
-config.lualibs = config.lualibs or { }
-config.lualibs.verbose = false
-config.lualibs.prefer_merged = true
-config.lualibs.load_extended = true
-
require "lualibs"
local iosavedata = io.savedata
@@ -117,6 +100,8 @@ local tablesortedkeys = table.sortedkeys
local tabletohash = table.tohash
local splitcomma = require "luaotfload-parsers".splitcomma
+local config = require "luaotfload-configuration"
+
--[[doc--
\fileent{luatex-basics-gen.lua} calls functions from the
\luafunction{texio.*} library; too much for our taste.
@@ -311,7 +296,7 @@ Enter 'luaotfload-tool --help' for a larger list of options.
local function help_msg (version)
local template = help_messages[version]
- local paths = config.luaotfload.paths
+ local paths = config.paths
local names_plain = paths.index_path_lua
local names_gzip = names_plain .. ".gz"
local names_bin = paths.index_path_luc
@@ -320,7 +305,7 @@ local function help_msg (version)
luaotfload.self,
names_gzip,
names_bin,
- caches.getwritablepath (config.luaotfload.paths.cache_dir, "")))
+ caches.getwritablepath (config.paths.cache_dir, "")))
end
local about = [[
@@ -336,7 +321,7 @@ local function version_msg ( )
local meta = fonts.names.getmetadata ()
local runtime = luaotfload.runtime
- local notes = config.luaotfload.status
+ local notes = config.status
local notes = status and status.notes or { }
out (about, luaotfload.self)
@@ -759,14 +744,7 @@ function actions.loglevel (job)
end
function actions.config (job)
- local defaults = luaotfload.default_config
- local vars = config.actions.read (job.extra_config)
- config.luaotfload = config.actions.apply (defaults, vars)
- config.luaotfload = config.actions.apply (config.luaotfload, job.config)
-
- --inspect(config.luaotfload)
- --os.exit()
- if not config.actions.reconfigure () then
+ if not config.apply(job.extra_config, job.config) then
return false, false
end
return true, true
@@ -778,7 +756,7 @@ function actions.version (job)
end
function actions.dumpconf (job)
- config.actions.dump ()
+ config.dump ()
return true, false
end
@@ -1093,7 +1071,7 @@ local function bisect_run ()
nsteps, lo, hi, pivot)
logreport ("info", 1, "bisect", "Step %d: Testing fonts from %d to %d.",
currentstep, lo, pivot)
- config.luaotfload.misc.bisect = { lo, pivot }
+ config.misc.bisect = { lo, pivot }
return true, true
end
diff --git a/testfiles/aaaaa-luakern.lvt b/testfiles/aaaaa-luakern.lvt
index 635b9a3..a16424e 100644
--- a/testfiles/aaaaa-luakern.lvt
+++ b/testfiles/aaaaa-luakern.lvt
@@ -13,7 +13,7 @@ abc
%texio.write_nl(table.serialize(info))}
\begin{luacode}
-texio.write_nl(luaotfload.version .. " with " .. string.gsub(tostring(config.luaotfload.run.fontloader),"[%-]","xxx"))
+texio.write_nl(luaotfload.version .. " with " .. string.gsub(tostring(require'luaotfload-configuration'.run.fontloader),"[%-]","xxx"))
-- t = {kpse.lookup("luaotfload-main.lua",{["all"]=true})}
--
More information about the latex3-commits
mailing list.