Page 1 of 1

C function callbacks

PostPosted: Thu Jun 12, 2014 7:48 am
by 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?

Re: C function callbacks

PostPosted: Sat Jun 14, 2014 8:27 am
by ralph.ronnquist
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.

Re: C function callbacks

PostPosted: Sat Jun 14, 2014 3:03 pm
by ryuo
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.