infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
Ch03_StatefulCallback.c File Reference

Cookbook Chapter 3: Creating a Stateful Callback. More...

#include <infix/infix.h>
#include <stdio.h>
Include dependency graph for Ch03_StatefulCallback.c:

Classes

struct  AppContext
 

Typedefs

typedef void(* item_processor_t) (int)
 

Functions

static void my_stateful_handler (infix_context_t *context, void *ret, void **args)
 
static void process_list (const int *items, int count, item_processor_t process_func)
 
int main ()
 

Detailed Description

Cookbook Chapter 3: Creating a Stateful Callback.

This example demonstrates how to create a "closure" or stateful callback. This is essential when a C library's callback mechanism does not provide a void* user_data parameter, but your handler still needs access to application state.

infix_reverse_create_closure is used for this. It takes a generic handler function and a void* pointer to your state, which can be retrieved inside the handler.

Typedef Documentation

◆ item_processor_t

typedef void(* item_processor_t) (int)

Function Documentation

◆ main()

int main ( void  )

◆ my_stateful_handler()

static void my_stateful_handler ( infix_context_t context,
void *  ret,
void **  args 
)
static

◆ process_list()

static void process_list ( const int *  items,
int  count,
item_processor_t  process_func 
)
static