Lua Rocks 配置

lua-users home
wiki

这是一个 LuaRocks 配置示例,用于从单个 LuaRocks 安装中为多个 Lua 安装提供服务,每个安装都有自己的 rocks。

假设 /usr/local/bin/luarocks 是 luarocks-2.0.12 或更高版本,并且 /usr/local/opt/lua/bin/lua 是 Lua 5.1.x,创建一个默认的 /usr/local/share/luarocks/config-5.1.lua(这些是 Mountain Lion 上使用 Homebrew 的默认包目录,但我也有类似的东西在 Ubuntu 持续集成服务器上工作 - 毫无疑问,在 Windows 上可以使用 BAT 文件做类似的事情)

rocks_trees = { "/usr/local/lib/luarocks/5.1" }
variables = {
   LUA = "/usr/local/opt/lua/bin/lua5.1",
   LUA_BINDIR = "/usr/local/opt/lua/bin",
   LUA_INCDIR = "/usr/local/opt/lua/include",
   LUA_LIBDIR = "/usr/local/opt/lua/lib",
}

然后在 /usr/local/bin/luarocks5.1 创建一个包装脚本

#!/bin/sh

PATH=/usr/local/opt/lua/bin:/usr/local/opt/luarocks/bin:$PATH
LUAROCKS_CONFIG=/usr/local/share/luarocks/config-5.1.lua
export LUAROCKS_CONFIG

lua5.1 `which luarocks` ${1+"$@"}
exit $?

类似地,您需要在 /usr/local/bin/lua5.1 添加另一个包装器来设置路径以查找正确的 rocks

#!/bin/sh

: ${LUA_PATH=";"}
: ${LUA_CPATH=";"}

PATH=/usr/local/opt/lua/bin:/usr/local/opt/luarocks/bin:$PATH
LUAROCKS_CONFIG=/usr/local/share/luarocks/config-5.1.lua
export LUAROCKS_CONFIG

# Set search paths to user environment settings, followed by system path, and finally rocks_trees.
save_LUA_PATH=$LUA_PATH
save_LUA_CPATH=$LUA_PATH
eval `luarocks path`
LUA_PATH="$save_LUA_PATH;$LUA_PATH"
LUA_CPATH="$save_LUA_CPATH;$LUA_CPATH"

exec lua5.1 ${1+"$@"}

在将 Lua 5.2.x 安装到 /usr/local/opt/lua52/ 之后(同样,这是 Mountain Lion 上 homebrew 的默认设置,尽管 brew lua52 中的一些路径与 brew lua 冲突,因此您必须手动进行链接),您将需要一个新的 /usr/local/share/luarocks/config-5.2.lua

rocks_trees = { "/usr/local/lib/luarocks/5.2" }
variables = {
   LUA = "/usr/local/opt/lua52/bin/lua",
   LUA_BINDIR = "/usr/local/opt/lua52/bin",
   LUA_INCDIR = "/usr/local/opt/lua52/include",
   LUA_LIBDIR = "/usr/local/opt/lua52/lib",
}

以及一个包装脚本,位于 /usr/local/bin/luarocks5.2

#!/bin/sh

PATH=/usr/local/opt/lua52/bin:/usr/local/opt/luarocks/bin:$PATH
LUAROCKS_CONFIG=/usr/local/share/luarocks/config-5.2.lua
export LUAROCKS_CONFIG

exec lua5.2 `which luarocks` ${1+"$@"}

以及另一个位于 /usr/local/bin/lua5.2

#!/bin/sh

: ${LUA_PATH=";"}
: ${LUA_CPATH=";"}

PATH=/usr/local/opt/lua52/bin:/usr/local/opt/luarocks/bin:$PATH
LUAROCKS_CONFIG=/usr/local/share/luarocks/config-5.2.lua
export LUAROCKS_CONFIG

# Set search paths to user environment settings, followed by system path, and finally rocks_trees.
save_LUA_PATH=$LUA_PATH
save_LUA_CPATH=$LUA_PATH
eval `luarocks path`
LUA_PATH="$save_LUA_PATH;$LUA_PATH"
LUA_CPATH="$save_LUA_CPATH;$LUA_CPATH"

exec lua5.2 ${1+"$@"}

LuaRocks 2.0.12 也适用于 luajit-2.0,因此我使用 /usr/local/share/luarocks/config-luajit.lua 和一对包装器 /usr/local/bin/luarocks-luajit/usr/local/bin/luajit 创建了第三个配置。适应不同的操作系统(例如 Ubuntu,它将软件包安装到 /usr/ 树中)只是调整脚本的 PATH 和脚本本身的问题。为了确保万无一失,我还为我首选的默认解释器创建了软链接

$ ln -s lua5.2 /usr/local/bin/lua
$ ln -s luarocks5.2 /usr/local/bin/luarocks

此时,您可以通过选择使用 luarocks5.1luarocks-luajit 等,将软件包安装到相应的 LuaRocks 树中,以便与关联的 Lua 解释器自动发现。


最近更改 · 偏好设置
编辑 · 历史记录
最后编辑于 2013 年 6 月 28 日上午 9:50 GMT (差异)