FFI closures are on the way

Q&A's, tips, howto's

FFI closures are on the way

Postby sunmountain » Fri Nov 25, 2011 8:57 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:
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.
Posts: 39
Joined: Tue Mar 15, 2011 5:11 am

Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 4 guests