Next Previous Up Top Contents Index

4 Advanced Uses of the FLI

4.2 Defining new types

The FLI provides thefli:define-foreign-type macro for defining new FLI types, using the basic FLI types that you have seen in Chapter 2. 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 calledodd-array, and takes an FLI type and a sequence of numbers as its arguments. When trying to allocate anodd-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, page 54.


LispWorks Foreign Language Interface - 12 Oct 1998

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker