I m trying to do some string operation inside content by lua
content_by_lua '
local app = ngx.var.arg_app or "none"
local resp = ngx.location.capture("/session?app="..app)
if resp.status == 200 then
_, _, cnt, uid, status = string.find(resp.body, "%[%{\"cnt\":(%d+),\"uid\":(%d+),\"status\":(%d+)%}%]")
ngx.print(resp.body)
end';
basically trying to decode a fix json. I not going via cjson route as the json in my case will be fixed. I have check this code on command line it works
Luajit
> s = '[{"cnt":10,"uid":11,"status":12}]'
> _, _, no, uid, status = string.find(s, "%[%{\"no\":(%d+),\"uid\":(%d+),\"status\":(%d+)%}%]")
> print (no, uid, status)
10 11 12
But when i run in ngnix i get this error. I suspect this has to do with qoutes. Any way i can qoute the string in different way.
2012/10/27 22:39:02 [error] 20335#0: *1 failed to load Lua inlined code: [string "content_by_lua"]:5: ')' expected near 'no', client:---