All Manuals > LispWorks Foreign Language Interface User Guide and Reference Manual > 7 Function, Macro and Variable Reference

NextPrevUpTopContentsIndex

with-foreign-slots

Macro
Summary

Allows convenient access to the slots of a foreign structure.

Package

fli

Signature

with-foreign-slots slots-and-options form &body body

slots-and-options := (slots &key object-type) | slots

slots := (slot-spec*)

slot-spec := slot-name | (variable-name slot-name &key copy-foreign-object)

Arguments

variable-name

A symbol

slot-name

A symbol

object-type

A FLI structure type

form

A form evaluating to an instance of (or a pointer to) a FLI structure

body

Forms to be executed

Description

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.

Example
(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
See also

Structures and unions
foreign-slot-value


LispWorks Foreign Language Interface User Guide and Reference Manual - 29 Sep 2017

NextPrevUpTopContentsIndex