[cffi-devel] help writing macro for with-foreign-slots aka help with the ULTIMATE derefrencing macro
Joeish W
joeish80829 at yahoo.com
Fri Nov 1 07:45:57 UTC 2013
I'm trying to write an all purpose dereferencing macro...ive done pretty good so far I have
(defmacro -> (var1 var2 var3 &optional var4 var5)
;; if var4 and var5 arent supplied give value of struct member
(if (not (and var4 var5)) `(cffi:with-foreign-slots ((,var3)
,var2 (:struct ,var1)) (list ,var3))
;; if var4 and var5 are supplied give value of nested struct member
(if (and var4 var5)
`(cffi:with-foreign-slots ((,var3)
,var2 (:struct ,var1))
(cffi:with-foreign-slots ((,var5)
,var3 (:struct ,var4)) ,var5) ))))
the roi struct member of ipl-image is defined as this
(roi (:pointer (:struct ipl-roi)))
;this gets the roi slot value of ipl-image correctly
CL-OPENCV> (-> ipl-image a roi )
(#.(SB-SYS:INT-SAP #X7FFFDC000E80))
;this gets the nested struct member "width" of ipl-roi which is just a an :int correctly
CL-OPENCV> (-> ipl-image a roi ipl-roi width)
100
both work correctly but i could use help getting rid of some of the typing to access these members
in this (-> ipl-image a roi ipl-roi width) i have to type "ipl-image"(the name of the struct) "a"( the name of the variable i'm dereferencing) "roi" (the name of the ipl-image struct member) "ipl-roi" (the foreign-type of roi) and "width" (the ipl-roi struct member) . if there was a way i can get the foreign type of the roi struct member like i can call foreign-slot-names to get all the slot names of a struct i could not have to use the ipl-roi here (-> ipl-image a roi ipl-roi width) but i looked in the manual and nothing....I couldnt think of any other way to shorten this (-> ipl-image a roi ipl-roi width) and make it a little closer to c so if someone could give me advice, or better yet their awesome dereferencing macro=), i named this post so everyone....including me=) would have access to this great information
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20131101/7a65ad9f/attachment.html>
More information about the cffi-devel
mailing list