C function callbacks

Started by ryuo, June 12, 2014, 12:48:19 AM

Previous topic - Next topic

ryuo

I have something very specific I wish to do with a C library's function callbacks. It has an object-like design, and I would like to make the user data pointer I feed to the library be able to take a pointer to a newLISP object.



I used the address function on the object's list of properties, but I cannot find a way to convert it back to a list from the pointer within the function callback for the object. I want to do this so I can provide better integration with newLISP by having the object's function callback call the list of registered user callbacks. Mainly I want do do this so the user of my object layer doesn't need to deal with the pointer directly, and is instead fed the newLISP argument to their callback function.



Any ideas for how I can solve this issue?

rrq

#1
I might be in too deep surf here, but since noone else has ventured an answer yet, I'll give it a go... maybe it'll be of help to you.



Notably, the "(address x)" function puts its argument into a CELL_LONG type cell, whose contents field holds the incoming value. Thus, if your C function gets that long value, you can type cast it to (CELL*) in the hope of then having a pointer to the originating cell. This however, I believe, requires your newlisp level code to make sure the cell is not reclaimed by garbage collection, as otherwise it'll cause grief.

ryuo

#2
This leads me to believe that the best option is to use a C intermediate layer. That way I can bypass the lack of low level access I don't have from newLISP for this single purpose.