Help with defcallback....shorter version

Discussion of Common Lisp
Post Reply
joeish80829
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Help with defcallback....shorter version

Post by joeish80829 » Sun Nov 10, 2013 10:03 pm

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):

Code: Select all

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):

Code: Select all

(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)

Code: Select all

;;;;;;;;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;
      }

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;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 ... qs#seqsort

the code the wrapper is used in is posted in the "Help with defcallback" post below this one

Post Reply