NextPrevUpTopContentsIndex

4.3 Defining new types

The FLI provides the define-foreign-type macro for defining new FLI types, using the basic FLI types that you have seen in FLI Types. The next example shows you how to define a new array type that only takes an odd number of dimensions.

(fli:define-foreign-type odd-array (element &rest dimensions)
   (unless (oddp (length dimensions))
     (error "Can't define an odd array with even dimensions - try 
adding an extra dimension!"))
               `(:c-array ,element ,@dimensions))

The new array type is called odd-array , and takes a FLI type and a sequence of numbers as its arguments. When trying to allocate an odd-array , if there are an even number of items in the sequence then an error is raised. If there are an odd number of items then an instance of the array is allocated. The next command raises an error, because a 2 by 3 array has an even dimension.

(fli:allocate-foreign-object :type '(odd-array :int 2 3))

However, adding an extra dimension and defining a 2 by 3 by 4 array works:

(fli:allocate-foreign-object :type '(odd-array :int 2 3 4))

For more information on defining types see define-foreign-type.


LispWorks Foreign Language Interface User Guide and Reference Manual - 14 Mar 2008

NextPrevUpTopContentsIndex