Next: Creating GObjects classes and implementing GInterfaces, Previous: GObject low-level, Up: Top
GObject high-level support includes integration of GObject and CLOS systems. This enables to use GObjects classes as CLOS classes (with support from
GObjects are reference counted, and CL-GTK2-GOBJECT manages its own reference to GObjects. This enables to have transparent garbage collection of unreferenced GObjects.
To be able to use particular GObject class with CLOS, it should be defined and registered. This is accomplished by
defclass'ing it with
gobject-class metaclass. After GObject class is defined, it may be used as CLOS class.
Example GObject class of definition:
(defclass dialog (gtk-window atk-implementor-iface buildable) ((has-separator :accessor dialog-has-separator :initarg :has-separator :allocation :gobject-property :g-property-type "gboolean" :g-property-name "has-separator")) (:metaclass gobject-class) (:g-type-name . "GtkDialog") (:g-type-initializer . "gtk_dialog_get_type"))
This example defines the CLOS class
dialog that corresponds to GObject class
GtkDialog. Whenever object of GObject type
GtkDialog are to be received from foreign functions or passed to foreign functions, it will be mapped to CLOS class
dialog. Properties that have
:gobject-property are mapped to GObject properties, and reading or writing this slot reads or writes corresponding GObject class property.
GObject does not expose objects methods. Because of this, methods are not automatically mapped to CLOS generic functions and methods. Methods should be manually wrapped with CFFI as foreign functions. Foreign type
g-object aids in it. This type automatically wraps (and unwraps) the GObject class instances and handles the reference counting.
GObject high-level support enables connect signals to signal handlers. Any function may be connected as a signal handler, and GObject will release the reference on signal handler whenever it become unneded (e.g., when object is destroyed or handler is disconnected).