C function callbacks

Q&A's, tips, howto's

C function callbacks

Postby ryuo » Thu Jun 12, 2014 7:48 am

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?
ryuo
 
Posts: 43
Joined: Wed May 21, 2014 4:40 pm

Re: C function callbacks

Postby ralph.ronnquist » Sat Jun 14, 2014 8:27 am

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.
ralph.ronnquist
 
Posts: 213
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: C function callbacks

Postby ryuo » Sat Jun 14, 2014 3:03 pm

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.
ryuo
 
Posts: 43
Joined: Wed May 21, 2014 4:40 pm


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 2 guests

cron