Next: with-foreign-pointer-as-string, Previous: lisp-string-to-foreign, Up: Strings [Contents][Index]
var-or-vars ::= var | (var &optional octet-size-var) bindings ::= {(var-or-vars string &rest args)}*
A symbol.
A Lisp string.
A list of forms to be executed.
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.
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"