Next: , Previous: , Up: Categories of Typelib Bindings   [Contents][Index]


2.3.3 Structs and Unions

In C, a struct or union is named type of a collection of member objects.

The unions and structs are handled in Guile-GI by creating a GOOPS type that wraps a native pointer. Typically, a library provides methods to operate on structs and unions, and Guile-GI wraps those methods as GOOPS generic functions. If a typelib does not provide an explicit constructor for a struct or union, an empty instance can be created by using make.

(use-modules (gi))
(use-typelibs ("GLib" "2.0"))
;; Create a new empty <GDate> using 'make'
(write (make <GDate>))
(newline)
;; Create a new <GDate> using a constructor procedure
(define dt (date:new-dmy 1 (symbol->date-month 'january) 2000))
;; Modify the contents of <GDate>
(add-years dt 1)
;; Compute the resulting year
(write (get-year dt))
(newline)