[racket] FFI callback object pointer

From: gabor papp (gabor.lists at mndl.hu)
Date: Sat Jul 17 06:45:58 EDT 2010

I'm trying to write an FFI wrapper for a C library that sets and gets 
variables via callback functions. The callbacks look like this:

void callback(void *value, void *clientData);

which I translated to this:

define _callback
     (_fun (value : _pointer)
           (client-data : _pointer)
           -> _void))

What I'm trying to do is passing a boxed variable to the FFI module, and 
when the C library changes the variable it calls the set callback, in 
which I set the content of the box.

I would like to pass the box through the client-data pointer, so the 
callback can do this, but I'm not sure how to do it. Is it possible to 
achieve something like this with FFI?

Another problem is that the variables can have various types: float, 
bool, vector of 3 floats, etc. So apart from passing the box alone, it 
would be better to pass a structure that holds the variable type, size 
and the box, so one callback can handle all variable types. I was 
looking into define-cstruct, but since type and box are not C types, I 
could not find a way to solve this.

Any help would be appreciated.


Posted on the users mailing list.