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.lua29
1 files changed, 23 insertions, 6 deletions
diff --git a/tex/context/base/data-lua.lua b/tex/context/base/data-lua.lua
index fde79d464..7e3d92585 100644
--- a/tex/context/base/data-lua.lua
+++ b/tex/context/base/data-lua.lua
@@ -14,7 +14,7 @@ local gsub = string.gsub
local concat = table.concat
local addsuffix = file.addsuffix
-local P, Cs, lpegmatch = lpeg.P, lpeg.Cs, lpeg.match
+local P, S, Cs, lpegmatch = lpeg.P, lpeg.S, lpeg.Cs, lpeg.match
local libsuffixes = { 'tex', 'lua' }
local clibsuffixes = { 'lib' }
@@ -77,17 +77,17 @@ local function loadedbyformat(name,rawname,suffixes,islib)
local trace = helpers.trace
local report = helpers.report
if trace then
- report("! locating %a as %a using formats %a",rawname,name,suffixes)
+ 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 for %a using format %a",name,format)
+ report("checking %a using format %a",name,format)
end
if resolved ~= "" then
if trace then
- report("! lib %a located on %a",name,resolved)
+ report("lib %a located on %a",name,resolved)
end
if islib then
return true, loadedaslib(resolved,rawname)
@@ -102,8 +102,25 @@ 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"))
+-- print(lualibfile("crap//foo.bar"))
+-- print(lualibfile("crap/../foo.bar"))
+-- print(lualibfile("crap/.././foo.bar"))
+
+-- alternatively we could split in path and base and temporary set the libpath to path
+
function helpers.loaded(name)
- local thename = gsub(name,"%.","/")
+ local thename = lualibfile(name)
local luaname = addsuffix(thename,"lua")
local libname = addsuffix(thename,os.libsuffix)
local libpaths = getlibpaths()
@@ -135,7 +152,7 @@ function helpers.loaded(name)
return notloaded(name)
end
-package.searchers[3] = nil -- get rid of the built in one
+-- package.searchers[3] = nil -- get rid of the built in one (done in l-lua)
-- package.extraclibpath(environment.ownpath)