Next: , Previous: , Up: Categories of Typelib Bindings   [Contents][Index]


2.3.4 GObjects

Some libraries use the GObject class system provided by GLib. GLib provides a complete, if idiosyncratic, class system written in C. It has features such as inheritance and a generic message-passing facility it calls signals.

The GObjects are handled in Guile-GI by creating a GOOPS type that wraps a native pointer. On the GOOPS side, we try to create the same inheritance hierarchy that the GObject classes use. A library provides methods to operate on object, and Guile-GI creates GOOPS generic functions for those methods.

Object instances usually will have parameters that can be queried and modified. If a typelib does not provide an explicit constructor for an object, an empty instance can be created by using make. make can also set the initial values of parameters when the object is constructed

(use-modules (gi))
(use-typelibs ("Gio" "2.0"))
;; Create a new empty <GApplication> using 'make' setting the
;; application-id parameter
(write (make <GApplication> #:application-id "org.test.test"))
(newline)
;; Create a new <GApplication> using a constructor procedure
(define ga (application:new "org.test.test2"
                            (list->application-flags '(handles-open))))
;; Modify the flags parameter of <GApplication> via the set-flags
;; method
(set-flags ga (list->application-flags '(non-unique)))
;; Query if it is running
(write (get-is-busy? ga))
(newline)