-- 参数 "j" 启用 JIT 编译,参数 "o" 是开启缓存必须的 local m = ngx.re.match("hello, 1234", regex, "jo")
local args = {...} or {} method_name(unpack(args, 1, table.maxn(args)))
local str = "abcde" print("case 1:", str:sub(1, 2)) print("case 2:", str.sub(str, 1, 2))
可使用一个 lj-releng 工具来扫描 Lua 代码,定位使用 Lua 全局变量的地方。 lj-releng 的相关连接:https://github.com/openresty/openresty-devel-utils/blob/master/lj-releng
function isTableEmpty(t) return t == nil or next(t) == nil end
推荐使用 ngx_lua 模块提供的带缓存的时间接口,如 ngx.today, ngx.time, ngx.utctime, ngx.localtime, ngx.now, ngx.http_time,以及 ngx.cookie_time 等
实际中的应用,在 OpenResty 项目中应尽量让网络处理部分、文件 I/0 操做部分相互独立,不要揉和在一块儿
词库解释html
名词 | 解释 |
---|---|
cdecl | A definition of an abstract C type(actually, is a lua string) |
ctype | C type object |
cdata | C data object |
ct | C type format, is a template object, may be cdecl, cdata, ctype |
cb | callback object |
VLA | An array of variable length |
VLS | A structure of variable length |
local ffi = require("ffi") ffi.cdef[[ int printf(const char *fmt, ...); ]] ffi.C.printf("Hello %s!", "world")
有些时候,ffi.C.xx_create 返回的不是具体的 cdata,而是整型的 handle。这会儿须要用 ffi.metatype 把 ffi.gc 包装一下
```
local resource_type = ffi.metatype("struct {int handle;}", {
__gc = free_resource
})git
local function free_resource(handle)
...
endgithub
resource = ffi.new(resource_type)
resource.handle = ffi.C.xx_create()
```正则表达式
JIT
```
能够经过 ngx-lj-gc-objs 工具看到指定的 Nginx worker 进程里全部 trace 对象的一些基本的统计信息:https://github.com/openresty/stapxx#ngx-lj-gc-objs编程
咱们如何才能知道具体是哪一行 Lua 代码上的哪个 NYI 原语终止了 trace 编译呢?
答案很简单。就是使用 LuaJIT 安装自带的 jit.v 和 jit.dump 这两个 Lua 模块。这两个 Lua 模块会打印出 JIT 编译器工做的细节过程数组
完整的 NYI 列表:http://wiki.luajit.org/NYI缓存
可使用 ab 和 weighttp 这样的工具对相应的服务接口进行预热,以触发 LuaJIT 的 JIT 编译器开始工做
```cookie