summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkiv/l-package.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/l-package.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/mkiv/l-package.lua71
1 files changed, 52 insertions, 19 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/l-package.lua b/Master/texmf-dist/tex/context/base/mkiv/l-package.lua
index 0dd71e5eca8..ef37aebe74e 100644
--- a/Master/texmf-dist/tex/context/base/mkiv/l-package.lua
+++ b/Master/texmf-dist/tex/context/base/mkiv/l-package.lua
@@ -16,7 +16,7 @@ if not modules then modules = { } end modules ['l-package'] = {
-- -- local mylib = require("libtest")
-- -- local mysql = require("luasql.mysql")
-local type = type
+local type, unpack = type, unpack
local gsub, format, find = string.gsub, string.format, string.find
local insert, remove = table.insert, table.remove
@@ -54,7 +54,7 @@ local function lualibfile(name)
return lpegmatch(pattern,name) or name
end
-local offset = luarocks and 1 or 0 -- todo: also check other extras
+local offset = luarocks and 1 or 0 -- todo: also check other extras ... we'll drop this luarocks anyway
local helpers = package.helpers or {
cleanpath = cleanpath,
@@ -70,6 +70,7 @@ local helpers = package.helpers or {
methods = {
},
sequence = {
+ "reset loaded",
"already loaded",
"preload table",
"qualified path", -- beware, lua itself doesn't handle qualified paths (prepends ./)
@@ -91,6 +92,7 @@ local builtin = helpers.builtin
local extraluapaths = { }
local extralibpaths = { }
+local checkedfiles = { }
local luapaths = nil -- delayed
local libpaths = nil -- delayed
local oldluapath = nil
@@ -245,10 +247,17 @@ local function loadedaslib(resolved,rawname) -- todo: strip all before first -
-- so, we can do a require("foo/bar") and initialize bar
-- local base = gsub(file.basename(rawname),"%.","_")
local init = "luaopen_" .. gsub(base,"%.","_")
+ local data = { resolved, init, "" }
+ checkedfiles[#checkedfiles+1] = data
if helpers.trace then
helpers.report("calling loadlib with '%s' with init '%s'",resolved,init)
end
- return package.loadlib(resolved,init)
+ local a, b, c = package.loadlib(resolved,init)
+ if not a and type(b) == "string" then
+-- data[3] = gsub(b or "unknown error","[\n\r]","")
+ data[3] = string.fullstrip(b or "unknown error")
+ end
+ return a, b, c -- c can be 'init'
end
helpers.loadedaslib = loadedaslib
@@ -295,12 +304,21 @@ end
helpers.loadedbyname = loadedbyname
+methods["reset loaded"] = function(name)
+ checkedfiles = { }
+ return false
+end
+
+
methods["already loaded"] = function(name)
return package.loaded[name]
end
methods["preload table"] = function(name)
- return builtin["preload table"](name)
+ local f = builtin["preload table"]
+ if f then
+ return f(name)
+ end
end
methods["qualified path"]=function(name)
@@ -316,22 +334,34 @@ methods["lib extra list"] = function(name)
end
methods["path specification"] = function(name)
- getluapaths() -- triggers list building and tracing
- return builtin["path specification"](name)
+ local f = builtin["path specification"]
+ if f then
+ getluapaths() -- triggers list building and tracing
+ return f(name)
+ end
end
methods["cpath specification"] = function(name)
- getlibpaths() -- triggers list building and tracing
- return builtin["cpath specification"](name)
+ local f = builtin["cpath specification"]
+ if f then
+ getlibpaths() -- triggers list building and tracing
+ return f(name)
+ end
end
methods["all in one fallback"] = function(name)
- return builtin["all in one fallback"](name)
+ local f = builtin["all in one fallback"]
+ if f then
+ return f(name)
+ end
end
methods["not loaded"] = function(name)
if helpers.trace then
helpers.report("unable to locate '%s'",name or "?")
+ for i=1,#checkedfiles do
+ helpers.report("checked file '%s', initializer '%s', message '%s'",unpack(checkedfiles[i]))
+ end
end
return nil
end
@@ -346,19 +376,22 @@ function helpers.loaded(name)
level = level + 1
for i=1,#sequence do
local method = sequence[i]
- if helpers.trace then
- helpers.report("%s, level '%s', method '%s', name '%s'","locating",level,method,name)
- end
- local result, rest = methods[method](name)
- if type(result) == "function" then
+ local lookup = method and methods[method]
+ if type(lookup) == "function" then
if helpers.trace then
- helpers.report("%s, level '%s', method '%s', name '%s'","found",level,method,name)
+ helpers.report("%s, level '%s', method '%s', name '%s'","locating",level,method,name)
end
- if helpers.traceused then
- used[#used+1] = { level = level, name = name }
+ local result, rest = lookup(name)
+ if type(result) == "function" then
+ if helpers.trace then
+ helpers.report("%s, level '%s', method '%s', name '%s'","found",level,method,name)
+ end
+ if helpers.traceused then
+ used[#used+1] = { level = level, name = name }
+ end
+ level = level - 1
+ return result, rest
end
- level = level - 1
- return result, rest
end
end
-- safeguard, we never come here