安转luajit 和 cjson模块

安装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/

你可能感兴趣的:(lua,cjson)