[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ffi-help: status to date
From: |
Matt Wette |
Subject: |
Re: ffi-help: status to date |
Date: |
Tue, 24 Oct 2017 17:18:29 -0700 |
> On Oct 22, 2017, at 11:31 AM, Matt Wette <address@hidden> wrote:
>
> Hi All,
>
> I am working on a ffi-helper (FH): a program that will read in a C dot-h file
> and generate a Guile dot-scm file
> which defines a module to provide hooks into the associated C library.
>
> I was able to generate scm code for glib, gobject, gio, pango, and gtk2+.
> The following demo code actually works.
> I get a GUI and click the button and it closes, though with an error message:
> gtkdemo.scm:16:0: Wrong number of arguments to #<procedure hello (widget
> data)>
>
> (define (hello widget data)
> (display "Hello World!\n"))
> (g_signal_connect button "clicked" hello NULL)
The reason I got error messages was that g_signal_connect uses signature `void
(*f)(void)' for the
callback but the semantics of GTK say use `void (*f)(void*, void*)', basically.
GTK handles this
by providing casts for arguments. I got the code working by hand generating
casts:
(define ~hello (ffi:procedure->pointer ffi:void hello (list '* '*)))
(g_signal_connect button "clicked" ~hello NULL)
Doing this by hand is a bit of a mess, but ... there it is. I am not confident
that there is a way
to automate or make this easier. I had to generate a couple other hand-casts
but the result is that
the demo is now working w/o error messages.
In case you are interested here are line counts for the text files and sizes
for the object files.
(oops, didn't include pango; that is bigish)
mwette$ wc gobject.* glib.* gtk2+.* gdk2.*
26 77 885 gobject.ffi
12543 28465 426476 gobject.scm
31 82 1006 glib.ffi
31326 75035 1013504 glib.scm
17 47 470 gtk2+.ffi
92827 210107 3259549 gtk2+.scm
18 52 534 gdk2.ffi
18986 45046 639630 gdk2.scm
mwette$ ls -l gobject.* glib.* gtk2+.* gdk2.*
-rw-r--r-- 1 mwette staff 3619461 Oct 22 10:57 gdk2.scm.go
-rw-r--r-- 1 mwette staff 5546829 Oct 22 10:48 glib.scm.go
-rw-r--r-- 1 mwette staff 2554501 Oct 24 16:36 gobject.scm.go
-rw-r--r-- 1 mwette staff 18521997 Oct 22 11:06 gtk2+.scm.go