Next Previous Up Top Contents Index

5 Function and Macro Reference

foreign-aref

Function

Summary

Accesses and returns the value at a specified point in an array.
Package

fli

Signature

foreign-aref array &rest subscripts => pointer

Arguments

array

An FLI array or a pointer to an FLI array.

subscripts

A list of valid array indices for array.

Values

pointer

A pointer containing the address of the array element being accessed.

Description

The functionforeign-aref accesses a specified element in an array and returns its value if the element is an immediate type. If it is an aggregate type, such as a:struct,:union, or:c-array, the functionforeign-aref returns a copy of the element. In this case, the copy must be de-allocated after use to reclaim the memory allocated for it byforeign-aref.
The value of an element in an array can be changed usingsetf andforeign-aref. See the examples section for an example of this.
Example

In the first example, a 3 by 3 integer array is created, andforeign-aref is used withsetf to set all the element equal to 42.
(setq array1 (fli:allocate-foreign-object
              :type '(:c-array :int 3 3)))

(dotimes (x 3) (dotimes (y 3) (setf (fli:foreign-aref array1 x y) 42)))

Next,foreign-aref is used to dereference the value at position2 2 inarray1. Remember that the count for the indices of an array start at0.
(fli:foreign-aref array1 2 2)

In the following example, an array of arrays of integers is created. When an element is dereferenced, a copy of an array of integers is returned.
(setq array2 (fli:allocate-foreign-object
              :type '(:c-array (:c-array :int 3) 3))

(fli:foreign-aref array2 2)

The array returned can be bound to the variablearray3, and accessed usingforeign-aref again. This time an integer is returned.
(setq array3 *)

(fli:foreign-aref array3 1)

See Also

foreign-array-dimensions
foreign-array-element-type
foreign-array-pointer

LispWorks Foreign Language Interface - 12 Oct 1998

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker