Package: gobject

Function gobject:object-data

Lambda List

gobject:object-data (object key)

Syntax

(g:object-data object key) => data
(setf (g:object-data object key) data)

Arguments

object -- a g:object instance containing the associations
key -- a string with the name of the key
data -- any Lisp object as data to associate with that key

Details

Each object carries around a table of associations from strings to pointers. The g:object-data function gets a named field from the objects table of associations. The (setf g:object-data) function sets an association. If the object already had an association with that name, the old association will be destroyed.

Examples

(defvar item (make-instance 'g:menu-item)) => ITEM
;; Set an integer
(setf (g:object-data item "prop") 123) => 123
(g:object-data item "prop") => 123
;; Set a Lisp list
(setf (g:object-data item "prop") '(a b c)) => (A B C)
(g:object-data item "prop") => (A B C)
;; Set a GObject
(setf (g:object-data item "prop") (make-instance 'g:menu-item))
=> #<GIO:MENU-ITEM {1001AAA263}>
(g:object-data item "prop")
=> #<GIO:MENU-ITEM {1001AAA263}>
;; Clear the association
(setf (g:object-data item "prop") nil) => nil
(g:object-data item "prop") => nil    
 

See also

2024-12-14