Next: , Previous: lisp-string-to-foreign, Up: Strings


with-foreign-string

Syntax

— Macro: with-foreign-string (var lisp-string-or-ub8-array) &body body

Arguments and Values

var
A symbol.
lisp-string-or-ub8-array
A Lisp string or a Lisp array with element type (unsigned-byte 8).
body
A list of forms to be executed.

Description

The with-foreign-string macro will bind var to a newly allocated foreign string containing lisp-string-or-ub8-array.

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

foreign-string-alloc
with-foreign-pointer-as-string