Package: gobject

CStruct gobject:value

Details

The g:value structure is a variable container that consists of a type identifier and a specific value of that type. The type identifier within a g:value instance determines the type of the associated value. To create an undefined g:value instance, simply create a zero-filled g:value instance. To initialize the g:value instance, use the g:value-init function. A g:value instance cannot be used until it is initialized.

Examples

These examples demonstrate some of the features.
(defun example-gvalue ()
  ;; Declare two variables of type g:value
  (gobject:with-values (value1 value2)
    ;; Initialization, setting and reading a value of type g:value
    (g:value-set value1 "string" "gchararray")
    (format t "value1 = ~a~%" (g:value-get value1))
    (format t "gtype  = ~a~%" (g:value-type value1))
    (format t "name   = ~a~%~%" (g:value-type-name value1))

;; The same for the second value (g:value-init value2 "gchararray") (setf (g:value-get value2) "a second string") (format t "value2 = ~a~%" (g:value-get value2)) (format t "gtype = ~a~%" (g:value-type value2)) (format t "name = ~a~%~%" (g:value-type-name value2))

;; Reuse value1 for an integer (g:value-unset value1) (g:value-set value1 42 "gint" ) (format t "value1 = ~a~%" (g:value-get value1)) (format t "gtype = ~a~%" (g:value-type value1)) (format t "name = ~a~%~%" (g:value-type-name value1))

;; Some test functions (assert (g:value-holds value1 "gint")) (format t "value holds integer is ~a~%" (g:value-holds value1 "gint")) (format t "value is integer ~a~%~%" (g:type-is-value "gint"))))
 

See also

2024-12-21