安转luajit 和 cjson模块

≡放荡痞女 提交于 2019-12-10 04:36:07

###安装luajit 从luajit下载源码,make && make install 顺利安装 缺省路径安装在/usr/local/ export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0 # 版本号自行修改

###安装cjson
cjson官网 下载源码 解压,编辑Makefile ,修改:
LUA_INCLUDE_DIR = $(PREFIX)/include/luajit-2.0

$ make
cc -c -O3 -Wall -pedantic -DNDEBUG  -I/usr/local/include/luajit-2.0 -fpic -o lua_cjson.o lua_cjson.c
cc -c -O3 -Wall -pedantic -DNDEBUG  -I/usr/local/include/luajit-2.0 -fpic -o strbuf.o strbuf.c
cc -c -O3 -Wall -pedantic -DNDEBUG  -I/usr/local/include/luajit-2.0 -fpic -o fpconv.o fpconv.c

$ sudo make install     
mkdir -p //usr/local/lib/lua/5.1
cp cjson.so //usr/local/lib/lua/5.1
chmod 755 //usr/local/lib/lua/5.1/cjson.so

成功安装后,写个测试代码:

local cjson = require "cjson"
local network = {
    {name = "web001",  IP = "10.10.10.1"},
    {name = "web002",  IP = "10.10.10.2"},
    {name = "web003",  IP = "10.10.10.3"},
    {name = "web004",  IP = "10.10.10.4"},
}
print(cjson.encode(network))
json_text = '[1, {"name":"test"},1111.1111111111,false]'
print(cjson.encode(cjson.decode(json_text)))

###参考: http://huoding.com/2012/08/31/156
http://www.wownepiece.com/category/nginx/
http://blog.irebit.com/luajit%E5%AE%89%E8%A3%85cjson/

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!