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

:struct FLI Type Descriptor

Summary

Converts between a FLI structure and a C struct.

Package

keyword

Syntax

:struct &rest slots

slots ::= {symbol | (symbol slot-type)}*

slot-type ::= type | (:bit-field integer-type size)

Arguments
slots
A sequence of one or more slots making up the structure.
symbol
A symbol naming the slot.
type
The slot type. If no type is given it defaults to an :int.
integer-type
An integer type. Only :int, (:unsigned :int) and (:signed :int) are guaranteed to work on all platforms.
size
An integer specifying a number of bits for the field.
Description

The FLI type :struct is an aggregate type, and converts between a FLI structure and a C struct type. The FLI structure consists of a collection of one or more slots. Each slot has a name symbol and a type type. A structure can also contain bit fields, which are integers of type integer-type with size bits.

The foreign-slot-names, foreign-slot-type, and foreign-slot-value functions can be used to access and change the slots of the structure. The convenience FLI function define-c-struct is provided to simplify the definition of structures.

Examples

In the following example a structure for passing coordinates to Windows functions is defined.

(fli:define-c-struct tagPOINT (x :long) (y :long))

An instance of the structure is allocated and bound to the Lisp variable place.

(setq place 
      (fli:allocate-foreign-object :type 'tagPOINT))

Finally, the x slot of place is set to be 4 using fli:foreign-slot-value.

(setf (fli:foreign-slot-value place 'x) 4)
See also

define-c-struct
foreign-slot-names
foreign-slot-offset
foreign-slot-pointer
foreign-slot-type
foreign-slot-value
2.2.3 Structures and unions


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