本地 luarocks 包安装 (luarepl) 不起作用

local luarocks package install (luarepl) does not work

我是 luarocks 的新手,我刚刚尝试安装 luarepl。 安装显然很顺利:

$ luarocks install luarepl
Installing https://luarocks.org/luarepl-0.8-1.rockspec...
Using https://luarocks.org/luarepl-0.8-1.rockspec... switching to 'build' mode
Updating manifest for /Users/me/.luarocks/lib/luarocks/rocks-5.1
luarepl 0.8-1 is now built and installed in /Users/me/.luarocks (license: MIT/X11)

但如果我尝试启动可执行文件,安装似乎已损坏:

$ ~/.luarocks/bin/rep.lua
/usr/local/bin/lua5.1: ...cks/lib/luarocks/rocks-5.1/luarepl/0.8-1/bin/rep.lua:23: module 'repl.console' not found:
    no field package.preload['repl.console']
    no file './repl/console.lua'
    no file '/usr/local/share/lua/5.1/repl/console.lua'
    no file '/usr/local/share/lua/5.1/repl/console/init.lua'
    no file '/usr/local/lib/lua/5.1/repl/console.lua'
    no file '/usr/local/lib/lua/5.1/repl/console/init.lua'
    no file './repl/console.so'
    no file '/usr/local/lib/lua/5.1/repl/console.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
    no file './repl.so'
    no file '/usr/local/lib/lua/5.1/repl.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
    [C]: in function 'require'
    ...cks/lib/luarocks/rocks-5.1/luarepl/0.8-1/bin/rep.lua:23: in main chunk
    [C]: ?

我查看 ~/.luarocks 目录:

$ cd ~ ; find .luarocks
.luarocks
.luarocks/bin
.luarocks/bin/rep.lua
.luarocks/config.lua
.luarocks/lib
.luarocks/lib/luarocks
.luarocks/lib/luarocks/rocks-5.1
.luarocks/lib/luarocks/rocks-5.1/luarepl
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/bin
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/bin/rep.lua
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc/COPYING
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc/IDEAS.md
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc/plugins.md
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc/README.md
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/doc/Roadmap.md
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/luarepl-0.8-1.rockspec
.luarocks/lib/luarocks/rocks-5.1/luarepl/0.8-1/rock_manifest
.luarocks/lib/luarocks/rocks-5.1/manifest
.luarocks/share
.luarocks/share/lua
.luarocks/share/lua/5.1
.luarocks/share/lua/5.1/repl
.luarocks/share/lua/5.1/repl/console.lua
.luarocks/share/lua/5.1/repl/init.lua
.luarocks/share/lua/5.1/repl/plugins
.luarocks/share/lua/5.1/repl/plugins/autoreturn.lua
.luarocks/share/lua/5.1/repl/plugins/completion.lua
.luarocks/share/lua/5.1/repl/plugins/example.lua
.luarocks/share/lua/5.1/repl/plugins/filename_completion.lua
.luarocks/share/lua/5.1/repl/plugins/history.lua
.luarocks/share/lua/5.1/repl/plugins/keep_last_eval.lua
.luarocks/share/lua/5.1/repl/plugins/linenoise.lua
.luarocks/share/lua/5.1/repl/plugins/pretty_print.lua
.luarocks/share/lua/5.1/repl/plugins/rcfile.lua
.luarocks/share/lua/5.1/repl/plugins/rlwrap.lua
.luarocks/share/lua/5.1/repl/plugins/semicolon_suppress_output.lua
.luarocks/share/lua/5.1/repl/sync.lua
.luarocks/share/lua/5.1/repl/utils.lua

我可以找到那些东西。 我尝试在 config.lua 中添加一行以从本地安装加载包无济于事:

$ cat ~/.luarocks/config.lua
local_by_default=true

(删除无效)

我是不是漏掉了一些明显的步骤?

运行 luarocks 没有参数给我:

CONFIGURATION
    Lua version: 5.1
    Configuration files:
        System: /usr/local/etc/luarocks51/config-5.1.lua (ok)
        User  : /Users/me/.luarocks/config.lua (ok)

    Rocks trees in use:
        /Users/me/.luarocks ("user")
        /usr/local ("system")

好像用户rock tree不在包路径中:

$ lua
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> print(package.path)
./?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua

为什么?

来自https://github.com/luarocks/luarocks/wiki/Using-LuaRocks

大多数 LuaRocks 装置将有两棵岩石树:

  • "system" 岩石树(默认使用)
  • "user" 岩石树

为了能够使用该模块,我们需要确保 Lua 在 运行 require("dkjson") 时可以找到 dkjson.lua 文件。您可以使用

从 Lua 环境检查您的 Lua 路径
print(package.path)
print(package.cpath)

可以使用 LUA_PATHLUA_CPATH 环境变量从外部 Lua 预先配置这些变量。

如果您将 Lua 和 LuaRocks 安装在它们的默认目录中(/usr/local 在 Linux 和 Mac OSX 上),那么 "system" 树就是 /usr/local 并且它将默认工作。但是,默认情况下 Lua 不会检测到 "user" 树(用于在没有管理员权限的情况下安装 rocks)。为此,我们需要配置这些环境变量。

LuaRocks 提供了一种半自动化的方法来执行此操作。如果您键入以下命令:

luarocks path --bin

它将打印适合您的平台的命令来设置您的环境。在典型的 Unix 终端环境中,您可以键入:

eval $(luarocks path --bin)

并将更改暂时应用到您的 shell。要永久设置这些变量,您必须将环境变量配置为您的 shell 配置(例如,如果您的 shell 是 Bash,则将以上行添加到您的 .bashrc 文件) .