Next Previous Up Top Contents Index

6 Type Reference


FLI type descriptor


Allows the specification of automatic conversion functions between Lisp and an instance of an FLI type.



:wrapper fli-type &key lisp-to-fli fli-to-lisp



The underlying type to wrap.


Code specifying how to convert between Lisp and the FLI.


Code specifying how to convert between the FLI and Lisp.


The FLI:wrapper type allows for an extra level of conversion between Lisp and a foreign language through the FLI. With the:wrapper type you can specify conversion functions from and to an instance of another type. Whenever data is passed to the object, or received from the object it is passed through the conversion function. See below for an example of a use of:wrapper to pass values to an:int as strings, and to receive them back as strings when the pointer to the:int is dereferenced.

In the following example an:int is allocated with a wrapper to allow the:int to be accessed as a string.
(setq wrap (fli:allocate-foreign-object
            :type '(:wrapper :int 
                    :lisp-to-foreign read-from-string
                    :foreign-to-lisp prin1-to-string)))

The object pointed to bywrap, although consisting of an underlying:int, is set withdereference by passing a string, which is automatically converted using the Lisp functionread-from-string. Similarly, whenwrap is dereferenced, the value stored as an:int is converted usingprin1-to-string to a Lisp string, which is the returned. The following two commands demonstrate this.
(setf (fli:dereference wrap) "#x100")

(fli:dereference wrap)

The first command sets the value stored atwrap to be 256 (100 in hex), by passing a string to it. The second command dereferences the value atwrap, but returns it as a string. The pointerwrap can be coerced to return the value as an actual:int as follows:
(fli:dereference wrap :type :int)

LispWorks Foreign Language Interface - 12 Oct 1998

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker