Page 1 of 1

FFI closures are on the way

Posted: Fri Nov 25, 2011 8:57 am
by sunmountain
This morning, while commuting, I did finish the foundation for ffi closures.
That said, now I can create real ffi closures and get their addresses for later use,
and more important, call them.

Hopefully on my way back home I finish the marshalling code and can show some demo.

To give you a clue on how it is used:

Code: Select all

(set 'a (callback (lambda (a b c) (mul a b c)) "int" "int" "int" "int"))
(println (a 1 2 3))
(println a)
Which gives

Code: Select all

OK <0x7b0008>
Me was called ...
with 3 arguments
The most interesting part here is Me was called ..., which is a real C call (the (println (a 1 2 3)) should not confuse you) to a ffi closure,
which then calls a trampoline function which executes the lambda in the callback definition.

The missing pieces are stuffing the lamba with arguments and returning the result cell(s) back
to the caller.
This explanation might get clearer if you see the code, though.