I\'m trying to write a SWIG wrapper for a C library that uses pointers to functions in its structs. I can\'t figure out how to handle structs that contain function pointers
You forget to "return t;" in init_test():
#include
#include
typedef struct {
int (*my_func)(int);
} test_struct;
int add1(int n) { return n+1; }
test_struct *init_test(){
test_struct *t = (test_struct*) malloc(sizeof(test_struct));
t->my_func = add1;
return t;
}
int main(){
test_struct *s=init_test();
printf( "%i\n", s->my_func(1) );
}