On Wed, 2014-11-05 at 09:16 +0000, Luís Oliveira wrote:
On Wed, Nov 5, 2014 at 7:53 AM, FAU fau@riseup.net wrote:
Is there a reliable/portable way to have lambdas called as a callback from a foreign C function? I assume there's not though.
SBCL has an ALIEN-LAMBDA but, last time I checked, most Lisps don't have a similar feature.
I could imagine it could be simulated (by a dispatcher callback or something) so I'm wondering if somebody has done something like that before and may share insight into her/his design.
I know one of the GTK bindings did something like this, but it used some GTK-specific tricks. IIRC, callbacks were somehow associated with specific GTK objects, and so you could dispatch on those.
If you know the callback will be invoked within your foreign function call, a special variable might do the trick, but you'd have to define callbacks a priori for each and every combination of argument types.
I think you might be able to do this using libffi's closure API, though. (See cffi-libffi for inspiration on how to use libffi.) Do you feel like giving that a go?
Thanks for all the details. I'll have a look at this.