All Manuals > Foreign Language Interface User Guide and Reference Manual > 8 Type Reference

:one-of FLI Type Descriptor

Summary

Converts between Lisp and C types of the same underlying type.

Package

keyword

Syntax

:one-of &rest types

Arguments
types
A list of types sharing the same underlying type.
Description

The FLI type :one-of is used to allocate an object which can be one of a number of types specified by types. The types must have the same underlying structure, which means they must have the same size and must be referenced in the same manner. The FLI :one-of type is useful when a foreign function returns a value whose underlying type is known, but whose exact type is not.

Examples

In the following example, a :one-of type is allocated.

(setq thing (fli:allocate-foreign-object
             :type '(:one-of :ptr :int :unsigned)))

If thing is set to be 100 using dereference, it is taken to be an object of type :int, as this is the first element in the sequence of types defined by :one-of which matches the type of the number 100.

(setf (fli:dereference thing) 100)

However, if thing is now dereferenced, it is returned as a pointer to the address 100 (Or hex address 64), as there is no method for determining the type of thing, and therefore the first element in the list of :one-of is used.

(fli:dereference thing)
See also

:union


Foreign Language Interface User Guide and Reference Manual - 01 Dec 2021 19:34:59