Hi!
I'm trying to wrap a C library using node-ffi and I have some doubts regarding function pointers.
The C library has a following callback function:
// typedef void (*logfunc_t) (context_t *context, loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *message, void *userdata);
var logFunctionPtr = ffi.Function( ref.refType(ref.types.void), [ contextTPtr, "int", "string", "int", "string", "string", ref.refType(ref.types.void) ]);
And below the FFI definition that I did:
var myLib = ffi.Library("mylib", {
// dc_status_t -> type int
// dc_status_t context_set_logfunc (context_t *context, logfunc_t logfunc, void *userdata);
"context_set_logfunc": [ "int", [ contextTPtr, logFunctionPtr, ref.refType(ref.types.void) ] ]
});
1. Is it the code above ok?
2. How should I pass the callback (as parameter, in red) to the function call? I'm trying this:
myLib.context_set_logfunc(context.ref(), ref.alloc(logFunctionPtr), null);
I'm having trouble trying to find some node-ffi examples where/how a callback function is defined and used?
Thanks.
--
Christian Guimarães