Next: , Previous: convert-from-foreign, Up: Foreign Types


convert-to-foreign

Syntax

— Function: convert-to-foreign value type ⇒ foreign-value, alloc-params

Arguments and Values

value
The Lisp object to be translated to a foreign object.
type
A CFFI type specifier.
foreign-value
The primitive C value, ready to be passed to a primitive foreign function.
alloc-params
Something of a translation state; you must pass it to free-converted-object along with the foreign value for that to work.

Description

This is an external interface to the type translation facility. In the implementation, all foreign functions are ultimately defined as type translation wrappers around primitive foreign function invocations.

This function is available mostly for inspection of the type translation process, and possibly optimization of special cases of your foreign function calls.

Its behavior is better described under translate-to-foreign's documentation.

Examples

  CFFI-USER> (convert-to-foreign t :boolean)
  => 1
  => (NIL)
  CFFI-USER> (convert-to-foreign "hello, world" :string)
  => #<FOREIGN-ADDRESS #x097C5F80>
  => (T)
  CFFI-USER> (code-char (mem-aref * :char 5))
  => #\,

See Also

convert-from-foreign
free-converted-object
translate-to-foreign