[luatex] Accessing external Lua libraries
lahcim8 at gmail.com
Wed Mar 24 21:17:28 CET 2021
On Wed Mar 24, 2021 at 5:58 PM CET, Faheem Mitha wrote:
> On Wed, 24 Mar 2021, Faheem Mitha wrote:
> > I'm not completely sure I understand what your issue is, but you might find
> > https://ctan.org/pkg/luapackageloader of interest if you aren't familiar with
> > it already. The strategy it uses is described somewhere in the LuaTeX manual
> > I think, though right now I can't remember exactly where.
> I forgot to say that I use
> in my Lua files for use with LuaTeX, in conjunction with
> and it seems to work. Though I can't remember whether I specifically
> needed to load an init.lua.
> Hope this helps.
> Regards, Faheem Mitha
Andreas, what Faheem suggests should work for you: use luapackage and
set package.path/packge.cpath to what you want. You should see section
6.3 "Modules" of https://www.lua.org/manual/5.3/manual.html and also the
source code of luapackageloader (luapackageloader.lua) to understand how
this works. Also you may have to disable some security precautions
(--shell-escape and no --safer).
Something like this should hopefully work for your setup:
local luarocks_path = kpse.expand_path("~/.luarocks/share/lua/5.3")
local luarocks_cpath = kpse.expand_path("~/.luarocks/lib/lua/5.3")
package.path = package.path .. string.format(";%s/?.lua;%s/?/init.lua", luarocks_path, luarocks_path)
package.cpath = package.cpath .. string.format(";%s/?.so;%s/?/init.so", luarocks_cpath, luarocks_cpath)
module = require("module")
Note that this appends to existing paths as you saw them earlier and
expects the ~/.luarocks directories to exist.
More information about the luatex