Honorable <gnhor@...> wrote:
>> Sam -- is ffi:def-call-in the way that gtk callbacks could be
>> implemented in clisp's ffi?
>yes, I think so.
>Joerg is the CLISP FFI expert, I hope he will reply.
def-call-in can be used, but it's not the only way.
An alternative is always to use correct (ffi:c-function ...) declarations for function arguments or for foreign places. This allows conversion between Lisp and foreign functions, including arbitrary closures, by creating trampolines (callbacks) as needed. This is particularly suited for variable or dynamic callbacks (Lisp function unknown at compile time).
I once added a callback example in the ffi testsuite. It may help you.
Note that the pattern I use therein gives you the ability to free the trampoline later, preventing possibly unlimited growth of an internal table of trampolines, while
(some-foreign-function #'(lambda ...) ...))
will fill that table (one entry for each closure), with few options to free it, unless you manage to get a handle on the trampoline.
Your choice will probably depend on the GTK setup: if there are few callbacks to known Lisp functions which themselves dispatch to user callbacks, a module using def-call-in is possible. If you want the foreign world to directly call user-supplied Lisp functions, then you have no change but to use the FFI dynamic conversion support (and probably do something to avoid growing that table, but talk to me again if that is a concern).
Get latest updates about Open Source Projects, Conferences and News.