<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
-<!ENTITY % myents SYSTEM "entities.xml">
+<!ENTITY % myents SYSTEM "entities.inc">
%myents;
]>
</refsect1>
<refsect1>
<title>Examples</title>
- <programlisting>
+ <screen>
(def-struct ab (a :int) (b :double))
(allocate-foreign-object 'ab)
=> #<ptr>
- </programlisting>
+ </screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
</refsect1>
<refsect1>
<title>Examples</title>
- <programlisting>
+ <screen>
(defun gethostname2 ()
"Returns the hostname"
(uffi:with-foreign-object (name '(:array :unsigned-char 256))
(if (zerop (c-gethostname (uffi:char-array-to-pointer name) 256))
(uffi:convert-from-foreign-string name)
(error "gethostname() failed."))))
- </programlisting>
+ </screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<refsect1>
<title>Examples</title>
<para>
-<programlisting>
+<screen>
(size-of-foreign-object :unsigned-byte)
=> 1
(size-of-foreign-object 'my-100-byte-vector-type)
=> 100
-</programlisting>
+</screen>
</para>
</refsect1>
<refsect1>
<refsect1>
<title>Examples</title>
<para>
-<programlisting>
+<screen>
(let ((intp (allocate-foreign-object :int)))
(setf (deref-pointer intp :int) 10)
(prog1
(deref-pointer intp :int)
(free-foreign-object intp)))
=> 10
-</programlisting>
+</screen>
</para>
</refsect1>
<refsect1>
<refsect1>
<title>Examples</title>
<para>
-<programlisting>
+<screen>
(let ((fs (convert-to-foreign-string "a")))
(prog1
(ensure-char-character (deref-pointer fs :char))
(free-foreign-object fs)))
=> #\a
-</programlisting>
+</screen>
</para>
</refsect1>
<refsect1>
<refsect1>
<title>Examples</title>
<para>
-<programlisting>
+<screen>
(let ((fs (convert-to-foreign-string "a")))
(prog1
(ensure-char-integer (deref-pointer fs :char))
(free-foreign-object fs)))
=> 96
-</programlisting>
+</screen>
</para>
</refsect1>
<refsect1>
<refsect1>
<title>Arguments and Values</title>
<variablelist>
+ <varlistentry>
+ <term><parameter>binding-name</parameter></term>
+ <listitem>
+ <para>A symbol which will be bound to the casted object.
+ </para>
+ </listitem>
+ </varlistentry>
<varlistentry>
<term><parameter>ptr</parameter></term>
<listitem>
<refsect1>
<title>Description</title>
<para>
- Executes BODY with POINTER cast to be a pointer to type TYPE. If
- BINDING-NAME is provided the cast pointer will be bound to this
- name during the execution of BODY. If BINDING-NAME is not provided
- POINTER must be a name bound to the pointer which should be
- cast. This name will be bound to the cast pointer during the
- execution of BODY.
+ Executes BODY with POINTER cast to be a pointer to type TYPE.
+ BINDING-NAME is will be bound to this value during the execution of
+ BODY.
This is a no-op in AllegroCL but will wrap BODY in a LET form if
BINDING-NAME is provided.
</refsect1>
<refsect1>
<title>Examples</title>
-<programlisting>
+<screen>
(with-foreign-object (size :int)
;; FOO is a foreign function returning a :POINTER-VOID
(let ((memory (foo size)))
(dotimes (i (deref-pointer size :int))
(do-something-with
(deref-array memory '(:array :unsigned-byte) i)))))))
-</programlisting>
+</screen>
</refsect1>
<refsect1>
<title>Side Effects</title>
<title>Examples</title>
<refsect2>
<title>C code</title>
-<programlisting>
+<screen>
int baz = 3;
typedef struct {
int foo () {
return baz;
}
-</programlisting>
+</screen>
</refsect2>
<refsect2>
<title>Lisp code</title>
-<programlisting>
+<screen>
(uffi:def-struct foo-struct
(x :int)
(y :double))
(foo)
=> 4
-</programlisting>
+</screen>
</refsect2>
</refsect1>
<refsect1>