How do i write a cffi:translate-into foreign defmethod?
Posted: Wed Oct 02, 2013 2:32 am
ok I tried this translate-from-foreign method and it did work i have these defined in my structs.lisp file in my library which loads first before all my other dependencies
and my opencv wrappers for CvGetSize and cvCreateImage, get-size and create-image, are defined like this
here is the definition of size->int64
it converts get-size output which is a structure here:
into 64-bit integer, which CFFI can handle (at least on some platforms)
but i love the idea of the translate-foreign defmethod's
so i was wondering if you can show my how to make the translate-into-foreign version of the below from method this would really make my library awesome
I was going to try stuff and add it but for the get-size output structure, it isnt a plist so not really sure what to put there for the
part, for the
part, i was hoping to find another method other than the size->64 function because that was made 2 years ago when cl-opencv https://github.com/ryepup/cl-opencv first came out and i would like to make an even better wrapper than that...i've already taken cl-opencv added 100 new function 5000 lines of code samples and documentation and a new structs.lisp file so i would love if someone could help me with all the latest cffi tools so i could do something else than int64...plus the if i have a funtion to wrap where the int64 thing wouldnt work ill be ready
Code: Select all
(cffi:defcstruct (cv-size :class cv-size-type)
(width :int)
(height :int))
Code: Select all
(defmethod cffi:translate-from-foreign (p (type cv-size-type))
(let ((plist (call-next-method)))
(make-size :width (getf plist 'width)
:height (getf plist 'height))))
Code: Select all
;; CvSize cvGetSize(const CvArr* arr)
(cffi:defcfun ("cvGetSize" get-size) (:struct cv-size)
(arr cv-arr))
Code: Select all
;; IplImage* cvCreateImage(CvSize size, int depth, int channels)
(cffi:defcfun ("cvCreateImage" %create-image) ipl-image
(size :int64)
(depth :int)
(channels :int))
Code: Select all
(defun create-image (size depth channels)
"Create an image with dimensions given by SIZE, DEPTH bits per
channel, and CHANNELS number of channels."
(let ((nsize (size->int64 size)))
(%create-image nsize depth channels)))
Code: Select all
(DEFUN SIZE->INT64 (S) (+ (SIZE-WIDTH S) (ASH (SIZE-HEIGHT S) 32)))
Code: Select all
#S(SIZE :WIDTH 640 :HEIGHT 480)
but i love the idea of the translate-foreign defmethod's
so i was wondering if you can show my how to make the translate-into-foreign version of the below from method this would really make my library awesome
Code: Select all
(defmethod cffi:translate-from-foreign (p (type cv-size-type))
(let ((plist (call-next-method)))
(make-size :width (getf plist 'width)
:height (getf plist 'height))))
Code: Select all
(let ((plist (call-next-method)))
Code: Select all
(make-size :width (getf plist 'width)
:height (getf plist 'height))))