openresty / openresty/lua-nginx-module

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

Open
#2,383 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the foo.c example and the content_by_lua_block snippet in the issue, then review the lua-nginx-module documentation for calling C functions and retaining state across requests. Done would be a documented, supported way to invoke the function and cache the parsed configuration result.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, lua
Domain
backend
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.