CFFI, callbacks, and void * (how do I create a pointer to a native object in common lisp/cffi?) -
let's have a callback in physics library in c generates collision information 2 objects nearby/touching. callback takes (void *)data parameter i'd use pass in 1 of lisp objects.
how make use of (void *) parameter? can think of (i'm relatively new cffi getting hang of pretty quickly) either
- somehow cast object (a clos object) pointer , pass pointer in callback. i've tried
(cffi:convert-to-foreign my-obj :pointer)returns my-obj, not pointer, , can't call callback it. - create closure around callback can reference data without needing void* pointer. i've searched google bunch , haven't found info on this. can wrap defcallback in defun?
- shove object want pass global scope. seems really, dirty , i'd avoid @ costs.
any ideas on cross-platform way this? know lot of callbacks in c take void* parameter, must have thought of this. i'm using clozure cl, said, more cross-platform/cross-implementation better. thanks!
sorry if answer bit late have come across same problem recently. solution used store lisp objects accessed callbacks in hash table using integer key. have pass key around c functions, cast void* if needed.
Comments
Post a Comment