summaryrefslogtreecommitdiff
path: root/tex/context/base/data-lua.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/data-lua.lua')
-rw-r--r--tex/context/base/data-lua.lua84
1 files changed, 75 insertions, 9 deletions
diff --git a/tex/context/base/data-lua.lua b/tex/context/base/data-lua.lua
index d7f6fdcf5..3005d5176 100644
--- a/tex/context/base/data-lua.lua
+++ b/tex/context/base/data-lua.lua
@@ -14,43 +14,109 @@ local trace_locating = false trackers.register("resolvers.locating", function(v
local gsub = string.gsub
-local libformats = { 'luatexlibs', 'tex', 'texmfscripts', 'othertextfiles' }
-local libpaths = file.split_path(package.path)
+local libformats = { 'luatexlibs', 'tex', 'texmfscripts', 'othertextfiles' } -- 'luainputs'
+local clibformats = { 'lib' }
+local libpaths = file.split_path(package.path)
+local clibpaths = file.split_path(package.cpath)
+
+local function thepath(...)
+ local t = { ... } t[#t+1] = "?.lua"
+ local path = file.join(unpack(t))
+ if trace_locating then
+ logs.report("fileio","! appending '%s' to 'package.path'",path)
+ end
+ return path
+end
+
+function package.append_libpath(...)
+ table.insert(libpaths,thepath(...))
+end
+
+function package.prepend_libpath(...)
+ table.insert(libpaths,1,thepath(...))
+end
+
+-- beware, we need to return a loadfile result !
package.loaders[2] = function(name) -- was [#package.loaders+1]
---~ package.loaders[#package.loaders+1] = function(name) -- was
+ if trace_locating then -- mode detail
+ logs.report("fileio","! locating '%s'",name)
+ end
for i=1,#libformats do
local format = libformats[i]
local resolved = resolvers.find_file(name,format) or ""
+ if trace_locating then -- mode detail
+ logs.report("fileio","! checking for '%s' using 'libformat path': '%s'",name,format)
+ end
if resolved ~= "" then
if trace_locating then
logs.report("fileio","! lib '%s' located via environment: '%s'",name,resolved)
end
- return function() return dofile(resolved) end
+ return loadfile(resolved)
end
end
- local simple = file.removesuffix(name)
+ local simple = gsub(name,"%.lua$","")
+ local simple = gsub(simple,"%.","/")
for i=1,#libpaths do -- package.path, might become option
- local resolved = gsub(libpaths[i],"?",simple)
+ local libpath = libpaths[i]
+ local resolved = gsub(libpath,"?",simple)
+ if trace_locating then -- more detail
+ logs.report("fileio","! checking for '%s' on 'package.path': '%s'",simple,libpath)
+ end
if resolvers.isreadable.file(resolved) then
if trace_locating then
logs.report("fileio","! lib '%s' located via 'package.path': '%s'",name,resolved)
end
- return function() return dofile(resolved) end
+ return loadfile(resolved)
+ end
+ end
+ local libname = file.addsuffix(simple,os.libsuffix)
+ for i=1,#clibformats do
+ -- better have a dedicated loop
+ local format = clibformats[i]
+ local paths = resolvers.expanded_path_list_from_var(format)
+ for p=1,#paths do
+ local path = paths[p]
+ local resolved = file.join(path,libname)
+ if trace_locating then -- mode detail
+ logs.report("fileio","! checking for '%s' using 'clibformat path': '%s'",libname,path)
+ end
+ if resolvers.isreadable.file(resolved) then
+ if trace_locating then
+ logs.report("fileio","! lib '%s' located via 'clibformat': '%s'",libname,resolved)
+ end
+ return package.loadlib(resolved,name)
+ end
+ end
+ end
+ for i=1,#clibpaths do -- package.path, might become option
+ local libpath = clibpaths[i]
+ local resolved = gsub(libpath,"?",simple)
+ if trace_locating then -- more detail
+ logs.report("fileio","! checking for '%s' on 'package.cpath': '%s'",simple,libpath)
+ end
+ if resolvers.isreadable.file(resolved) then
+ if trace_locating then
+ logs.report("fileio","! lib '%s' located via 'package.cpath': '%s'",name,resolved)
+ end
+ return package.loadlib(resolved,name)
end
end
-- just in case the distribution is messed up
+ if trace_loading then -- more detail
+ logs.report("fileio","! checking for '%s' using 'luatexlibs': '%s'",name)
+ end
local resolved = resolvers.find_file(file.basename(name),'luatexlibs') or ""
if resolved ~= "" then
if trace_locating then
logs.report("fileio","! lib '%s' located by basename via environment: '%s'",name,resolved)
end
- return function() return dofile(resolved) end
+ return loadfile(resolved)
end
if trace_locating then
logs.report("fileio",'? unable to locate lib: %s',name)
end
- return "unable to locate " .. name
+-- return "unable to locate " .. name
end
resolvers.loadlualib = require