Problems with nested structs and the newer cffi
Chris Bagley
chris.bagley at gmail.com
Thu Apr 25 08:33:43 UTC 2013
I ran into similar issues to Willem and have taken to using the following
macro:
(defmacro with-foreign-slots* ((vars ptr type) &body body)
"Create local symbol macros for each var in VARS to reference
foreign slots in PTR of TYPE. Similar to WITH-SLOTS.
Each var can be of the form: slot-name - in which case slot-name will
be bound to the value of the slot or: (:pointer slot-name) - in which
case slot-name will be bound to the pointer to that slot."
(let ((ptr-var (gensym "PTR")))
`(let ((,ptr-var ,ptr))
(symbol-macrolet
,(loop :for var :in vars :collect
(if (listp var)
(if (eq (first var) :pointer)
`(,(second var) (foreign-slot-pointer
,ptr-var ',type ',(second var)))
(error "Malformed var names must be:~%name~% -or-
~%(:pointer name)"))
`(,var (foreign-slot-value
,ptr-var ',type ',var))))
, at body))))
This, for me, balances the needs quite nicely and feels in line with the
style of cffi. Thoughts or modifications?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20130425/3c4802a9/attachment.html>
More information about the cffi-devel
mailing list