+(define-foreign-type fixed-array ()
+ ((element-type :reader fixed-array-element-type :initarg :element-type :initform (error "Element type must be specified"))
+ (array-size :reader fixed-array-array-size :initarg :array-size :initform (error "Array size must be specified")))
+ (:actual-type :pointer)
+ (:documentation
+ "CFFI foreign type for an array of a fixed length. Slot @code{element-type}@see-slot{fixed-array-element-type} specifies the type of elements and slot @code{array-size}@see-slot{fixed-array-array-size} specifies the size of array (in elements)."))
+
+(define-parse-method fixed-array (element-type array-size)
+ (make-instance 'fixed-array :element-type element-type :array-size array-size))
+
+(defmethod translate-from-foreign (ptr (type fixed-array))
+ (when (not (null-pointer-p ptr))
+ (let ((result (make-array (fixed-array-array-size type)))
+ (el-type (fixed-array-element-type type)))
+ (loop
+ for i from 0 below (fixed-array-array-size type)
+ do (setf (aref result i) (mem-aref ptr el-type i)))
+ result)))
+