On Mar 15, 2006, at 6:46 AM, Luís Oliveira wrote:

[EMAIL PROTECTED] writes:
What is the right way to create a 2D array to pass to a c-function
that expects **arr?

In message ID <[EMAIL PROTECTED]>, Vasilis
sent some functions macros to manipulate and create arrays of arbitrary ranks: http://common-lisp.net/pipermail/cffi-devel/2005-December/ 000281.html

I was able to get this to work. I was using the wrong index variable (y instead of x) in the inner loop.

  (defun make-matrix (lisp-mat)
    "Creates a two-dimensional c array, initializes with lisp matrix"
    (let* ((x-dim (array-dimension lisp-mat 0))
           (y-dim (array-dimension lisp-mat 1))
           (c-mat (foreign-alloc :pointer :count y-dim)))
      (dotimes (y y-dim)
        (let ((cur (foreign-alloc :double :count x-dim)))
          (setf (mem-aref c-mat :pointer y) cur)
          (dotimes (x x-dim)
(setf (mem-aref cur :double x) (coerce (aref lisp-mat x y) 'double-float)))))
      c-mat))                                         ^^^

Thanks for the suggestion though, it looks like a nice generalization of the specific case I am trying to handle.

-Hazen

_______________________________________________
cffi-devel mailing list
cffi-devel@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel

Reply via email to