LUAROCKS 在 Windows 上安装 rocks 的方式很奇怪。

在 Linux 上,luarocks 安装 rock 到 /usr/local/lib/luarocks/rock,并将相应的 lua 文件放置在 /usr/local/share/lua/5.3

在 Windows(LUA 5.1)上,rock 在以下位置:C:\Program Files (x86)\LuaRocks\systree\lib\luarocks,lua 文件在以下位置:C:\Program Files (x86)\LuaRocks\systree\share\lua\5.1,但 Lua 无法在 Windows 安装中找到它们。

我的 PATH 有问题。

这是我的 PATH 的一部分:Path=C:\Program Files (x86)\Lua\5.1\lua\;C:\Program Files (x86)\LuaRocks\2.2;C:\Program Files (x86)\LuaRocks\2.2\lua\luarocks;C:\Program Files (x86)\LuaRocks\systree\bin;C:\Perl64\site\bin;C:\UnxUpdts;C:\Perl64\bin;C:\Program Files (x86)\Lua\5.1;C:\Program Files (x86)\Lua\5.1\clibs

我正在尝试使用 ZeroBraneStudio 作为 IDE,我的系统首选项指定了此路径:path.lua = 'C:\Program Files (x86)\Lua\5.1'

我运行了 luarocks install inspect,然后编写了此简单的测试代码:

require "inspect"
assert(inspect(1) == "1")
assert(inspect("Hello") == '"Hello"')

但出现了以下错误:

Program starting as '"E:\Anonamouse\ZeroBraneStudio\bin\lua.exe" -e "io.stdout:setvbuf('no')" "E:\Anonamouse\ZeroBraneStudio\myprograms\DemoInspectModule.lua"'.
Program 'lua.exe' started in 'E:\Anonamouse\ZeroBraneStudio\myprograms' (pid: 14776).
E:\Anonamouse\ZeroBraneStudio\bin\lua.exe: ...namouse\ZeroBraneStudio\myprograms\DemoInspectModule.lua:2: attempt to call global 'inspect' (a nil value)
stack traceback:
        ...namouse\ZeroBraneStudio\myprograms\DemoInspectModule.lua:2: in main chunk
        [C]: at 0x00402a57
Program completed in 0.04 seconds (pid: 14776).

在控制台中直接执行相同的简单应用程序时,我会收到相同的错误。(这告诉我 PATH 变量对于 Lua 是有效的。)

我错过了什么?

点赞
用户3677376
用户3677376

从你引用的错误信息来看,require "inspect" 工作得很好,但是该模块没有设置全局变量 inspect。 最近的政策是在模块内部不要设置全局变量,而是从模块代码返回某些东西(通常是模块表),这些东西通过 require 传递下来。 因此,像下面这样的代码应该可以工作:

local inspect = require "inspect"
assert(inspect(1) == "1")
assert(inspect("Hello") == '"Hello"')

local inspect = require "inspect"
assert(inspect.inspect(1) == "1")
assert(inspect.inspect("Hello") == '"Hello"')
2015-03-30 07:58:19