From: Nitro <ni...@dr...> - 2006-10-05 15:53:30
|
Am 05.10.2006, 01:58 Uhr, schrieb Günter Dannoritzer <dan...@we...>: > Hi, > > I am trying to create a callback and follow chapter 5.4.9 "Pointers to > functions and callbacks" on page 38 of the swig documentation. > > It shows the use of the %constant directive to define some call back > functions like this: > > > /* Function with a callback */ > int binary_op(int a, int b, int (*op)(int,int)); > > /* Some callback functions */ > %constant int add(int,int); > %constant int sub(int,int); > %constant int mul(int,int); > > Now when I do that with my function, I am getting a compiler error, that > the function I used instead of the add function is undeclared. > > Here is the code I am using in my .i file: > > typedef int (*brh_t) (handle_t, unsigned int generation); > > brh_t set_handler(handle_t, brh_t new_h); > > %constant brh_t my_handler(handle_t, unsigned int generation); > > > The error message is: > > my_wraper.c: error: my_handler undeclared here (not in a function) > > What am I overlooking here? As in the documentation shown, I want to use > myhandler() in my Python code. I am aware that this needs to be declared > in the _wrap.c file first, but wouldn't that need to be a function done > by swig? You need to define my_handler in your C code yourself somewhere. It could look like this for example: typedef int (*brh_t) (handle_t, unsigned int generation); brh_t set_handler(handle_t, brh_t new_h); %{ brh_t my_handler(handle_t, unsigned int generation) { printf("I was called!"); return 0; } %} %constant brh_t my_handler(handle_t, unsigned int generation); Of course you can also just link to the library which exposes my_handler (if you have a library that exposes it). -Matthias |