【问题标题】:How to import luarocks local modules如何导入 luarocks 本地模块
【发布时间】:2021-09-20 08:08:19
【问题描述】:

我已经在本地使用 Lua Rocks 安装了cjson

 luarocks install --local  lua-cjson

但我无法访问该模块。

> require('cjson')
stdin:1: module 'cjson' not found:

软件包已安装到 ~/.luarocks。以下是文件结构

.
├── bin
│   ├── json2lua
│   └── lua2json
├── lib
│   ├── lua
│   │   └── 5.4
│   │       └── cjson.so
│   └── luarocks
│       └── rocks-5.4
│           ├── lua-cjson
│           │   └── 2.1.0.6-1
│           │       ├── bin
│           │       │   ├── json2lua
│           │       │   └── lua2json
│           │       ├── lua-cjson-2.1.0.6-1.rockspec
│           │       ├── rock_manifest
│           │       └── tests
│           │           ├── agentzh.t
│           │           ├── bench.lua
│           │           ├── example1.json
│           │           ├── example2.json
│           │           ├── example3.json
│           │           ├── example4.json
│           │           ├── example5.json
│           │           ├── genutf8.pl
│           │           ├── numbers.json
│           │           ├── octets-escaped.dat
│           │           ├── README
│           │           ├── rfc-example1.json
│           │           ├── rfc-example2.json
│           │           ├── test.lua
│           │           ├── TestLua.pm
│           │           └── types.json
│           └── manifest
└── share
    └── lua
        └── 5.4
            ├── cjson
            │   └── util.lua
            ├── json2lua.lua
            └── lua2json.lua

为了让 Lua 能够找到包,应该设置哪些环境变量?

【问题讨论】:

    标签: lua luarocks


    【解决方案1】:

    luarocks path 打印应添加的所有内容

    ➜  ~ luarocks path
    export LUA_PATH='/usr/share/lua/5.4/?.lua;/usr/share/lua/5.4/?/init.lua;/usr/lib/lua/5.4/?.lua;/usr/lib/lua/5.4/?/init.lua;./?.lua;./?/init.lua;/home/s1n7ax/.luarocks/share/lua/5.4/?.lua;/home/s1n7ax/.luarocks/share/lua/5.4/?/init.lua'
    export LUA_CPATH='/usr/lib/lua/5.4/?.so;/usr/lib/lua/5.4/loadall.so;./?.so;/home/s1n7ax/.luarocks/lib/lua/5.4/?.so'
    export PATH='/home/s1n7ax/.luarocks/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/s1n7ax/.s1n7ax/bin:/home/s1n7ax/.yarn/bin:/home/s1n7ax/.local/bin'
    

    它只是打印它们而不是运行它们。所以需要运行。我在初始化脚本中添加了以下行以在系统启动时添加路径

    eval $(luarocks path)
    

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 2021-05-08
      • 1970-01-01
      • 1970-01-01
      • 2020-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多