|(require gir)||package: gir|
This is Gobject FFI.
(define gtk (gi-ffi "Gtk")) (gtk 'init 0 #f) (let ([window (gtk 'Window 'new 0)]) (window 'show) (gtk 'main))
Interface with the GObjectIntrospection is based on repositories. Main function is
func-name : (or/c string? symbol?) func-arg : any/c (repository const-name) → any/c const-name : (or/c string? symbol?) (repository enum-name enum-value-name) → exact-integer? enum-name : (or/c string? symbol?) enum-value-name : (or/c string? symbol?) (repository class-name constructor-name) → procedure? class-name : (or/c string? symbol?) constructor-name : (or/c 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.
(gtk 'WindowType ':toplevel)
(define window (gtk 'Window 'new 0))
(window 'add button)
But you cannot set with :set-field! complex types such as structs, unions or even strings. It is a restriction of GObjectIntrospection.
Getting and setting field values are done with :properties and :set-properties!. You may get or set several properties at once.
(define-values (width height) (window ':properties 'width-request 'height-request)) (window ':set-properties! 'width-request 100 'height-request 200)
object : procedure? signal-name : (or/c symbol? string?) handler : (or/c procedure? cpointer?)
If you like more traditional interface, you may use gi-ffi/interface module
Besides, it provides functional interface for object pointers and properties:
object : procedure? property-name : (or/c string? symbol?)
( object property-name property-value ...+ ...+) → void? object : procedure? property-name : (or/c string? symbol?) property-value : any/c