| 1 |
#!/usr/bin/env texlua |
| 2 |
-- Remove relative directories from package path |
| 3 |
package.path = package.path:gsub("%f[^\0;]%.[^;]*", ""):gsub(";+", ";"):gsub("^;", ""):gsub(";$", "") |
| 4 |
package.cpath = package.cpath:gsub("%f[^\0;]%.[^;]*", ""):gsub(";+", ";"):gsub("^;", ""):gsub(";$", "") |
| 5 |
-- Use an invalid directory name in order not to allow kpse to search |
| 6 |
-- in the current directory. |
| 7 |
os.setenv("TEXMFDOTDIR", package.config:find("^\\") and "NUL" or "/dev/null") |
| 8 |
kpse.set_program_name("luatex") |
| 9 |
local zip = require "zip" |
| 10 |
local archive = kpse.find_file("digestif.zip", "texmfscripts") |
| 11 |
or error("Can't find 'digestif.zip' archive") |
| 12 |
local function digestif_searcher(modname) |
| 13 |
local submod = modname:match("^digestif%.(.+)") |
| 14 |
if not submod then return end |
| 15 |
local zipfile = zip.open(archive) |
| 16 |
local luafile = zipfile and zipfile:open(submod .. ".lua") |
| 17 |
if not luafile then |
| 18 |
return "\n\t[digestif] no file '"..submod..".lua' in '"..archive.."'" |
| 19 |
end |
| 20 |
local chunk = luafile:read("*a") |
| 21 |
luafile:close(); zipfile:close() |
| 22 |
return load(chunk, "="..archive.."#"..submod..".lua") |
| 23 |
end |
| 24 |
-- Search inside digestif.zip when requiring digestif.* modules. |
| 25 |
table.insert(package.searchers, 2, digestif_searcher) |
| 26 |
-- Search inside digestif.zip when loading the *.tags data files. |
| 27 |
table.insert(require "digestif.config".data_dirs, archive) |
| 28 |
require "digestif.langserver".main(arg) |