Maintenance in progress: we are indexing a large batch of new skills. Some pages may load slowly or briefly show no results. Nothing is lost, and everything is back to normal within the hour.

Patterns/callback Context

Callback + Context Pattern (C-Specific) pattern for C development

majiayu000 e0d7190 2 files · 1.5 KB Updated 567 repo stars

File contents

Callback + Context Pattern (C-Specific)

Pair function pointer with void * user data. Callback receives user data, enabling state access without globals. Universal C pattern for async/event handling.

ikigai Application

Streaming responses:

typedef void (*chunk_cb_t)(void *user_ctx, const char *data, size_t len);

res_t ik_llm_stream(ik_llm_client_t *client,
                    ik_message_t **msgs,
                    chunk_cb_t on_chunk,
                    void *user_ctx);  // Passed to callback

Usage: REPL passes itself as context, callback updates scrollback.

Convention: Callback function pointer immediately followed by void * context parameter. Callback signature includes context as first param.

Benefit: Stateful callbacks without globals. Each caller provides own context.

majiayu000/claude-skill-registry-data/tree/main/data/callback-context commit e0d7190de7

Frequently asked questions

npx skillmds add majiayu000/patterns-callback-context