On Sun, Aug 16, 2009 at 5:14 PM, Tamas K Papptkpapp@gmail.com wrote:
Is there a way to make mem-aref work with CL's complex numbers? I don't need anything else from CFFI (no complex function arguments, return types, etc), just mem-aref, eg something like
(mem-aref ptr :complex-float 11)
That is doable with something like:
(defmethod translate-from-foreign (ptr (type complex-float-type)) (complex (mem-aref ptr :float 0) (mem-aref ptr :float 1)))
(setf (mem-aref ptr :complex-float 12) #C(1s0 2s0))
But that isn't. Would defining your own setter work for you?
(defun complex-float-aref (ptr index c) (let ((p (* (foreign-type-size :complex-float) index))) (setf (mem-aref p :float 0) (realpart c) (mem-aref p :float 1) (imagpart c))))
To do that with plain MEM-AREF as you wanted, I think we would need some sort of TRANSLATE-INTO-FOREIGN hook.
HTH.