From 974d9c6a280e42d01eb4a7c810900f9b4855e919 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 27 Sep 2015 18:43:41 +0200 Subject: [main, conf] prepare for deferred loading --- src/luaotfload-configuration.lua | 57 ++++++++++++++++++++-------------------- src/luaotfload-main.lua | 22 ++++++++-------- 2 files changed, 40 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/luaotfload-configuration.lua b/src/luaotfload-configuration.lua index e2cfbd8..263c8ad 100644 --- a/src/luaotfload-configuration.lua +++ b/src/luaotfload-configuration.lua @@ -6,7 +6,6 @@ -- AUTHOR: Philipp Gesang (Phg), -- AUTHOR: Dohyun Kim -- VERSION: same as Luaotfload --- MODIFIED: 2015-05-05 ------------------------------------------------------------------------------- -- @@ -18,17 +17,12 @@ if not modules then modules = { } end modules ["luaotfload-configuration"] = { license = "GNU GPL v2.0" } -luaotfload = luaotfload or { } -config = config or { } -config.luaotfload = { } - local status_file = "luaotfload-status" local luaotfloadstatus = require (status_file) -local stringexplode = string.explode +local string = string local stringfind = string.find local stringformat = string.format -local string = string local stringstrip = string.strip local stringsub = string.sub @@ -55,9 +49,7 @@ local lpegmatch = lpeg.match local commasplitter = lpeg.splitat "," local equalssplitter = lpeg.splitat "=" -local kpse = kpse local kpseexpand_path = kpse.expand_path -local kpselookup = kpse.lookup local lfs = lfs local lfsisfile = lfs.isfile @@ -67,16 +59,12 @@ local file = file local filejoin = file.join local filereplacesuffix = file.replacesuffix +local logreport = print -- overloaded later +local getwritablepath = caches.getwritablepath -local parsers = luaotfload.parsers - -local log = luaotfload.log -local logreport = log.report - -local config_parser = parsers.config -local stripslashes = parsers.stripslashes -local getwritablepath = caches.getwritablepath +local config_parser -- set later during init +local stripslashes -- set later during init ------------------------------------------------------------------------------- --- SETTINGS @@ -301,8 +289,11 @@ local set_name_resolver = function () end local set_loglevel = function () - log.set_loglevel (config.luaotfload.run.log_level) - return true + if luaotfload then + luaotfload.log.set_loglevel (config.luaotfload.run.log_level) + return true + end + return false end local build_cache_paths = function () @@ -846,7 +837,7 @@ local read = function (extra) return false end - local parsed = lpegmatch (parsers.config, raw) + local parsed = lpegmatch (config_parser, raw) if not parsed then logreport ("both", 2, "conf", "Error parsing configuration file %q.", readme) return false @@ -912,13 +903,23 @@ end --- EXPORTS ------------------------------------------------------------------------------- -luaotfload.default_config = default_config - -config.actions = { - read = read, - apply = apply, - apply_defaults = apply_defaults, - reconfigure = reconfigure, - dump = dump, +return { + init = function () + config.luaotfload = { } + logreport = luaotfload.log.report + local parsers = 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, + } + return true + end } diff --git a/src/luaotfload-main.lua b/src/luaotfload-main.lua index 3005f5a..73f9a75 100644 --- a/src/luaotfload-main.lua +++ b/src/luaotfload-main.lua @@ -15,6 +15,7 @@ local initial_log_level = 0 luaotfload = luaotfload or { } +config = config or { } local luaotfload = luaotfload luaotfload.log = luaotfload.log or { } luaotfload.version = "2.6" @@ -150,22 +151,21 @@ local logreport = log.report --doc]]-- -local tmp = load_luaotfload_module "parsers" --- fonts.conf and syntax -if not tmp.init () then - logreport ("log", 0, "load", "Failed to install the parsers.") -end - -load_luaotfload_module "configuration" --- configuration options - -if not config.actions.apply_defaults () then - logreport ("log", 0, "load", "Configuration unsuccessful.") -end - luaotfload.init.main (store) luaotfload.main = function () local starttime = os.gettimeofday () + local tmp = load_luaotfload_module "parsers" --- fonts.conf and syntax + if not tmp.init () then + logreport ("log", 0, "load", "Failed to install the parsers.") + end + + local tmp = load_luaotfload_module "configuration" --- configuration options + if not tmp.init() or not config.actions.apply_defaults () then + logreport ("log", 0, "load", "Configuration unsuccessful.") + end + luaotfload.loaders = load_luaotfload_module "loaders" --- Font loading; callbacks if not luaotfload.loaders.install () then logreport ("log", 0, "load", "Callback and loader initialization failed.") -- cgit v1.2.3