Next: foreign-type-alignment, Previous: foreign-slot-pointer, Up: Foreign Types [Contents][Index]
A pointer to a structure.
A foreign structure type.
A symbol naming a slot in the structure type.
The object contained in the slot specified by slot-name.
For simple slots, foreign-slot-value
returns the value of the
object, such as a Lisp integer or pointer. In C, this would be
expressed as ptr->slot
.
For aggregate slots, a pointer inside the structure to the beginning
of the slot’s data is returned. In C, this would be expressed as
&ptr->slot
. This pointer and the memory it points to have the
same extent as ptr.
There are compiler macros for foreign-slot-value
and its
setf
expansion that open code the memory access when
type and slot-names are constant at compile-time.
(defcstruct point "Pointer structure." (x :int) (y :int)) CFFI> (with-foreign-object (ptr '(:struct point)) ;; Initialize the slots (setf (foreign-slot-value ptr '(:struct point) 'x) 42 (foreign-slot-value ptr '(:struct point) 'y) 42) ;; Return a list with the coordinates (with-foreign-slots ((x y) ptr (:struct point)) (list x y))) ⇒ (42 42)
defcstruct
foreign-slot-names
foreign-slot-offset
foreign-slot-pointer
with-foreign-slots