FLI type descriptor
fli
: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.
: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. :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)))
wrap, 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)
wrap 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)