libs-imp-kpse.lmt /size: 1663 b    last modification: 2021-10-28 13:51
1if not modules then modules = { } end modules ['libs-imp-kpse'] = {
2    version   = 1.001,
3    comment   = "companion to luat-imp-kpse.mkxl",
4    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5    copyright = "PRAGMA ADE / ConTeXt Development Team",
6    license   = "see context related readme files"
7}
8
9-- This is an experiment. It might make sense to have this available in case I want
10-- more runners to use LuaMetaTeX in which case (as with mtxrun using LuaTeX) we
11-- need to load kpse.
12
13local libname = "kpse"
14local libfile = (os.platform == "win64" and "kpathsea*w64")
15             or (os.platform == "win32" and "kpathsea*w32")
16             or "libkpathsea"
17local libkpse = resolvers.libraries.validoptional(libname)
18
19if package.loaded[libname] then
20    return package.loaded[libname]
21end
22
23-- This is a variant that loaded directly:
24
25-- kpse = libkpse -- the library will issue warnings anyway
26--
27-- resolvers.libraries.optionalloaded(libname,libfile) -- no need to chedk if true
28
29-- This variant delays loading and has a bit more protection:
30
31local function okay()
32    if libkpse and resolvers.libraries.optionalloaded(libname,libfile) then
33        okay = function() return true end
34    else
35        okay = function() return false end
36    end
37    return okay()
38end
39
40local kpse = { }
41
42for k, v in next, libkpse do
43    kpse[k] = function(...) if okay() then return v(...) end end
44end
45
46-- We properly register the module:
47
48package.loaded[libname] = kpse
49
50optional.loaded.kpse = kpse
51
52-- A simple test:
53
54-- kpse.set_program_name("pdftex")
55-- print("find file:",kpse.find_file("oeps.tex"))
56-- print("find file:",kpse.find_file("context.mkii"))
57
58return kpse
59