Defines a new FLI type specifier.
fli
define-foreign-type name-and-options lambda-list &body forms => name
name-and-options ::= name | (name option*)
option ::= (:foreign-name foreign-name)
lambda-list⇩ |
A lambda list which is the argument list of the new FLI type. |
forms⇩ |
One or more Lisp forms which provide a definition of the new type. |
name⇩ |
A symbol naming the new FLI type. |
foreign-name⇩ |
A string specifying the foreign name of the type. |
name |
The name of the new FLI type. |
The macro define-foreign-type
defines a new FLI type called name, with optional foreign name foreign-name.
When name is used as a foreign type, forms are evaluated as an implicit progn with the variables in lambda-list bound to the arguments of the foreign type. The value returned by forms is used as the definition of the foreign type. This is similar to how deftype works for Lisp type specifiers.
foreign-name, specifying the foreign name, is supported only for documentation purposes.
In the following example an integer array type specifier is defined. Note that the type takes a list as its argument, and uses this to determine the size of the array.
(fli:define-foreign-type :int-array (dimensions) `(:c-array :int ,@dimensions))
(setq number-array (fli:allocate-foreign-object :type '(:int-array (2 2))))
In the next example a boolean type, called :bool
, with the same size as an integer is defined.
(fli:define-foreign-type :bool () `(:boolean :int))
(fli:size-of :bool)
define-c-typedef
define-foreign-converter
define-foreign-forward-reference-type
foreign-type-equal-p
2 FLI Types
5.4 Defining new types
Foreign Language Interface User Guide and Reference Manual - 01 Dec 2021 19:34:58