lua-nginx-module icon indicating copy to clipboard operation
lua-nginx-module copied to clipboard

[question] How to invoke stateful C function in .so with lua

Open zhwaaaaaa opened this issue 1 year ago • 0 comments

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.

zhwaaaaaa avatar Dec 07 '24 09:12 zhwaaaaaa