首选的配置Lua加载路径的方法

我从Centos 7包存档和他们的网站安装了Lua 5.1.4和Luarocks 2.2.2。我尝试通过 luarocks install luacurl 安装 luacurl,它将文件分为 /usr/local/lib/lua/5.1/usr/local/lib/luarocks/rocks/usr/local/share/lua/5.1。我无法弄清楚我应该添加到我的Lua包路径中以及您应该如何配置它。

> lua -e 'print(package.path)'

./?.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;/usr/lib64/lua/5.1/?.lua;/usr/lib64/lua/5.1/?/init.lua

但是当我尝试 require("luacurl") 时,我收到以下错误消息

stdin:1: module 'luacurl' not found:
    no field package.preload['luacurl']
    no file './luacurl.lua'
    no file '/usr/share/lua/5.1/luacurl.lua'
    no file '/usr/share/lua/5.1/luacurl/init.lua'
    no file '/usr/lib64/lua/5.1/luacurl.lua'
    no file '/usr/lib64/lua/5.1/luacurl/init.lua'
    no file './luacurl.so'
    no file '/usr/lib64/lua/5.1/luacurl.so'
    no file '/usr/lib64/lua/5.1/loadall.so'

是否有一个关于Lua包遵循的标准的好参考资料?尝试要求我的 luacurl.so 文件实际存在的位置的绝对路径似乎不起作用。

module '/usr/local/lib/lua/5.1/luacurl.so' not found:
    no field package.preload['/usr/local/lib/lua/5.1/luacurl.so']
    no file './/usr/local/lib/lua/5/1/luacurl/so.lua'
    no file '/usr/share/lua/5.1//usr/local/lib/lua/5/1/luacurl/so.lua'
    no file '/usr/share/lua/5.1//usr/local/lib/lua/5/1/luacurl/so/init.lua'
    no file '/usr/lib64/lua/5.1//usr/local/lib/lua/5/1/luacurl/so.lua'
    no file '/usr/lib64/lua/5.1//usr/local/lib/lua/5/1/luacurl/so/init.lua'
    no file './/usr/local/lib/lua/5/1/luacurl/so.so'
    no file '/usr/lib64/lua/5.1//usr/local/lib/lua/5/1/luacurl/so.so'
    no file '/usr/lib64/lua/5.1/loadall.so'
    no file './/usr/local/lib/lua/5.so'
    no file '/usr/lib64/lua/5.1//usr/local/lib/lua/5.so'
    no file '/usr/lib64/lua/5.1/loadall.so'

完全有可能 require 不是在这里使用正确的函数。

点赞
用户5622901
用户5622901

Lua 有两种类型的 require 路径:package.path 用于纯 Lua 库(.lua),而 package.cpath 用于编译后的库(.so)。

如果你知道 luacurl.so 的位置($ whereis luacurl.so),那么你可以像这样修改 cpath:

package.cpath = package.cpath .. ";/usr/local/lib/lua/5.1/?.so"

或者 luacurl.so 的放置位置。只需要阅读文档了解格式(; 为分隔符,? 为你在 require 参数中传递的内容,_ 转换为 /)。

2015-12-03 23:12:48
用户11226352
用户11226352

Luarocks 默认安装在路径中。在引用任何 luarocks 之前,请执行:

require 'luarocks.loader'

这将修改“require”以便在 luarocks 安装它们的位置中查找和找到 luarocks。

如果 Lua 代码应在不同的系统上运行,在某些系统上使用 luarocks,在其他系统上安装了默认搜索路径中的库,则可能需要执行:

pcall( require, 'luarocks.loader' )

这将允许在未安装 luarocks 的情况下,“require”默默失败,并继续使用“require”的默认搜索路径。

2019-10-09 09:04:34