Previous: translate-into-foreign-memory, Up: Foreign Types [Contents][Index]
A list with each element a symbol, or list of length two with the
first element :pointer
and the second a symbol.
A foreign pointer to a structure.
A structure type.
A list of forms to be executed.
The with-foreign-slots
macro creates local symbol macros for each
var in vars to reference foreign slots in ptr of type.
If the var is a list starting with :pointer
, it will bind the
pointer to the slot (rather than the value). It is similar to Common
Lisp’s with-slots
macro.
(defcstruct tm (sec :int) (min :int) (hour :int) (mday :int) (mon :int) (year :int) (wday :int) (yday :int) (isdst :boolean) (zone :string) (gmtoff :long)) CFFI> (with-foreign-object (time :int) (setf (mem-ref time :int) (foreign-funcall "time" :pointer (null-pointer) :int)) (foreign-funcall "gmtime" :pointer time (:pointer (:struct tm)))) ⇒ #<A Mac Pointer #x102A30> CFFI> (with-foreign-slots ((sec min hour mday mon year) * (:struct tm)) (format nil "~A:~A:~A, ~A/~A/~A" hour min sec (+ 1900 year) mon mday)) ⇒ "7:22:47, 2005/8/2"