代码之家  ›  专栏  ›  技术社区  ›  fferri

本地luarocks包安装(luarepl)不工作

  •  2
  • fferri  · 技术社区  · 7 年前

    我是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
    

    我可以找到那些东西。 我尝试在配置中添加一行。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树似乎不在包路径中:

    $ 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
    

    为什么?

    1 回复  |  直到 7 年前
        1
  •  6
  •   fferri    7 年前

    从…起 https://github.com/luarocks/luarocks/wiki/Using-LuaRocks :

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

    • “系统”岩石树(默认使用)
    • “用户”岩石树

    为了能够使用该模块,我们需要确保Lua能够找到dkjson。当我们运行时lua文件 require("dkjson") . 您可以使用从Lua环境检查Lua路径

    print(package.path)
    print(package.cpath)
    

    这些变量可以使用 LUA_PATH LUA_CPATH 环境变量。

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

    LuaRocks提供了一种半自动化的方法来实现这一点。如果键入以下命令:

    luarocks path --bin
    

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

    eval $(luarocks path --bin)
    

    它会将更改临时应用到shell。要永久设置这些变量,必须将环境变量配置到shell配置中(例如,如果shell是Bash,则将上述行添加到.bashrc文件)。