如何使用 Luarocks 为 Lua5.2 和 5.1 安装库? [英] How do install libraries for both Lua5.2 and 5.1 using Luarocks?

查看:66
本文介绍了如何使用 Luarocks 为 Lua5.2 和 5.1 安装库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个小型 Lua 项目并使用 Luarocks 安装我的第 3 方依赖项.我机器上的默认 Lua 版本是 5.2,到目前为止一切正常.

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.

然而,今天我偶然发现了一个让我感到困惑的问题.我想在 Lua 5.1 和 Luajit 上运行我的程序,看看它是否也适用于这些版本,但我很难让 Luarocks 下载相应版本的依赖项.作为最后的 hack,我试图告诉 Lua5.1 使用 Luarocks 安装的 5.2 库(通过将 LUA_PATH 环境变量设置为与 LUA_PATH_5_2 相同的值)但不幸的是,这还不够:我的项目依赖 LuaFileSystem,一个基于 C 的模块,所以我需要为 5.1 和 5.2 安装单独的版本.

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.

我需要做什么才能安装 5.1 和 5.2 版本的依赖项?我需要向luarocks install 命令传递一些参数吗?我需要在我的机器上安装多个 Luarocks 实例吗?让我感到困惑的一件事是 .luarocks 文件夹内的东西被归类在 5.2 子文件夹(~/.luarocks/share/lua/5.2/)下,这表明可能有一种方法可以将东西安装在同级5.1文件夹中,但同时只有一个bin文件夹,说明luarocks一次只能处理一个版本的Lua...

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...

推荐答案

根据您对 ~/.luarocks/share/lua/5.2/ 的引用,您似乎正在运行 Unix 系统(Linux 或 Mac).您可以为 Lua 5.1 和 Lua 5.2 安装两次最新版本的 LuaRocks,如下所示:

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

然后是 5.2:

./configure --lua-version=5.2 --versioned-rocks-dir
make build
sudo make install

这将为您提供 /usr/local/bin/luarocks-5.1/usr/local/bin/luarocks-5.2.如果您在/usr/local/中安装了 Lua 5.1 和 5.2,并且它们中的每一个都将使用自己的 ~/.luarocks/lib/luarocks/rocks-5.x/ 条目作为用户树(和 /usr/local/lib/luarocks/rocks-5.x 用于系统树),并将模块安装到 /usr/share/lua/5.x/的正确位置~/.luarocks/share/lua/5.x/(对于 lib 也是如此).

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.

这篇关于如何使用 Luarocks 为 Lua5.2 和 5.1 安装库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆