Import

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

Procedures

gi-import-info
gi-import-enum
gi-import-flags
gi-import-struct
gi-import-function
gi-import-constant

Variables

%gi-base-info-types
%gi-imported-base-info-types

Procedures

Procedure: gi-import-info info

Returns the object or constant returned by the one of the gi-import-enum, gi-import-flags, …, called upon info.

Obtains the GIBaseInfo type for info and uses it to dispatch a call to gi-import-enum, gi-import-enum, …, and returns the object or constant returned by the procedure that has been called.

You probably will prefer to call gi-import-by-name most of the time, but here is a example:

,use (g-golf)
(g-irepository-require "Clutter")
⇒ $2 = #<pointer 0x5642cb065e30>

(g-irepository-find-by-name "Clutter" "ActorFlags")
⇒ $3 = #<pointer 0x5642cb067de0>

(gi-import-info $3)
⇒ $4 = #<<gi-flags> 5642cb13c5d0>

(describe $4)
-| #<<gi-flags> 5642cb13c5d0> is an instance of class <gi-flags>
-| Slots are:
-|      enum-set = ((mapped . 2) (realized . 4) (reactive . 8) (visible . 16) (no-layout . 32))
-|      g-type = 94844874149456
-|      g-name = "ClutterActorFlags"
-|      name = clutter-actor-flags
Procedure: gi-import-enum info [#:with-method #t]
Procedure: gi-import-flags info [#:with-method #t]
Procedure: gi-import-struct info [#:with-method #t]

Returns a <gi-enum>, a <gi-flags> or a <gi-struct> instance, respectively.

The info argument is (must be) a pointer to GIEnumInfo, a GIEnumInfo for which (g-base-info-get-type info) returned 'flags and a GIStructInfo respectively. It is an error to call any of these procedures upon an invalid info argument.

The optional keyword #:with-method argument - which is #t by default - is passed using #f, then info will be imported without its respective methods. A description and an example ware also given here above, as part of the gi-import-by-name documentation entry.

Every imported <gi-enum>, <gi-flags> and <gi-struct> instance is cached under the 'enum, 'flags and 'boxed main key (respectively), using the content of their (symbol) name slot as the secondary key. For example, reusing the "Clutter" "ActorFlags" namespace/name introduced above, you would retreive its <gi-flags> instance as is:

...
(gi-cache-ref 'flags 'clutter-actor-flags)
⇒ $6 = #<<gi-flags> 5642cb13c5d0>
Procedure: gi-import-function info

Returns a <function> instance.

Imports info - a pointer to a GIFunctionInfo (see Function Info), which represents a function, a method or a constructor - in Guile and exports its interface. This procedure also imports, recursively (and exports the interface of) its argument’s type(s) and method(s).

Every imported function, method and constructor is cached under 'function main key, and using the value of their <function> instance name slot as the secondary key. Here is an example:

,use (g-golf)
(g-irepository-require "Clutter")
⇒ $2 = #<pointer 0x55c191f3fe30>

(g-irepository-find-by-name "Clutter" "init")
⇒ $3 = #<pointer 0x55c191f41de0>

(gi-import-function $3)
⇒ $4 = #<<function> 55c191e81510>

(describe $4)
-| #<<function> 55c191e81510> is an instance of class <function>
-| Slots are:
-|      info = #<pointer 0x55c191f41de0>
-|      name = clutter-init
-|      flags = ()
-|      n-arg = 2
-|      caller-owns = nothing
-|      return-type = interface
...

(gi-cache-ref 'function 'clutter-init)
⇒ $5 = #<<function> 55c191e81510>

Returned value(s):

In most situations - unless the return-type is 'void (in which case nothing is returned) - the function or method returned value comes first, then in order, if any, the value(s) of its 'inout and 'out argument(s).

However, some function and method, that have at least one 'inout or 'out argument(s), do return #t or #f solely to indicate that the function or method call was successful or not. It is only if the call is successful that the 'inout and 'out argument(s) have been ‘correctly’ set and may safely be used.

In scheme, when binding such a function or method, we would rather (a) when the call is successful, elude the boolean and return, in order, the 'inout and/or 'out argument(s) value(s); and (b), when the call is unsuccessful, raise an exception.

Since it is not possible to automatically detect these functions and methods, G-Golf provides a series of interfaces to maintain, at user discretion and responsibility, a list of GI typelib functions and methods for which G-Golf is expected to elude their result value from the returned value(s). G-Golf interfaces to maintain this list are documented in the Customization Square section.

Procedure: gi-import-constant info

Returns two values, the constant value and its name.

Obtains and returns the info constant value and its name. For example:

,use (g-golf)
(g-irepository-require "GLib")
⇒ #<pointer 0x55ad58e6ae00>

(g-irepository-find-by-name "GLib" "PRIORITY_DEFAULT_IDLE")
⇒ $3 = #<pointer 0x55ad58e6cde0>

(gi-import-constant $3)
⇒ $4 = 200
⇒ $5 = "PRIORITY_DEFAULT_IDLE"

Constants are curently not being automatically imported, though this will probably change in the near future, stay tuned.

Variables

Variable: %gi-base-info-types
Variable: %gi-imported-base-info-types

A (cumulative) list of the distinct (top level) base info types contained in the imported namespace(s).

These two variables have no other purpose then offering a feedback about: (a) the (top level) base info types contained in the namespace(s) passed to gi-import; (b) the (top level) base info types that have effectively been imported - when G-Golf is complete, both lists should be identical.

Initially, these variables are empty. As gi-import, gi-import-info and/or gi-import-by-name are being called, they are filled with new types, which are added to both lists.

Note that the order in which base info types appear in these two lists is rrelevant, and may slightly vary, depending on the order of the namespace used for the successive gi-import calls and how complete is G-Golf.