lua cjson使用

cjson下载 https://github.com/mpx/lua-cjson.git 下载解压后,编译需要根据自己的lua环境以及操作系统修改Makefile的一些配置,不然容易出错。 以下是Makefile中的一些配置。 c 1 2 3 4 5 6 7 8 LUA_VERSION = 5.2 TARGET = cjson.so PREFIX = /usr/local CJSON_LDFLAGS = -shared LUA_INCLUDE_DIR = $(PREFIX)/include LUA_CMODULE_DIR = $(PREFIX)/lib/lua/$(LUA_VERSION) LUA_MODULE_DIR = $(PREFIX)/share/lua/$(LUA_VERSION) LUA_BIN_DIR = $(PREFIX)/bin https://blog.gezhiqiang.com/2017/08/24/lua-cjson/ lua 1 2 3 4 5 6 7 8 9 10 11 12 13 local cjson = require("cjson") local obj = { id = 1, name = "zhangsan", age = nil, is_male = false, hobby = {"zhangsan","lisi","wangwu"} } local str = cjson....

 ·  · 

lua nginx api

lua 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 location = /reqq { default_type text/plain; content_by_lua_block { ngx.req.read_body() local data = ngx.req.get_body_data() local args, err = ngx.req.get_uri_args() if not args then ngx.say('post fail') return end for key,v in pairs(args) do ngx.say(key,"::",v,"--") end ngx.say(data) } } ngx.exec 内部重定向 lua 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 location = /bb { default_type text/plain; content_by_lua_block{ ngx....

 ·  · 

lua nginx module

lua 1 2 3 4 5 6 7 8 9 10 package1 = {} package1.const = "测试常量" function package1.func1() io.write("this is public func\n") end return package1 req.lua lua 1 2 3 require "package1" package1.func1() print(package1) text 1 2 3 lc@lc-virtual-machine:~/lua$ lua pack1.lua this is public func table: 0x5575766224a0 注意事项: 测试文件是和封装好的模块在同一个目录,否则引用时需要设置路径。 lua 1 2 3 4 5 6 7 package.path = '/home/lc/lua/1/package1.lua;'; require "package1" package1.func1() print(package1) 模块名称和文件名称必须相同

 ·  ·