Next: , Previous: GObject high-level, Up: GObject Reference


4.11 Creating GObjects classes and implementing GInterfaces

Creating GObject classes from Lisp is the most complex part of GObject binding.

GObject binding at the moment provides only limited scenarios of creating GObject classes. It lets register GObject class (as a subclass of another class or of GObject), specify its properties and implemented interfaces. Each property is associated with Lisp getter and setter functions. Each interface is associated wth vtable (table of virtual function pointers, see http://en.wikipedia.org/wiki/Vtable) that specifies a list of methods and their signatures. If class is ever created from GObject side (not from Lisp side, must be constructable with no parameters).

Each virtual function is mapped to a generic function for which class should provide a specialized method. This function should not be called by user. Rather, user code should call corresponding foreign function.

Practically speaking, creating GObject class requires defining CLOS class that correspond to GObject class and calling register-object-type-implementation with information about the class (its GType name, superclass, interfaces and properties).

Interface that is implemented by a class should have its vtable defined by define-vtable. Vtable definitions consists of a list of functions's names and signatures and their locations in vtable.

Unfortunately, GObject does not provide information about vtables, and does not support using GClosures to implement virtual functions. Therefore, implementation for all interface's functions are defined as CFFI foreign callbacks. These callbacks in turn call corresponding generic functions that should be specialized on required objects.