我的lua require语句无法搜索到正确的路径。如何修改安装或我的环境以使 Lua require 语句起作用?

问题描述 投票:0回答:1

在 MAC 操作系统索诺玛 14.2.1 下

luaclient.lua 脚本第 2 行是:

local socket = require('socket')

当脚本运行时,它会产生:

lua: luaclient.lua:2: module 'socket' not found:
    no field package.preload['socket']
    no file '/usr/local/share/lua/5.4/socket.lua'
    no file '/usr/local/share/lua/5.4/socket/init.lua'
    no file '/usr/local/lib/lua/5.4/socket.lua'
    no file '/usr/local/lib/lua/5.4/socket/init.lua'
    no file './socket.lua'
    no file './socket/init.lua'
    no file '/usr/local/lib/lua/5.4/socket.so'
    no file '/usr/local/lib/lua/5.4/loadall.so'
    no file './socket.so'
stack traceback:
    [C]: in function 'require'
    luaclient.lua:2: in main chunk
    [C]: in ?

插座安装在这里:

/Users/user_name/.luarocks/share/lua/5.4

Lua 解释器说:

Lua 5.4.7 版权所有 (C) 1994-2024 Lua.org,PUC-Rio

print(package.path) 

/usr/local/share/lua/5.4/?.lua;/usr/local/share/lua/5.4/?/init.lua;/usr/local/lib/lua/5.4/?.lua;/usr/local/lib/lua/5.4/?/init.lua;./?.lua;./?/init.lua

尝试:

set LUA_PATH '/Users/perryhorwich/.luarocks/share/lua/5.4/?.lua'

...在 shell 中,给出相同的错误,就好像 LUA_PATH 对“socket”的查找没有影响

我错过了什么?

macos installation lua
1个回答
0
投票

将其添加到我的代码中:

package.cpath ="/Users/user_name/.luarocks/lib/lua/5.4/?.so;" .. package.cpath
package.path = "/Users/user_name/.luarocks/share/lua/5.4/?.lua;" .. package.path

...有效。

© www.soinside.com 2019 - 2024. All rights reserved.