Next: , Previous: , Up: Foreign Functions   [Contents][Index]


65.3 Examining and Modifying Foreign Objects

In this section we give a quick overview of what else can be done with foreign objects or foreign function definitions.

Function: ffi-object-p fo

Return non-nil if fo is an FFI object, nil otherwise.

Function: ffi-object-type fo

Return fo’s type.

Function: ffi-set-object-type fo type

Cast fo to type type and reassign the cast value.

Function: ffi-object-size fo

Return the size of the allocated space of fo.

Function: ffi-set-storage-size fo size

Set the size of the allocated space of fo to size.

Function: ffi-address-of fo

Return the FFI object that stores address of given FFI object fo.

This is the equivalent of the ‘&’ operator in C.

Function: ffi-deref fo-pointer

Return the data fo-pointer points to.

This is the equivalent of the ‘*’ operator in C.

Function: ffi-null-p fo

Return non-nil if fo is a null pointer, nil otherwise. Non-nil may be returned only for pointer types or the type ‘c-string’.

Function: ffi-null-pointer

Return the FFI object that represents a null pointer.

This is the equivalent of ‘NULL’ in C.

For foreign arrays, unions and structures, there are accessor functions to modify or fetch portions in the foreign object:

Function: ffi-aref farray idx

Return the element of farray at index idx. The slot enumeration starts at 0.

Function: ffi-aset farray idx value

Store the element value in farray at index idx. The slot enumeration starts at 0.

Function: ffi-slot-offset type slot

Return the offset of slot in type. slot can be either a valid (named) slot in type or nil. If slot is nil return the size of the structure.

(define-ffi-type mystruct
  (struct foo
   (bar int)
   (hey char)
   (baz c-string)))
(ffi-slot-offset 'mystruct 'baz)
     ⇒ 8

Next: , Previous: , Up: Foreign Functions   [Contents][Index]