Returns a pointer to a specified slot of an object.
fli
foreign-slot-pointer object slot-name &key type object-type => pointer
| object⇩ |
A foreign object, or a pointer to a foreign object. |
| slot-name⇩ |
A symbol or a list of symbols identifying the slot to be accessed, as described for foreign-slot-value. |
| type⇩ |
A foreign type. |
| object-type⇩ |
The FLI structure type that contains slot-name. |
| pointer |
A pointer to the slot identified by slot-name. |
The function foreign-slot-pointer returns a foreign pointer to the slot slot-name in object.
If type is supplied, then foreign-slot-pointer assumes that the slot contains an object of that type, overriding the type in the structure definition.
If object-type is supplied then foreign-slot-pointer assumes that object is of the that type and the compiler might be able to optimize the access to the slot. If object-type is not supplied, then the object type is determined dynamically from object.
In the following example a structure type called compass is defined. An instance of the structure is allocated using allocate-foreign-object, pointed to by point1. Then foreign-slot-pointer is used to get a pointer, called point2, to the second slot of the foreign object.
(fli:define-c-struct compass
(west :int)
(east :int))
(setq point1 (fli:allocate-foreign-object :type
'compass))
(setq point2 (fli:foreign-slot-pointer point1 'east
:type :int))
The :type keyword can be used to return the value stored in the slot as a different type, providing the type is compatible. In the next example, point3 is set to be a pointer to the same address as point2, but it expects the value stored there to be a boolean.
(setq point3 (fli:foreign-slot-pointer point1 'east
:type '(:boolean :int)))
Using dereference the value can be set as an integer using point2 and read as a boolean using point3.
(setf (fli:dereference point2) 0) (fli:dereference point3) (setf (fli:dereference point2) 1) (fli:dereference point3)
2.2.3 Structures and unions
decf-pointer
incf-pointer
make-pointer
foreign-slot-value
foreign-slot-offset
Foreign Language Interface User Guide and Reference Manual - 18 Feb 2025 15:36:32