[luatex] [EXT] Re: Accessing external Lua libraries

Michal Vlasák lahcim8 at gmail.com
Thu Mar 25 11:51:26 CET 2021


On Wed Mar 24, 2021 at 11:22 PM CET, Andreas Matthias wrote:
> On Wed, Mar 24, 2021 at 10:50 PM Philip Taylor <P.Taylor at rhul.ac.uk>
> wrote:
> >
> > Andreas Matthias wrote:
> >
> > Setting LUAINPUTS and CLUAINPUTS in texmf.cnf is not enough
> > to load _all_ kind of modules/libraries. It suffice[s] to
> > load files like 'foobar.lua' or 'foobar.so'. But to load files
> > like 'foobar/init.lua' one needs luapackageloader.
> >
> > For the benefit of those (such as myself) who are less familiar with Lua conventions than yourself, Andreas, could you explain which of the two possible criteria is the crucial one ?  Is it (a) that the file lives in a sub-directory such as "foobar", or (b) that the file is called "init.lua" and not (e.g.,) "foobar.lua" ?  Or I suppose (c), both of the preceding.
>
> I think both are common. At least both are mentioned in
>
> Programming in Lua (3. edition)
> §15.4 Submodules and Packages
>
> I don't know why kpathsea doesn't handle both. Hmm... maybe:
> This section didn't exist in the first edition of the book. Don't
> know about the second. Maybe the adjustments for lua in kpathsea
> date back earlier?
>
> Andreas

Well, at least as I understand it, kpathsea is designed to search for
files with more or less unique file names, while Lua path search is
based on "path patterns".

After kpathsea is ordered to find a file (e.g. "foobar" of type "lua")
and it sees that it doesn't have a suffix it tries all the suffixes it
knows. These are defined in tex-file.c:

#define LUA_SUFFIXES \
  ".lua", ".luatex", ".luc", ".luctex", ".texlua", ".texluc", ".tlu"

After adding equivalent of Lua's "?/init.lua" (which across platforms is
probably a suffix of 'DIR_SEP_STRING "init.lua"') Lua like path
searching for modules seems to work even in kpathsea. However surely
there are assumptions in the code that suffix does not contain directory
separtors and this will break in non simplistic cases. (Like in database
lookups). Maybe this can be fixed.

But I don't think it's worth to make these changes:

1) Both CTAN and TeX Live strongly prefer unique file names and I don't
think they would like many "init.lua" files.

2) Lua path searching for files outside of TEXMF trees can be achieved
using luapackageloader or custom path searcher.

Michal



More information about the luatex mailing list.