lua-nginx-module
lua-nginx-module copied to clipboard
[question] How to invoke stateful C function in .so with lua
I want to invoke a stateful C function in so with lua
I want to parse a complex configuration using C, like:
foo.c
void* checkAndParse(void *ctx, char *unparsed, uint64_t key) {
// ...
if (ctx->oldKey == key) {
return ctx->oldParsed;
}
void *parsed = parseConfig(unparsed);
ctx->oldParsed = parsed;
ctx->oldKey = key;
return parsed;
}
content_by_lua_block {
// invoke c function
local parsed = checkAndParse(ctx, ngx.var.http_x_config, key);
ngx.say(r.data);
}
How to cache some result If I use C. Looking forward to your help. Thank you.