Next Previous Up Top Contents Index

6 Type Reference

:one-of

FLI type descriptor

Summary

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

fli

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)))

Ifthing is set to be 100 usingdereference, 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, ifthing 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 ofthing, and therefore the first element in the list of:one-of is used.
(fli:dereference thing)

See Also

:union

LispWorks Foreign Language Interface - 12 Oct 1998

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker