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

问题描述

我正在编写一个小的Lua项目,并使用Luarocks来安装我的第三方依赖项.我机器上的默认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下载相应版本的依赖项.作为最后的手段,我试图告诉Lua5.1使用Luarocks安装的5.2库(通过将LUA_PATH环境变量设置为与LUA_PATH_5_2相同的值),但是不幸的是,这还不够:我的项目取决于在基于C的模块LuaFileSystem上,因此我需要为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安装库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 09:08