I am writing a small Lua project and using Luarocks to install my 3rd-party dependencies. The default Lua version on my machine is 5.2 and up to this point everything is working just fine.
However, today I have stumbled across a problem that is confusing me. I want to run my program on Lua 5.1 and Luajit to see if it would also work on those versions but I am having a hard time getting Luarocks to download the appropriate versions of the dependencies. As a last resort hack, I have tried to tell Lua5.1 to use the 5.2 libraries that Luarocks installed (by setting the LUA_PATH
environment variable to the same value as LUA_PATH_5_2
) but unfortunately that is not enough: my project depends on LuaFileSystem, a C-based module, so I'm going to need to have separate versions of it installed for 5.1 and 5.2.
What do I have to do to install both the 5.1 and 5.2 versions of my dependencies? Do I need to pass some parameters to theluarocks install
command? Do I need to have multiple instances of Luarocks installed on my machine? One thing that confuses me is that the inside the .luarocks
folder things are classified under a 5.2 subfolder (~/.luarocks/share/lua/5.2/), suggesting that maybe there could be a way to install things in a sibling 5.1
folder but at the same time there is only one bin
folder, suggesting that luarocks is only able to handle one version of Lua at a time...
Based on your reference to ~/.luarocks/share/lua/5.2/
, you seem to be running a Unix system (Linux or Mac). You can install the latest version of LuaRocks twice, for both Lua 5.1 and Lua 5.2 like this:
./configure --lua-version=5.1 --versioned-rocks-dir
make build
sudo make install
And then again for 5.2:
./configure --lua-version=5.2 --versioned-rocks-dir
make build
sudo make install
This will get you /usr/local/bin/luarocks-5.1
and /usr/local/bin/luarocks-5.2
. If you installed Lua 5.1 and 5.2 in /usr/local/, and each of them will use its own ~/.luarocks/lib/luarocks/rocks-5.x/
entry for the user tree (and /usr/local/lib/luarocks/rocks-5.x
for the system tree), and install modules to the right location at /usr/share/lua/5.x/
and ~/.luarocks/share/lua/5.x/
(and likewise for lib
) appropriately.