Package: cffi

Macro with-foreign-string

Lambda List

with-foreign-string ((var-or-vars lisp-string &rest args) &body body)

Syntax

var-or-vars ::= var | (var &optional octet-size-var)
bindings ::= {(var-or-vars string &rest args)}*

Arguments

var, byte-size-var -- A symbol.
string -- A Lisp string.
body -- A list of forms to be executed.

Details

The with-foreign-string macro will bind var to a newly allocated foreign string containing string. args is passed to the underlying foreign-string-alloc call.

If octet-size-var is provided, it will be bound the length of foreign string in octets including the null terminator.

Examples

  CFFI> (with-foreign-string (foo "12345")
          (foreign-funcall "strlen" :pointer foo :int))
  => 5

CFFI> (let ((array (coerce #(84 117 114 97 110 103 97) '(array (unsigned-byte 8))))) (with-foreign-string (foreign-string array) (foreign-string-to-lisp foreign-string))) => "Turanga"
 

See also