How do I convert C++ 2 dimensional array to Common Lisp/CFFI
Posted: Mon Mar 10, 2014 9:21 am
Here is what I'm trying to convert to Lisp with CFFI
I was told by a CFFI developer that the only way to do it was with this undocumented CFFI function
The thing is he didn't tell me how and I think it would be better if I heard how to use it from others mouth other than piecing together a hack that might break in code I distribute. So if anyone could throw me a quick how to...I'd be forever grateful=) If this breaks the rules I apologize but I do like to be safe whenever possible. I will edit my code with attempts if neccessary though.
Code: Select all
float trainingData[4][2] = { {501, 10}, {255, 10}, {501, 255}, {10, 501} };
Code: Select all
(defun foreign-array-alloc (array array-type)
"Allocate a foreign array containing the elements of lisp array.
The foreign array must be freed with foreign-array-free."
(check-type array array)
(let* ((type (follow-typedefs (parse-type array-type)))
(ptr (foreign-alloc (element-type type)
:count (reduce #'* (dimensions type)))))
(lisp-array-to-foreign array ptr array-type)
ptr))