# Installing Lua Modules for use in LuaLaTeX

I've done all of the searching that I can, and I think I've read the right answer, but am too dumb to know that I read it.

I can't seem to figure out the magic tricks to get Lua modules, installed by luarocks or by any other means, to show up in LuaLaTeX. So here is a minimal:

%!TEX TS-program = lualatex
\documentclass{article}
\usepackage{luatexbase}
\usepackage{luacode}
\begin{document}

\directlua{package.path = "~/.luarocks/share/lua/5.1/?.lua;~/.luarocks/share/lua/5.1/?/init.lua;" .. package.path }

\directlua{require('pl')}
\directlua{require('htk')}

\directlua{tex.sprint(package.path)}

the standard approximation $\pi = \directlua{tex.sprint(math.pi)}$

\end{document}


In installed htk using luarocks with the command luarocks --local install HTK . The Penlight module was installed the same way, except with penlight. Penlight uses the "pl/submodulename" scheme and htk uses just "htk.lua" in the ~/.luarocks/share/lua/5.1  directory.

The log output is:

./luamoduleload.tex:9: LuaTeX error <\directlua >:1: module 'pl' not found:
stack traceback:
[C]: in function 'require'
<\directlua >:1: in main chunk.
l.9     \directlua{require('pl')}

The lua interpreter ran into a problem, so the
remainder of this lua chunk will be ignored.

stack traceback:
[C]: in function 'require'
<\directlua >:1: in main chunk.
l.10    \directlua{require('htk')}

The lua interpreter ran into a problem, so the
remainder of this lua chunk will be ignored.


Would more of the log file be helpful?

In truth, if i just knew where to instal the lua modules that I want to use, I'd be a happy camper, especially if I don't need to do any magic tricks to get stand-alone lua scripts to work outside of LuaLaTeX.

Please let me know if I can be any clearer or if I'm not reading the right fine manuals. :)

-Andrew

-
Have you tried the CLUAINPUTS path? texmf.cnf says: % Lua needs to look for binary lua libraries distributed with packages. CLUAINPUTS = .;$SELFAUTOLOC/lib/{$progname,$engine,}/lua//. Perhaps you can add the location where luarocks adds libraries to CLUAINPUTS. – Aditya Mar 27 '11 at 20:34 So now that line looks like CLUAINPUTS = .;$SELFAUTOLOC/lib/{$progname,$engine,}/lua//;~/.luarocks/share/lua/5.1// and it appears to have no effect... Cry ;) – Andrew Starks Mar 28 '11 at 4:55
How about adding the .so file in the current directory to see if dynamic loading works at all. – Aditya Mar 28 '11 at 13:12
It does. If I drop the file into the project's directory it seems to work. – Andrew Starks Mar 28 '11 at 13:27
Could you please tell a bit more about this "pl"? What is the exact name (the extension) of the module? Where do you want to store it? A small complete example with a simple \directlua{require('pl')} and the log-file would be useful too. E.g. I can't understand where the reference to oberdiek.luatex.kpse_module_loader comes from. – Ulrike Fischer Mar 28 '11 at 14:34

 \directlua{package.path = "~/.luarocks/share/lua/5.1/?.lua;~/.luarocks/share/lua/5.1/?/init.lua;" .. package.path }

looks suspicious. I think you need to have \noexpands before the tilde characters, otherwise the expansion of the ~ macro ends up as part of package.path.
\directlua{package.path = "\noexpand~/.luarocks/share/lua/5.1/?.lua;\noexpand~/.luarocks/share/lua/5.1/?/init.lua;" .. package.path }