with-foreign-slots slots-and-options form &body body
slots-and-options := (slots &key object-type) | slots
slot-spec := slot-name | (variable-name slot-name &key copy-foreign-object)
A symbol
A symbol
A FLI structure type
A form evaluating to an instance of (or a pointer to) a FLI structure
Forms to be executed
The macro with-foreign-slots
is analogous to the Common Lisp macro with-slots
. Within body, each slot-name (or variable-name) evaluates to the result of calling foreign-slot-value on form with that slot. setf
can be used to set the foreign slot value.
If the first syntax of slots-and-options is used, then object-type is passed as the value of the :object-type
keyword argument in all the generated calls to foreign-slot-value. If the second syntax of slots-and-options is used, no object-type is passed.
Each slot-spec can either be a symbol slot-name naming a slot in the object, which will be also be used in body, or a list of variable-name, a symbol naming a slot, and a plist of options. In this case the copy-foreign-object option is passed as the value of the :copy-foreign-object
keyword argument in the generated call to foreign-slot-value. The default value of copy-foreign-object is :error
.
The with-foreign-slots
form returns the value of the last form in body.
(fli:define-c-struct abc
(a :int)
(b :int)
(c :int))
=>
(:STRUCT ABC)
(setf abc (fli:allocate-foreign-object :type 'abc))
=>
#<Pointer to type (:STRUCT ABC) = #x007F3BE0>
(fli:with-foreign-slots (a b c) abc
(setf a 6 b 7 c (* a b)))
=>
42
(fli:foreign-slot-value abc 'c)
=>
42
LispWorks Foreign Language Interface User Guide and Reference Manual - 16 Feb 2015