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

Reply via email to