[luatex] Accessing external Lua libraries
Michal Vlasák
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
>
> package.cpath="/usr/local/lib/lua/5.3/?.so;/usr/lib/x86_64-linux-gnu/lua/5.3/?.so;/usr/lib/lua/5.3/?.so;/usr/local/lib/lua/5.3/loadall.so;./?.so"..package.cpath
>
> package.path="/usr/local/share/lua/5.3/?.lua;/usr/local/share/lua/5.3/?/init.lua;/usr/local/lib/lua/5.3/?.lua;/usr/local/lib/lua/5.3/?/init.lua;/usr/share/lua/5.3/?.lua;/usr/share/lua/5.3/?/init.lua;./?.lua"..package.path
>
> in my Lua files for use with LuaTeX, in conjunction with
> luapackageloader,
> 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:
```
\input luapackageloader.sty
\bgroup
\catcode`~=12
\catcode`\%=12
\directlua{
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")
}
\egroup
\bye
```
Note that this appends to existing paths as you saw them earlier and
expects the ~/.luarocks directories to exist.
Michal
More information about the luatex
mailing list.