Hello,
in the TeX world scripts are usually installed below TDS:scripts.
Lua does know a module system.
Example: There is a package "foobar" with module "foobar.hello".
Lua then searches in some standard places for
foobar/hello.lua
However LuaTeX neglects the texmf trees. Thus "package.loaders"
could be extended by a kpse loader, e.g.:
function kpse.module_loader(module)
local file
if string.find(module, ".", 1, true) then
-- What to do?
-- the following is just an unreliable emergency workaround:
module = string.gsub(module, "^.*\%.", "")
file = kpse.find_file(module .. ".lua", "texmfscripts")
else
file = kpse.find_file(module .. ".lua", "texmfscripts")
end
if file then
local loader, error = loadfile(file)
if loader then
return loader
end
return "\n\t KPSE loading error:\n" .. error
end
return "\n\t KPSE search failed"
end
table.insert(package.loaders, kpse.module_loader)
However, the problem are modules with dots.
I haven't find a solution using kpse functions.
kpsewhich --format=texmfscripts foobar/hello.lua
doesn't find the file.
Perhaps a search path could be hacked by using the output of
kpsewhich --show-path=texmfscripts
and appending the module directories to each path component.
But:
* LuaTeX's kpse library doesn't have a "show_path" function.
* os.execute is not available in safer mode.
* Last but not least, a kpse function is missing for
searching along the modified path specification.
* Portability among different operating systems.
(directory specificator, ..., LUA_DIRSEP isn't available, ...)
Ideas?
Something like "foobar_hello.lua" isn't the best solution:
* Redundancy in the full name:
TDS:scripts/foobar/foobar_hello.lua
* It doesn't scale well, e.g. it pollutes "package.loaded".
Yours sincerely
Heiko