summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/data-lua.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/data-lua.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/data-lua.lua148
1 files changed, 60 insertions, 88 deletions
diff --git a/Master/texmf-dist/tex/context/base/data-lua.lua b/Master/texmf-dist/tex/context/base/data-lua.lua
index 7e3d92585ab..0e7c81181bb 100644
--- a/Master/texmf-dist/tex/context/base/data-lua.lua
+++ b/Master/texmf-dist/tex/context/base/data-lua.lua
@@ -16,83 +16,83 @@ local addsuffix = file.addsuffix
local P, S, Cs, lpegmatch = lpeg.P, lpeg.S, lpeg.Cs, lpeg.match
-local libsuffixes = { 'tex', 'lua' }
-local clibsuffixes = { 'lib' }
-local libformats = { 'TEXINPUTS', 'LUAINPUTS' }
-local clibformats = { 'CLUAINPUTS' }
-local helpers = package.helpers
+local luasuffixes = { 'tex', 'lua' }
+local libsuffixes = { 'lib' }
+local luaformats = { 'TEXINPUTS', 'LUAINPUTS' }
+local libformats = { 'CLUAINPUTS' }
+local helpers = package.helpers or { }
+local methods = helpers.methods or { }
trackers.register("resolvers.libraries", function(v) helpers.trace = v end)
trackers.register("resolvers.locating", function(v) helpers.trace = v end)
helpers.report = logs.reporter("resolvers","libraries")
+helpers.sequence = {
+ "already loaded",
+ "preload table",
+ "lua variable format",
+ "lib variable format",
+ "lua extra list",
+ "lib extra list",
+ "path specification",
+ "cpath specification",
+ "all in one fallback",
+ "not loaded",
+}
+
local pattern = Cs(P("!")^0 / "" * (P("/") * P(-1) / "/" + P("/")^1 / "/" + 1)^0)
-local function cleanpath(path) -- hm, don't we have a helper for this?
+function helpers.cleanpath(path) -- hm, don't we have a helper for this?
return resolvers.resolve(lpegmatch(pattern,path))
end
-helpers.cleanpath = cleanpath
-
-local loadedaslib = helpers.loadedaslib
-local loadedbylua = helpers.loadedbylua
-local loadedbypath = helpers.loadedbypath
-local notloaded = helpers.notloaded
-
-local getlibpaths = package.libpaths
-local getclibpaths = package.clibpaths
-
-function helpers.libpaths(libhash)
- local libpaths = { }
- for i=1,#libformats do
- local paths = resolvers.expandedpathlistfromvariable(libformats[i])
- for i=1,#paths do
- local path = cleanpath(paths[i])
- if not libhash[path] then
- libpaths[#libpaths+1] = path
- libhash[path] = true
- end
+local loadedaslib = helpers.loadedaslib
+local getextraluapaths = package.extraluapaths
+local getextralibpaths = package.extralibpaths
+local registerpath = helpers.registerpath
+local lualibfile = helpers.lualibfile
+
+local luaformatpaths
+local libformatpaths
+
+local function getluaformatpaths()
+ if not luaformatpaths then
+ luaformatpaths = { }
+ for i=1,#luaformats do
+ registerpath("lua format","lua",luaformatpaths,resolvers.expandedpathlistfromvariable(luaformats[i]))
end
end
- return libpaths
+ return luaformatpaths
end
-function helpers.clibpaths(clibhash)
- local clibpaths = { }
- for i=1,#clibformats do
- local paths = resolvers.expandedpathlistfromvariable(clibformats[i])
- for i=1,#paths do
- local path = cleanpath(paths[i])
- if not clibhash[path] then
- clibpaths[#clibpaths+1] = path
- clibhash[path] = true
- end
+local function getlibformatpaths()
+ if not libformatpaths then
+ libformatpaths = { }
+ for i=1,#libformats do
+ registerpath("lib format","lib",libformatpaths,resolvers.expandedpathlistfromvariable(libformats[i]))
end
end
- return clibpaths
+ return libformatpaths
end
-local function loadedbyformat(name,rawname,suffixes,islib)
+local function loadedbyformat(name,rawname,suffixes,islib,what)
local trace = helpers.trace
local report = helpers.report
- if trace then
- report("locating %a as %a using formats %a",rawname,name,suffixes)
- end
for i=1,#suffixes do -- so we use findfile and not a lookup loop
local format = suffixes[i]
local resolved = resolvers.findfile(name,format) or ""
if trace then
- report("checking %a using format %a",name,format)
+ report("%s format, identifying %a using format %a",what,name,format)
end
if resolved ~= "" then
if trace then
- report("lib %a located on %a",name,resolved)
+ report("%s format, %a found on %a",what,name,resolved)
end
if islib then
- return true, loadedaslib(resolved,rawname)
+ return loadedaslib(resolved,rawname)
else
- return true, loadfile(resolved)
+ return loadfile(resolved)
end
end
end
@@ -100,16 +100,6 @@ end
helpers.loadedbyformat = loadedbyformat
--- alternatively we could set the package.searchers
-
-local pattern = Cs((((1-S("\\/"))^0 * (S("\\/")^1/"/"))^0 * (P(".")^1/"/"+P(1))^1) * -1)
-
-local function lualibfile(name)
- return lpegmatch(pattern,name) or name
-end
-
-helpers.lualibfile = lualibfile
-
-- print(lualibfile("bar"))
-- print(lualibfile("foo.bar"))
-- print(lualibfile("crap/foo...bar"))
@@ -119,41 +109,23 @@ helpers.lualibfile = lualibfile
-- alternatively we could split in path and base and temporary set the libpath to path
-function helpers.loaded(name)
- local thename = lualibfile(name)
- local luaname = addsuffix(thename,"lua")
- local libname = addsuffix(thename,os.libsuffix)
- local libpaths = getlibpaths()
- local clibpaths = getclibpaths()
- local done, result = loadedbyformat(luaname,name,libsuffixes,false)
- if done then
- return result
- end
- local done, result = loadedbyformat(libname,name,clibsuffixes,true)
- if done then
- return result
- end
- local done, result = loadedbypath(luaname,name,libpaths,false,"lua")
- if done then
- return result
- end
- local done, result = loadedbypath(luaname,name,clibpaths,false,"lua")
- if done then
- return result
- end
- local done, result = loadedbypath(libname,name,clibpaths,true,"lib")
- if done then
- return result
- end
- local done, result = loadedbylua(name)
- if done then
- return result
+-- we could build a list of relevant paths but for tracing it's better to have the
+-- whole lot (ok, we could skip the duplicates)
+
+methods["lua variable format"] = function(name)
+ if helpers.trace then
+ helpers.report("%s format, checking %s paths","lua",#getluaformatpaths()) -- call triggers building
end
- return notloaded(name)
+ return loadedbyformat(addsuffix(lualibfile(name),"lua"),name,luasuffixes,false,"lua")
end
--- package.searchers[3] = nil -- get rid of the built in one (done in l-lua)
+methods["lib variable format"] = function(name)
+ if helpers.trace then
+ helpers.report("%s format, checking %s paths","lib",#getlibformatpaths()) -- call triggers building
+ end
+ return loadedbyformat(addsuffix(lualibfile(name),os.libsuffix),name,libsuffixes,true,"lib")
+end
-- package.extraclibpath(environment.ownpath)
-resolvers.loadlualib = require
+resolvers.loadlualib = require -- hm