[plt-scheme] C++ Bindings using FFI

From: Hans Oesterholt-Dijkema (hdnews at gawab.com)
Date: Tue May 9 17:54:14 EDT 2006

Eli Barzilay schreef:
>
> Like I said -- the advantage of SWIG is in its ability to parse the
> header files.
>
>   
> If you can get the type information in some readable format (readable
> without a C-parser), then it should be easy to do the same with
> Scheme, maybe easier.
>   
Ahum. I'd personally use SWIG to generate the type information in 'some 
readable format'.
> My personal conclusion about this is that for some strange reason
> people completely miss the use of the Scheme interface.  It's a
> different mode of thinking, and you should just try it out to see the
> differences.
>   
I actually like the idea of using the scheme interface. I just don't 
want to code the scheme
FFI code for 12.000 functions and a couple of hundred enumeration types.

Also I have questions. How would I resolve the memory management 
differences between
scheme and Gtk (see 
http://www.elemental-programming.org/mzgtk2-mzgtk2-memory-management.html).
How would I let callbacks work? How would I make property setting work 
with GtkValue types?
How would I be able to use the GObject introspection facilities? How 
would I code with use
of the FFI a specific Gtk list-model (that requires a new 'GObject 
derived class') to be able
to use the functional way mzscheme to fill up tables?

It's not a 'in principle possible' question. For me it is a practical 
issue.
> One thing that is definitely easier using the Scheme interface is
> trying quick things out.  I recently wanted to auto-type text on
> Windows.  All I needed was to browse through MSDN and get to the
> description of `keybd_event', and from that I was able to write
>
>   (define key-press
>     (get-ffi-obj "keybd_event" "user32.dll"
>       (_fun (key : _byte)
>             (_byte = 0) (flags : _int32 = 0) (extra : _pointer = #f)
>             -> _void)))
>
> and that's all.  That's very easy compared to a SWIG solution (which I
> wouldn't even be able to use since I don't have a compiler on my
> laptop).
>   
I can and will only agree to that.

--Hans




Posted on the users mailing list.