2016-09-29 44 views
1

Lua中找不到安装luarocks我安装luarocks:在Ubuntu

$ sudo apt-get install luarocks 

我安装LUA-cjson由luarocks:

$sudo luarocks install lua-cjson 

节目包:

$luarocks list 

Installed rocks: 
---------------- 
lua-cjson 
    2.1.0-1 (installed) - /usr/local/lib/luarocks/rocks 

所以,我看包:

$luarocks show lua-cjson 

License: MIT 
Homepage: http://www.kyne.com.au/~mark/software/lua-cjson.php 
Installed in: /usr/local 
. . . 
Modules: 
    cjson 
    lua2json 
    json2lua 
    cjson.util 


    lua-cjson 
      2.1.0-1 (installed) - /usr/local/lib/luarocks/rocks 

但是,Lua中无法看到的模块:

$lua 
Lua 5.2.3 Copyright (C) 1994-2013 Lua.org, PUC-Rio 
> require "cjson" 
stdin:1: module 'cjson' not found: 
.... 


$locate cjson.so 
/usr/local/lib/lua/5.1/cjson.so 

它是什么错误?

回答

2

问题似乎是luarocks默认为Lua 5.1安装了东西(如果您使用apt-get安装它,这是行为)。如果你不介意使用Lua 5.1,你可以直接使用它(通过输入lua5.1),而require "cjson"应该可以正常工作。

如果你真的想要用于Lua 5.2的cjson,这有点复杂。首先,你需要确保你有Lua 5.2的开发文件。尝试

sudo apt-get install liblua5.2-dev 

然后下载最新版本的源动力,luarockshere。 Extract和cd添加到终端的目录中。

然后执行以下命令(从this post

./configure --lua-version=5.2 --versioned-rocks-dir 
make build 
sudo make install 

这将安装一个版本的luarocks与Lua的5.2工作。然后,您可以使用

sudo luarocks-5.2 install lua-cjson 

,那么你应该能够在Lua 5.2使用cjson安装cjson