summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/data-lua.lua
blob: 86231b3a3a90970848725a6ea09f35926f3a2a26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
if not modules then modules = { } end modules ['data-lua'] = {
    version   = 1.001,
    comment   = "companion to luat-lib.tex",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

-- some loading stuff ... we might move this one to slot 1 depending
-- on the developments (the loaders must not trigger kpse); we could
-- of course use a more extensive lib path spec

local trace_locating = false  trackers.register("resolvers.locating", function(v) trace_locating = v end)

local gsub = string.gsub

local libformats = { 'luatexlibs', 'tex', 'texmfscripts', 'othertextfiles' }
local libpaths   = file.split_path(package.path)

package.loaders[#package.loaders+1] = function(name)
    for i=1,#libformats do
        local format = libformats[i]
        local resolved = resolvers.find_file(name,format) or ""
        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
        end
    end
    local simple = file.removesuffix(name)
    for i=1,#libpaths do
        local resolved = gsub(libpaths[i],"?",simple)
        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
        end
    end
    -- just in case the distribution is messed up
    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
    end
    if trace_locating then
        logs.report("fileio",'? unable to locate lib: %s',name)
    end
    return "unable to locate " .. name
end

resolvers.loadlualib = require