3.34 <GValue>

Structure: <GValue>

An opaque structure used to hold different types of values.

Before it can be used, a <GValue> has to be initialized to a specific type by calling value:init on it.

Many types which are stored within a <GValue> need to allocate data on the heap, so value:unset must always be called on a <GValue> to free any such data once you’re finished with the <GValue>, even if the <GValue> itself is stored on the stack.

The data within the structure has protected scope: it is accessible only to functions within a <GTypeValueTable> structure, or implementations of the g_value_*() API. That is, code which implements new fundamental types.

<GValue> users cannot make any assumptions about how data is stored within the 2 element data union, and the g-type member should only be accessed through the GObject.VALUE_TYPE macro and related macros.

Fields

data

Procedures

Method: value:copy self dest-value
Method: copy self dest-value

Copies the value of self into dest-value.

self

Passed: a <GValue>.

an initialized <GValue> structure

dest-value

Passed: a <GValue>.

an initialized <GValue> structure of the same type as self

Method: value:dup-object self ⇒ %return
Method: dup-object self ⇒ %return

Get the contents of a G_TYPE_OBJECT derived <GValue>, increasing its reference count. If the contents of the <GValue> are #f, then #f will be returned.

self

Passed: a <GValue>.

a valid <GValue> whose type is derived from G_TYPE_OBJECT

%return

Returned: a <GObject>, or #f.

object content of self, should be unreferenced when no longer needed.

Method: value:dup-string self ⇒ %return
Method: dup-string self ⇒ %return

Get a copy the contents of a G_TYPE_STRING <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_STRING

%return

Returned: a string, or #f.

a newly allocated copy of the string content of self

Method: value:dup-variant self ⇒ %return
Method: dup-variant self ⇒ %return

Get the contents of a variant <GValue>, increasing its refcount. The returned <GVariant> is never floating.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_VARIANT

%return

Returned: a <GVariant>, or #f.

variant contents of self (may be #f); should be unreffed using variant:unref when no longer needed

Method: value:fits-pointer? self ⇒ %return
Method: fits-pointer? self ⇒ %return

Determines if self will fit inside the size of a pointer value.

This is an internal function introduced mainly for C marshallers.

self

Passed: a <GValue>.

an initialized <GValue> structure

%return

Returned: a boolean.

true if self will fit inside a pointer value; false otherwise

Method: value:get-boolean? self ⇒ %return
Method: get-boolean? self ⇒ %return

Get the contents of a G_TYPE_BOOLEAN <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_BOOLEAN

%return

Returned: a boolean.

boolean contents of self

Method: value:get-boxed self ⇒ %return
Method: get-boxed self ⇒ %return

Get the contents of a G_TYPE_BOXED derived <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of G_TYPE_BOXED derived type

%return

Returned: a foreign pointer, or #f.

boxed contents of self

Method: value:get-char self ⇒ %return
Method: get-char self ⇒ %return

Do not use this function; it is broken on platforms where the char type is unsigned, such as ARM and PowerPC. See value:get-schar.

Get the contents of a G_TYPE_CHAR <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_CHAR

%return

Returned: an 8-bit integer.

character contents of self

Method: value:get-double self ⇒ %return
Method: get-double self ⇒ %return

Get the contents of a G_TYPE_DOUBLE <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_DOUBLE

%return

Returned: a real number.

double contents of self

Method: value:get-enum self ⇒ %return
Method: get-enum self ⇒ %return

Get the contents of a G_TYPE_ENUM <GValue>.

self

Passed: a <GValue>.

a valid <GValue> whose type is derived from G_TYPE_ENUM

%return

Returned: a 32-bit integer.

enum contents of self

Method: value:get-flags self ⇒ %return
Method: get-flags self ⇒ %return

Get the contents of a G_TYPE_FLAGS <GValue>.

self

Passed: a <GValue>.

a valid <GValue> whose type is derived from G_TYPE_FLAGS

%return

Returned: an unsigned 32-bit integer.

flags contents of self

Method: value:get-float self ⇒ %return
Method: get-float self ⇒ %return

Get the contents of a G_TYPE_FLOAT <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_FLOAT

%return

Returned: a real number.

float contents of self

Method: value:get-gtype self ⇒ %return
Method: get-gtype self ⇒ %return

Get the contents of a G_TYPE_GTYPE <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_GTYPE

%return

Returned: a class, or a GType number.

the GType stored in self

Method: value:get-int self ⇒ %return
Method: get-int self ⇒ %return

Get the contents of a G_TYPE_INT <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_INT

%return

Returned: a 32-bit integer.

integer contents of self

Method: value:get-int64 self ⇒ %return
Method: get-int64 self ⇒ %return

Get the contents of a G_TYPE_INT64 <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_INT64

%return

Returned: a 64-bit integer.

64bit integer contents of self

Method: value:get-long self ⇒ %return
Method: get-long self ⇒ %return

Get the contents of a G_TYPE_LONG <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_LONG

%return

Returned: a 64-bit integer.

long integer contents of self

Method: value:get-object self ⇒ %return
Method: get-object self ⇒ %return

Get the contents of a G_TYPE_OBJECT derived <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of G_TYPE_OBJECT derived type

%return

Returned: a <GObject>, or #f.

object contents of self

Method: value:get-param self ⇒ %return
Method: get-param self ⇒ %return

Get the contents of a G_TYPE_PARAM <GValue>.

self

Passed: a <GValue>.

a valid <GValue> whose type is derived from G_TYPE_PARAM

%return

Returned: a <GParam>.

<GParam> content of self

Method: value:get-pointer self ⇒ %return
Method: get-pointer self ⇒ %return

Get the contents of a pointer <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of G_TYPE_POINTER

%return

Returned: a foreign pointer, or #f.

pointer contents of self

Method: value:get-schar self ⇒ %return
Method: get-schar self ⇒ %return

Get the contents of a G_TYPE_CHAR <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_CHAR

%return

Returned: an 8-bit integer.

signed 8 bit integer contents of self

Method: value:get-string self ⇒ %return
Method: get-string self ⇒ %return

Get the contents of a G_TYPE_STRING <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_STRING

%return

Returned: a string, or #f.

string content of self

Method: value:get-uchar self ⇒ %return
Method: get-uchar self ⇒ %return

Get the contents of a G_TYPE_UCHAR <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_UCHAR

%return

Returned: an unsigned 8-bit integer.

unsigned character contents of self

Method: value:get-uint self ⇒ %return
Method: get-uint self ⇒ %return

Get the contents of a G_TYPE_UINT <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_UINT

%return

Returned: an unsigned 32-bit integer.

unsigned integer contents of self

Method: value:get-uint64 self ⇒ %return
Method: get-uint64 self ⇒ %return

Get the contents of a G_TYPE_UINT64 <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_UINT64

%return

Returned: an unsigned 64-bit integer.

unsigned 64bit integer contents of self

Method: value:get-ulong self ⇒ %return
Method: get-ulong self ⇒ %return

Get the contents of a G_TYPE_ULONG <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_ULONG

%return

Returned: an unsigned 64-bit integer.

unsigned long integer contents of self

Method: value:get-variant self ⇒ %return
Method: get-variant self ⇒ %return

Get the contents of a variant <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_VARIANT

%return

Returned: a <GVariant>, or #f.

variant contents of self (may be #f)

Method: value:init self g-type ⇒ %return
Method: init self g-type ⇒ %return

Initializes self to store values of the given type, and sets its value to the initial value for type.

This must be called before any other methods on a <GValue>, so the value knows what type it’s meant to store.

  GValue value = G_VALUE_INIT;

  g_value_init (&value, SOME_G_TYPE);
  …
  g_value_unset (&value);
self

Passed: a <GValue>.

a zero-filled (cleared) <GValue> structure

g-type

Passed: a class, or a GType number.

type the <GValue> should hold values of

%return

Returned: a <GValue>.

the <GValue> structure that has been passed in

Method: value:peek-pointer self ⇒ %return
Method: peek-pointer self ⇒ %return

Returns the value contents as a pointer.

This function asserts that value:fits-pointer? returned true for the passed in value.

This is an internal function introduced mainly for C marshallers.

self

Passed: a <GValue>.

an initialized <GValue> structure

%return

Returned: a foreign pointer, or #f.

the value contents as a pointer

Method: value:reset self ⇒ %return
Method: reset self ⇒ %return

Clears the current value in self and resets it to the initial value (as if the value had just been initialized using value:init).

self

Passed: a <GValue>.

an initialized <GValue> structure

%return

Returned: a <GValue>.

the <GValue> structure that has been passed in

Method: value:set-boolean self v-boolean
Method: set-boolean self v-boolean

Set the contents of a G_TYPE_BOOLEAN <GValue> to v-boolean.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_BOOLEAN

v-boolean

Passed: a boolean.

boolean value to be set

Method: value:set-boxed self [v-boxed]
Method: set-boxed self [v-boxed]

Set the contents of a G_TYPE_BOXED derived <GValue> to v-boxed.

self

Passed: a <GValue>.

a valid <GValue> of G_TYPE_BOXED derived type

v-boxed

Passed, or left out: a foreign pointer, or a bytevector, or #f.

caller-owned boxed object to be duplicated for the <GValue>

Method: value:set-boxed-take-ownership self [v-boxed]
Method: set-boxed-take-ownership self [v-boxed]

This is an internal function introduced mainly for C marshallers.

self

Passed: a <GValue>.

a valid <GValue> of G_TYPE_BOXED derived type

v-boxed

Passed, or left out: a foreign pointer, or a bytevector, or #f.

duplicated unowned boxed value to be set

Method: value:set-char self v-char
Method: set-char self v-char

Set the contents of a G_TYPE_CHAR <GValue> to v-char.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_CHAR

v-char

Passed: an 8-bit integer, or a character.

character value to be set

Method: value:set-double self v-double
Method: set-double self v-double

Set the contents of a G_TYPE_DOUBLE <GValue> to v-double.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_DOUBLE

v-double

Passed: a real number.

double value to be set

Method: value:set-enum self v-enum
Method: set-enum self v-enum

Set the contents of a G_TYPE_ENUM <GValue> to v-enum.

self

Passed: a <GValue>.

a valid <GValue> whose type is derived from G_TYPE_ENUM

v-enum

Passed: a 32-bit integer.

enum value to be set

Method: value:set-flags self v-flags
Method: set-flags self v-flags

Set the contents of a G_TYPE_FLAGS <GValue> to v-flags.

self

Passed: a <GValue>.

a valid <GValue> whose type is derived from G_TYPE_FLAGS

v-flags

Passed: an unsigned 32-bit integer.

flags value to be set

Method: value:set-float self v-float
Method: set-float self v-float

Set the contents of a G_TYPE_FLOAT <GValue> to v-float.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_FLOAT

v-float

Passed: a real number.

float value to be set

Method: value:set-gtype self v-gtype
Method: set-gtype self v-gtype

Set the contents of a G_TYPE_GTYPE <GValue> to v-gtype.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_GTYPE

v-gtype

Passed: a class, or a GType number.

GType to be set

Method: value:set-instance self [instance]
Method: set-instance self [instance]

Sets self from an instantiatable type.

This calls the <GTypeValueCollectFunc> function for the type the <GValue> contains.

self

Passed: a <GValue>.

an initialized <GValue> structure

instance

Passed, or left out: a foreign pointer, or a bytevector, or #f.

the instance

Method: value:set-int self v-int
Method: set-int self v-int

Set the contents of a G_TYPE_INT <GValue> to v-int.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_INT

v-int

Passed: a 32-bit integer.

integer value to be set

Method: value:set-int64 self v-int64
Method: set-int64 self v-int64

Set the contents of a G_TYPE_INT64 <GValue> to v-int64.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_INT64

v-int64

Passed: a 64-bit integer.

64bit integer value to be set

Method: value:set-interned-string self [v-string]
Method: set-interned-string self [v-string]

Set the contents of a G_TYPE_STRING <GValue> to v-string. The string is assumed to be static and interned (canonical, for example from intern-string), and is thus not duplicated when setting the <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_STRING

v-string

Passed, or left out: a string, or #f.

static string to be set

Method: value:set-long self v-long
Method: set-long self v-long

Set the contents of a G_TYPE_LONG <GValue> to v-long.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_LONG

v-long

Passed: a 64-bit integer.

long integer value to be set

Method: value:set-object self [v-object]
Method: set-object self [v-object]

Set the contents of a G_TYPE_OBJECT derived <GValue> to v-object.

value:set-object increases the reference count of v-object (the <GValue> holds a reference to v-object). If you do not wish to increase the reference count of the object (i.e. you wish to pass your current reference to the <GValue> because you no longer need it), use g_value_take_object() instead.

It is important that your <GValue> holds a reference to v-object (either its own, or one it has taken) to ensure that the object won’t be destroyed while the <GValue> still exists).

self

Passed: a <GValue>.

a valid <GValue> of G_TYPE_OBJECT derived type

v-object

Passed, or left out: a <GObject>, or #f.

object value to be set

Method: value:set-param self [param]
Method: set-param self [param]

Set the contents of a G_TYPE_PARAM <GValue> to param.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_PARAM

param

Passed, or left out: a <GParam>, or #f.

the <GParam> to be set

Method: value:set-pointer self [v-pointer]
Method: set-pointer self [v-pointer]

Set the contents of a pointer <GValue> to v-pointer.

self

Passed: a <GValue>.

a valid <GValue> of G_TYPE_POINTER

v-pointer

Passed, or left out: a foreign pointer, or a bytevector, or #f.

pointer value to be set

Method: value:set-schar self v-char
Method: set-schar self v-char

Set the contents of a G_TYPE_CHAR <GValue> to v-char.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_CHAR

v-char

Passed: an 8-bit integer, or a character.

signed 8 bit integer to be set

Method: value:set-static-boxed self [v-boxed]
Method: set-static-boxed self [v-boxed]

Set the contents of a G_TYPE_BOXED derived <GValue> to v-boxed.

The boxed value is assumed to be static, and is thus not duplicated when setting the <GValue>.

self

Passed: a <GValue>.

a valid <GValue> of G_TYPE_BOXED derived type

v-boxed

Passed, or left out: a foreign pointer, or a bytevector, or #f.

static boxed value to be set

Method: value:set-static-string self [v-string]
Method: set-static-string self [v-string]

Set the contents of a G_TYPE_STRING <GValue> to v-string. The string is assumed to be static, and is thus not duplicated when setting the <GValue>.

If the the string is a canonical string, using value:set-interned-string is more appropriate.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_STRING

v-string

Passed, or left out: a string, or #f.

static string to be set

Method: value:set-string self [v-string]
Method: set-string self [v-string]

Set the contents of a G_TYPE_STRING <GValue> to a copy of v-string.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_STRING

v-string

Passed, or left out: a string, or #f.

caller-owned string to be duplicated for the <GValue>

Method: value:set-string-take-ownership self [v-string]
Method: set-string-take-ownership self [v-string]

This is an internal function introduced mainly for C marshallers.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_STRING

v-string

Passed, or left out: a string, or #f.

duplicated unowned string to be set

Method: value:set-uchar self v-uchar
Method: set-uchar self v-uchar

Set the contents of a G_TYPE_UCHAR <GValue> to v-uchar.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_UCHAR

v-uchar

Passed: an unsigned 8-bit integer, or a character.

unsigned character value to be set

Method: value:set-uint self v-uint
Method: set-uint self v-uint

Set the contents of a G_TYPE_UINT <GValue> to v-uint.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_UINT

v-uint

Passed: an unsigned 32-bit integer.

unsigned integer value to be set

Method: value:set-uint64 self v-uint64
Method: set-uint64 self v-uint64

Set the contents of a G_TYPE_UINT64 <GValue> to v-uint64.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_UINT64

v-uint64

Passed: an unsigned 64-bit integer.

unsigned 64bit integer value to be set

Method: value:set-ulong self v-ulong
Method: set-ulong self v-ulong

Set the contents of a G_TYPE_ULONG <GValue> to v-ulong.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_ULONG

v-ulong

Passed: an unsigned 64-bit integer.

unsigned long integer value to be set

Method: value:set-variant self [variant]
Method: set-variant self [variant]

Set the contents of a variant <GValue> to variant. If the variant is floating, it is consumed.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_VARIANT

variant

Passed, or left out: a <GVariant>, or #f.

a <GVariant>, or #f

Method: value:steal-string self ⇒ %return
Method: steal-string self ⇒ %return

Steal ownership on contents of a G_TYPE_STRING <GValue>. As a result of this operation the value’s contents will be reset to #f.

The purpose of this call is to provide a way to avoid an extra copy when some object have been serialized into string through <GValue> API.

NOTE: for safety and compatibility purposes, if <GValue> contains static string, or an interned one, this function will return a copy of the string. Otherwise the transfer notation would be ambiguous.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_STRING

%return

Returned: a string, or #f.

string content of self; Should be freed with byte-array:free when no longer needed.

Method: value:take-boxed self [v-boxed]
Method: take-boxed self [v-boxed]

Sets the contents of a G_TYPE_BOXED derived <GValue> to v-boxed and takes over the ownership of the caller’s reference to v-boxed; the caller doesn’t have to unref it any more.

self

Passed: a <GValue>.

a valid <GValue> of G_TYPE_BOXED derived type

v-boxed

Passed, or left out: a foreign pointer, or a bytevector, or #f.

duplicated unowned boxed value to be set

Method: value:take-string self [v-string]
Method: take-string self [v-string]

Sets the contents of a G_TYPE_STRING <GValue> to v-string.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_STRING

v-string

Passed, or left out: a string, or #f.

string to take ownership of

Method: value:take-variant self [variant]
Method: take-variant self [variant]

Set the contents of a variant <GValue> to variant, and takes over the ownership of the caller’s reference to variant; the caller doesn’t have to unref it any more (i.e. the reference count of the variant is not increased).

If variant was floating then its floating reference is converted to a hard reference.

If you want the <GValue> to hold its own reference to variant, use value:set-variant instead.

This is an internal function introduced mainly for C marshallers.

self

Passed: a <GValue>.

a valid <GValue> of type G_TYPE_VARIANT

variant

Passed, or left out: a <GVariant>, or #f.

a <GVariant>, or #f

Method: value:transform? self dest-value ⇒ %return
Method: transform? self dest-value ⇒ %return

Tries to cast the contents of self into a type appropriate to store in dest-value.

If a transformation is not possible, dest-value is not modified.

For example, this could transform a G_TYPE_INT value into a G_TYPE_FLOAT value.

Performing transformations between value types might incur precision loss. Especially transformations into strings might reveal seemingly arbitrary results and the format of particular transformations to strings is not guaranteed over time.

self

Passed: a <GValue>.

source value

dest-value

Passed: a <GValue>.

target value

%return

Returned: a boolean.

true on success; false otherwise

Procedure: value:type-compatible? src-type dest-type ⇒ %return

Checks whether a value:copy is able to copy values of type src-type into values of type dest-type.

src-type

Passed: a class, or a GType number.

source type to be copied

dest-type

Passed: a class, or a GType number.

destination type for copying

%return

Returned: a boolean.

true if the copy is possible; false otherwise

Procedure: value:type-transformable? src-type dest-type ⇒ %return

Checks whether value:transform? is able to transform values of type src-type into values of type dest-type.

Note that for the types to be transformable, they must be compatible or a transformation function must be registered using GObject.Value.register_transform_func.

src-type

Passed: a class, or a GType number.

source type

dest-type

Passed: a class, or a GType number.

target type

%return

Returned: a boolean.

true if the transformation is possible; false otherwise

Method: value:unset self
Method: unset self

Clears the current value in self (if any) and ‘unsets’ the type.

This releases all resources associated with this <GValue>. An unset value is the same as a cleared (zero-filled) <GValue> structure set to G_VALUE_INIT.

self

Passed: a <GValue>.

an initialized <GValue> structure