Next: , Previous: , Up: Strings   [Contents][Index]


foreign-string-to-lisp

foreign-string-to-lisp

Syntax

Function: foreign-string-to-lisp ptr &key offset count max-chars encoding ⇒ string

Arguments and Values

ptr

A pointer.

offset

An integer greater than or equal to 0. Defauls to 0.

count

Either nil (the default), or an integer greater than or equal to 0.

max-chars

An integer greater than or equal to 0. (1- array-total-size-limit), by default.

encoding

Foreign encoding. Defaults to *default-foreign-encoding*.

string

A Lisp string.

Description

The foreign-string-to-lisp function converts at most count octets from ptr into a Lisp string, using the defined encoding.

If count is nil (the default), characters are copied until max-chars is reached or a NULL character is found.

If ptr is a null pointer, returns nil.

Note that the :string type will automatically convert between Lisp strings and foreign strings.

Examples

  CFFI> (foreign-funcall "getenv" :string "HOME" :pointer)
  ⇒ #<FOREIGN-ADDRESS #xBFFFFFD5>
  CFFI> (foreign-string-to-lisp *)
  ⇒ "/Users/luis"

See Also

lisp-string-to-foreign
foreign-string-alloc