newLISP Fan Club

Forum => newLISP in the real world => Topic started by: sunmountain on November 25, 2011, 12:57:27 AM

Title: FFI closures are on the way
Post by: sunmountain on November 25, 2011, 12:57:27 AM
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:

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


Which gives

OK <0x7b0008>
Me was called ...
with 3 arguments
6
<closure><6D0090>


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.