The define-foreign-type
anddefine-foreign-converter
types allow the definition of parameterized types. For example, assume you want to create a foreign type that matches the Lisp typeunsigned-byte
when supplied with an argument of one of 8, 16, or 32. The following code achieves this:
(fli:define-foreign-type unsigned-byte (&optional (bitsize '*)) (case bitsize (8 '(:unsigned :byte)) (16 '(:unsigned :short)) (32 '(:unsigned :int)) (otherwise (error "Illegal foreign type (~s ~s)" 'unsigned-byte bitsize))))
This defines the new foreign typeunsigned-byte
that can be used anywhere within the FLI as one of
(unsigned-byte 8)
(unsigned-byte 16)
(unsigned-byte 32)
Specifying anything else returns an error.