Package: cffi

Macro with-foreign-object

Lambda List

with-foreign-object ((var type &optional count) &body body)


var -- A symbol.
type -- A foreign type, evaluated.
count -- An integer.


The macros with-foreign-object and with-foreign-objects bind var to a pointer to count newly allocated objects of type type during body. The buffer has dynamic extent and may be stack allocated if supported by the host Lisp.


  CFFI> (with-foreign-object (array :int 10)
          (dotimes (i 10)
            (setf (mem-aref array :int i) (random 100)))
          (loop for i below 10
                collect (mem-aref array :int i)))
  => (22 7 22 52 69 1 46 93 90 65)  

See also