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

NextPrevUpTopContentsIndex

:one-of

FLI type descriptor
Summary

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

Syntax

:one-of &rest types

Arguments

types

A list of types sharing the same underlying type.

Description

The FLI :one-of type is used to allocate an object which can be one of a number of 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.

Example

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


LispWorks Foreign Language Interface User Guide and Reference Manual - 7 Dec 2011

NextPrevUpTopContentsIndex