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


-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/b2181056-1089-49be-838f-3bfef504235b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to