[cffi-devel] Trivial GTK/CFFI test
Luís Oliveira
luismbo at gmail.com
Sun Dec 11 07:39:57 UTC 2005
On 2005-dec-11, at 07:00, ssmith wrote:
> I was trying out CFFI at the weekend and was pleasantly surprised at
> how simple it was to create some simple bindings to GTK:
>
> http://people.vislab.usyd.edu.au/~ssmith/lisp/cffi-gtk-test.lisp
Hello,
Looking at your code, I have a couple of suggestions:
1. (defcfun ("gtk_window_new" gtk-window-new) ...)
This is identical to (defcfun "gtk_window_new" ...), CFFI will
convert the name automatically for you and generate a function named
GTK-WINDOW-NEW.
2. WITH-FOREIGN-OBJECT allocates memory, if what you want to do is
bind the return value of some foreign function to a variable use let.
So your gtk-button-test should look something like this:
(defun gtk-button-test ()
(let (win button)
(gtk-init (null-pointer) (null-pointer))
(setf win (gtk-window-new :gtk-window-toplevel))
(g-signal-connect win "delete_event"
(callback delete-event) (null-pointer))
(gtk-container-set-border-width win 10)
(setf button (gtk-button-new-with-label "Press Me"))
(g-signal-connect button "clicked"
(callback click-event) (null-pointer))
(gtk-container-add win button))
(gtk-widget-show-all win)
(gtk-main)))
BTW, have you looked at cells-gtk? It might be nice to port it to
CFFI *hint* *hint*. :-) It'd be very nice, since IIRC it currently
only supports CLISP, Lispworks and Allegro. You'd have my support, by
e-mail or in #lisp!
--
Luís Oliveira
http://student.dei.uc.pt/~lmoliv/
Equipa Portuguesa do Translation Project
http://www.iro.umontreal.ca/translation/registry.cgi?team=pt
More information about the cffi-devel
mailing list