How do install libraries for both Lua5.2 and 5.1 using Luarocks?

主宰稳场 提交于 2019-12-03 06:19:57

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.

As suggested by moteus, I decided to install a second version of Luarocks for Lua 5.1. But he is using Windows and I am using Linux so here is what I did:

  • Download the source for the latest version of Luarocks on the Luarocks website

  • From the source directory, run the ./configure script:

    /configure --prefix="${HOME}/.luarocks51" --lua-suffix=5.1

    The prefix setting tells Luarocks to put its stuff on the .luarocks51 folder, next to the existing .luarocks folder from my 5.2 install of Luarocks. The lua-suffix parameter tells Luarocks to use Lua 5.1 instead of the default lua version in my machine (5.2). This depends on me having named the interpreter for Lua 5.1 as lua5.1 (Debian installed mine on /usr/bin/lua5.1). Finally, Luarocks managed to automatically detect where the 5.1 headers and libraries are installed (/usr/include/lua5.1/) but if it didn't I guess I could have specified that with the --with-lua-include and --with-lua-lib parameters.

  • Compile Luarocks with make

  • Install it with make isntall (no need for Sudo since I'm installing it in a local directory).

  • Configure my 5.1 environment to use the libraries downloaded by Luarocks. I added the following to my .bashrc:

    export PATH=$PATH:~/.luarocks/bin:~/.luarocks51/bin
    export LUA_CPATH=";;${HOME}/.luarocks51/lib/lua/5.1/?.so"
    export LUA_PATH=";;${HOME}/.luarocks51/share/lua/5.1/?.lua;${HOME}/.luarocks51/share/lua/5.1/?/init.lua"
    
    export LUA_CPATH_5_2=";;${HOME}/.luarocks/lib/lua/5.2/?.so"
    export LUA_PATH_5_2=";;${HOME}/.luarocks/share/lua/5.2/?.lua;${HOME}/.luarocks/share/lua/5.2/?/init.lua"
    

    The 5.1 configuration also works for Luajit.

  • The executable for the 5.1 version of luarocks is named luarocks-5.1:

    luarocks-5.1 install lfs
    

This is how i do this. https://gist.github.com/moteus/6823437 My English is not very good. But i think it may be useful.

I had this very same problem. and wanted something more automatic that I would reuse.

I am very much used to Ruby RVM. And so I wanted to get inspired by it. I just make 3 quick bash functions to cover my needs. Feel free to use them, but they are only tested on ArchLinux

https://github.com/mathieujobin/lua_version_manager

Using homebrew, you can do:

brew install lua51  # Lua 5.1
brew install lua    # Lua latest

Luarocks comes with Lua, so you can do:

# Install Lua 5.1 version of any package
luarocks-5.1 install moonscript

# Install Lua latest version of any package
luarocks install moonscript

You have to mention both lua version and lua dir in the latest versions:

luarocks --lua-dir=$(brew --prefix)/opt/lua@5.1 --lua-version=5.1 install lua-cassandra
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!