GObject Introspection
1 Main interface
This is Gobject FFI.
Usage example:
(defvar *gtk* (gir:ffi "Gtk")) (gir:call *gtk* 'init 0 (cffi:null-pointer)) (let ((window (gir:call *gtk* "Window" 'new 0))) (gir:call window 'show) (gir:call *gtk* 'main))
Interface with the GObjectIntrospection is based on repositories. Main function is
procedure
(ffi repository-name [version]) → function
repository-name : string version : string = nil
2 Using interface objects
Every interface object, returned by ffi, or other objects can be used in function call as you can see in the example above. In this version call is simply alias to cl:funcall, but in future versions this may change.
3 Get FFI element
procedure
(repository func-name func-arg ...) → any
func-name : (or string symbol) func-arg : any (repository const-name) → any const-name : (or string symbol) (repository enum-name enum-value-name) → integer enum-name : (or string symbol) enum-value-name : (or string symbol) (repository class-name constructor-name) → function class-name : (or string symbol) constructor-name : (or string symbol)
This interface takes as a first argument name of foreign object. Name could be string or symbol. In both cases it’s allowed to replace "_" with "-". So you can write either "get_name" or ’get-name with the same result. If you use symbol its name is downcased.
(defvar *gtk* (ffi "Gtk")) (call *gtk* 'init 0 (cffi:null-pointer))
(call *gtk* "MAJOR-VERSION")
If first argument is a name of enumeration, then second arguments should be value name. It returns integer value. Value name must be keyword. Any other symbol or string will mean, that you want call a method with that name.
(call *gtk* "WindowType" :toplevel)
(defvar *window* (gir:call *gtk* "Window" 'new 0))
4 Foreign objects
procedure
(call object method-name method-arg ...) → any
object : gir-object method-name : (or string symbol) method-arg : any
Representation of an object is also a function. First argument of it should be either name of method (string or symbol) or keyword with special meaning.
(call *window* 'add button)
4.1 Pointer to object
(call *window* :this)
(defvar *window-from-ptr* (call *gtk* "Window" window-ptr))
window-ptr should be cffi:foreign-pointer here.
4.2 Fields
(defvar *entry* (call *gtk* "TargetEntry" 'new "ok" 0 0)) > (call *entry* :field 'flags) 0 > (call *entry* :set-field! 'flags 1) > (call *entry* :field 'flags) 1
But you cannot set with :set-field! complex types such as structs, unions or even strings. It is a restriction of GObjectIntrospection.
4.3 Properties
Getting and setting field values are done with :properties and :set-properties!. You may get or set several properties at once.
(multiple-value-bind (width height) (call *window* :properties 'width-request 'height-request) ...) (call *window* :set-properties! 'width-request 100 'height-request 200)
5 Signals
procedure
(connect object signal-name handler) → void?
object : gir-object signal-name : (or symbol string) handler : (or function cffi:foreign-pointer string symbol)
Connects signal handler to object. If handler is a string o symbol, then it denotes C-function.