[cffi-devel] Help with defcallback....shorter version

Joeish W joeish80829 at yahoo.com
Mon Nov 11 05:00:00 UTC 2013


What am i doing wrong in my conversion of this c code to lisp
I think the issue is with my callback function but not 100% when i run the c code and print
with these 2 lines(from c callback):

cout << "a = " << "(" << "" << "," << _a << ")" << endl ;
          cout << "b = " << "(" << "" << "," << _b << ")" << endl;

 i get 53 elements printed not icluding the other printf output
and  in the lisp code i converterd 

when i print with this line(from lisp defcallback):

(format t "~%x~a~%b~a" _a _b)

 in the defcallback  i get 114 elements

Hoping someone can look at my code and tell me if my coding is off
the -> is a macro for with-foreign-slots (and if not a pointer just a getf for a plist)

;;;;;;;;C CODE;;;;;;;;;;;;;;;;;;;

      static int cmp_func( const void* _a, const void* _b, void* userdata )
      {
          CvPoint* a = (CvPoint*)_a;
          CvPoint* b = (CvPoint*)_b;
          cout << "a = " << "(" << "" << "," << _a << ")" << endl ;
          cout << "b = " << "(" << "" << "," << _b << ")" << endl;
          int y_diff = a->y - b->y;
          int x_diff = a->x - b->x;
          return y_diff ? y_diff : x_diff;
      }


 
;;;;;;;;;;;;;;;;;;;;;;;;;LISP CODE;;;;;;;;;;;;;;;;;;;;
(defcallback cmp-func :void  ((_a :pointer) (_b :pointer) (user-data :pointer) (a :int) (b :int) (y-diff :int) (x-diff :int))
  (format t "~%x~a~%b~a" _a _b)
  (setf a (mem-aref _a '(:struct cv-point)))
  (setf b (mem-aref _b '(:struct cv-point)))
                    ;(format t "~%a~a~%b~a" a b)
  (setf y-diff (- (-> cv-point a y) (-> cv-point b y)))
  (setf x-diff (- (-> cv-point a x) (-> cv-point b x)))
  (if y-diff y-diff x-diff))


using callback with (callback cmp-func) in the OpenCV function cvSeqSort ....here is documentation for cvSeqSort
http://docs.opencv.org/modules/core/doc/dynamic_structures.html?highlight=cvseqs#seqsort

the code the wrapper is used in is posted in the "Help with defcallback"  post below this one
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20131110/097f159f/attachment.html>


More information about the cffi-devel mailing list