GLib supports generic typed values via its GValue module. These values are
wrapped in Scheme as instances of <gvalue-class>
classes, such as
<gint>
, <gfloat>
, etc.
In most cases, use of <gvalue>
is transparent to the Scheme user. Values
which can be represented directly as Scheme values are normally given to the
user in their Scheme form, e.g. #\a
instead of #<gvalue <gchar>
3020c708 a>
. However, when dealing with low-level routines it is sometimes
necessary to have values in <gvalue>
form. The conversion between the two
is performed via the scm->gvalue
and gvalue->scm
functions.
The other set of useful procedures exported by this module are those dealing with enumerated values and flags. These objects are normally represented on the C side with integers, but they have symbolic representations registered in the GLib type system.
On the Scheme side, enumerated and flags values are canonically expressed as
<gvalue>
objects. They can be converted to integers or symbols using the
conversion procedures exported by this module. It is conventional for Scheme
procedures that take enumerated values to accept any form for the values, which
can be canonicalized using (make <your-enum-type> #:value
value)
,
where value can be an integer, a symbol (or symbol list in the case of
flags), or the string “nickname” (or string list) of the enumerated/flags
value.
A
<gvalue>
class for “boxed” types, a way of wrapping generic C structures. You won't see instances of this class, only of its subclasses.
A
<gvalue>
base class for enumerated values. Users may define new enumerated value types via subclssing from<genum>
, passing#:vtable
table as an initarg, where table should be in a format suitable for passing togenum-register-static
.
A
<gvalue>
base class for flag values. Users may define new flag value types via subclssing from<gflags>
, passing#:vtable
table as an initarg, where table should be in a format suitable for passing togflags-register-static
.
Creates and registers a new enumerated type with name name with the C runtime. There must be no type with name name when this function is called.
The new type can be accessed by using
gtype-name->class
.vtable is a vector describing the new enum type. Each vector element describes one enum element and must be a list of 3 elements: the element's nick name as a symbol, its name as a string, and its integer value.
(genum-register-static "Test" #((foo "Foo" 1) (bar "Bar" 2) (baz "Long name of baz" 4)))
Creates and registers a new flags
<gtype-class>
with name name with the C runtime.The vtable should be in the format described in the documentation for
genum-register-static
.
Return a table of the values supported by the enumerated
<gtype-class>
class. The return value will be in the format described ingenum-register-static
.
Return a table of the values supported by the flag
<gtype-class>
class. The return value will be in the format described ingflags-register-static
.
Convert a Scheme value into a
<gvalue>
of type class. If the conversion is not possible, raise agruntime-error
.
Convert a
<gvalue>
into it normal scheme representation, for example unboxing characters into Scheme characters. Note that the Scheme form for some values is the<gvalue>
form, for example with boxed or enumerated values.
Convert the enumerated value obj from a
<gvalue>
to its symbol representation (its “nickname”).
Convert the enumerated value obj from a
<gvalue>
to its representation as a string (its “name”).
Convert the enumerated value obj from a
<gvalue>
to its representation as an integer.
Convert the flags value obj from a
<gvalue>
to its representation as an integer.
Convert the flags value obj from a
<gvalue>
to a list of the symbols that it represents.