guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ffi-help: gtk demo updated


From: Matt Wette
Subject: ffi-help: gtk demo updated
Date: Tue, 13 Mar 2018 17:13:19 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

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.

Lately I've been working to clean up user-level APIs.  A recoded demo of the 
GTK+
Hello World example is shown below.  This is based on 100% guile wrappers to the
loaded C libraries for gtk+, gobject, pango and glib.. The comments with the
(use-modules (ffi xxx)) lines below indicate the line-counts for the associated
ffi file and its auto-generated scm file.

If you `git clone -b c99dev git://git.savannah.nongnu.org/nyacc.git' you will 
find
the demo in examples/nyacc/lang/c99/ffi-exam/.  Read the ffi-helper section of 
the
HACKING file for hints to run the demo.  Caveat: Up until a few months ago I was
developing on MacOS; I am now on Ubuntu.


;; gtkdemo.scm
;;https://developer.gnome.org/gtk-tutorial/stable/c39.html#SEC-HELLOWORLD

(use-modules (system ffi-help-rt))
(use-modules (bytestructures guile))

(use-modules (ffi glib))                ; ffi:31 scm:31889
(use-modules (ffi gobject))             ; ffi:26 scm:12044
(use-modules (ffi gtk2+))               ; ffi:26 scm:92964

;; This will generate a FFI code wrapper around the lambda.  Then below
;; we use (fh-cast GCallback hello) to match the argument signature.
(define hello
  (make-GtkCallback
   (lambda (widget data)
     (display "Hello world!\n"))))

(define (delete-event widget event data)
  (display "delete event occurred\n")
  1)

(define (main)
  (define window #f)
  (define button #f)
  (define argc (bytestructure int 0))

  (gtk_init (pointer-to argc) NULL)

  (set! window (gtk_window_new 'GTK_WINDOW_TOPLEVEL))
  (g_signal_connect window "delete-event" delete-event NULL)
  (g_signal_connect window "destroy" ~gtk_main_quit NULL)
  (gtk_container_set_border_width window 10)

  (set! button (gtk_button_new_with_label "Hello World"))
  (g_signal_connect button "clicked" (fh-cast GCallback hello) NULL)
  (g_signal_connect_swapped button "clicked" ~gtk_widget_destroy window)
  (gtk_container_add window button)

  (gtk_widget_show button)
  (gtk_widget_show window)

  (gtk_main))

(main)

;; --- last line ---



reply via email to

[Prev in Thread] Current Thread [Next in Thread]