Search code examples
linuxwindowslualuarocks

LUAROCKS on windows installs rocks oddly


On Linux, luarocks installs rocks to

/usr/local/lib/luarocks/rock

and puts a corresponding lua file into

/usr/local/share/lua/5.3

On Windows(LUA 5.1), the rocks are in:

C:\Program Files (x86)\LuaRocks\systree\lib\luarocks

and the lua files are in:

C:\Program Files (x86)\LuaRocks\systree\share\lua\5.1

but lua cannot find them on the windows install.

I must have a PATH problem

This is some of my 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

I am trying ZeroBraneStudio as the IDE and my system prefs specify this path

path.lua = 'C:\Program Files (x86)\Lua\5.1'

I ran

luarocks install inspect

and that generated the necessary files. Then I wrote this simple test code:

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

and got this error

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

I get the same error when I execute the same simple app directly in the console.(That tells me that PATH variable for lua is working)

What am I missing?


Solution

  • Judging from the error message you quoted the require "inspect" worked just fine, but the module didn't set a global variable inspect. For some time now it has been policy to not set globals from within modules, but instead return something (usually the module table) from the module code, which in turn gets passed down via require. So probably something like

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

    or

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

    should work.