Module installed by Luarocks not found
Asked Answered
V

2

13

I am working on Debian Stable Linux. I installed luafilesystem module by command:

luarocks --local install luafilesystem

However, it is not found when any of following is used in lua source files:

require ("lfs")
require ("luafilesystem")

(Although these files run properly when ran from within ZeroBraneStudio IDE).

From a suggestion on the web, I ran following command also:

luarocks --local install luarocks

But it does not help. I checked with luarocks-admin command, which showed:

CONFIGURATION
    Lua version: 5.1
    Configuration files:
        System: /etc/luarocks/config.lua (ok)
        User  : /home/abcd/.luarocks/config-5.1.lua (not found)

    Rocks trees in use: 
        /home/abcd/.luarocks
        /usr/local

Currently, I only have these 2 modules installed:

$ luarocks list

Installed rocks:
----------------

luafilesystem
   1.7.0-2 (installed) - /home/abcd/.luarocks/lib/luarocks/rocks

luarocks
   2.4.3-1 (installed) - /home/abcd/.luarocks/lib/luarocks/rocks

Should I copy /etc/luarocks/config.lua to /home/abcd/.luarocks for this? Thanks for your help.

Vat answered 29/10, 2017 at 19:14 Comment(2)
Do you require "luarocks.loader" first?Grenville
I installed modules using sudo luarocks install luafilesystem (without --local option) and it works. So luarocks.loader is needed for locally installed modules?Vat
H
11

The LUA_PATH and LUA_CPATH environment variables control the paths searched by lua when looking for packages. These are probably not set correctly. Include the paths used by luarocks in these variables by running

eval "$(luarocks path)"

and you should be all set.

Hardener answered 30/10, 2017 at 8:34 Comment(0)
P
3

Eval works fine when executing the code from the terminal, but it doesn't work when executing it using the vscode debugger.

To get around this problem, I did the following.

local LUA_PATH = 'my LUA_PATH from "$ luarocks path"'
local LUA_CPATH = 'my LUA_CPATH from "$ luarocks path"'

package.path = package.path .. ';' .. LUA_PATH
package.cpath = package.cpath .. ';' .. LUA_CPATH

With this change, I can run the code using the debugger.

Pure answered 29/10, 2023 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.