Import

G-Golf Import interfaces.
Importing GNOME libraries.

Procedures

gi-import
gi-import-by-name

Description

The G-Golf GIR namespace (Typelib) import interfaces.

Procedures

Procedure: gi-import namespace #:key (version #f)

Returns nothing.

Imports the namespace GIR Typelib and exports its interface. For example:

,use (g-golf
(gi-import "Clutter")

The namespace is a case sensitive string. It is an error to call this procedure using an invalid namespace.

The optional #:version keyword argument may be used to require a specific namespace version, otherwise, the latest will be used.

This procedure is certainly one of the first thing you will want to try and use, but it has a cost: you will not ‘feel it’ if the number of objects in namespace is relatively small, but importing the "Gtk" namespace, on a laptop equiped with a i5-2450M CPU  2.50GHz × 4 and 6GB of memory takes nearly 2 seconds.

So, either early in the development cycle, or when your application is more stable, at your best convenience, you may consider making a series of selective import instead, see gi-import-by-name here below.

Procedure: gi-import-by-name namespace name #:key (version #f) (force? #f) (with-method #t) (allow-constant? #f)

Returns the object returned by gi-import-info called upon the GIBaseInfo info named name in namespace. The namespace and name arguments are case sensitive. It is an error to call this procedure using an invalid namespace or name.

The optional #:version keyword argument may be used to require a specific namespace version, otherwise, the latest will be used.

The optional #:force? keyword argument is required to import object(s) from the GLib and GObject namespaces, as G-Golf won’t allow any import from those by default (due to bootsrap reasons, a very important part of those namespaces are manually imported, see the GLib and GObject sections of the G-Golf Core Reference parts of the manual). As a user, you should normally not have to import for neither GLib nor GObject (if you think you do, ask for help, either by email or on irc), unless you really know what you are doing, this may corrupt your g-golf session/environment - you have been warned.

The optional #:with-method keyword argument (which is #t by default) is passed to the gi-import-enum, gi-import-flags and gi-import-struct. When #:with-method is #f, then the enum, flags or struct info will be imported without their respective methods.

The optional #:allow-constant? keyword argument is required to import constants, as by default, G-Golf doesn’t not import any constants, from any namespace. The reason is there are (far) too many and most are not useful for language bindings, but of course there are exception(s), such as (for example) the Gdk KEY_* constants, required to add shortcuts to your application. Here is an example, an excerpt from the (pages tab-view tab-view-demo-window) module (distributed with G-Golf, in the examples/adw-1/demo directory):

(define (install-shortcuts tab-view-demo-window)
  (let ((controller (make <gtk-shortcut-controller>)))
    (set-scope controller 'managed)
    (add-controller tab-view-demo-window controller)
    (for-each (match-lambda
                ((key-name modifiers action-name)
                 (let ((key-value
                        (gi-import-by-name "Gdk" key-name
                                           #:allow-constant? #t)))
                   (add-shortcut controller
                                 (make <gtk-shortcut>
                                   #:trigger (make <gtk-keyval-trigger>
                                               #:keyval key-value
                                               #:modifiers modifiers)
                                   #:action (make <gtk-named-action>
                                              #:action-name action-name))))))
        '(("KEY_n" (control-mask)  "win.window-new")
          ("KEY_t" (control-mask)  "win.tab-new")
          ("KEY_w" (control-mask)  "tab.close")))))