html fixes

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9501 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2006-10-31 22:39:20 +00:00
commit 0136c1da7c

View file

@ -50,6 +50,8 @@
</p> </p>
<H2><a name="Lisp_nn3"></a>21.2 Common Foreign Function Interface(CFFI)</H2> <H2><a name="Lisp_nn3"></a>21.2 Common Foreign Function Interface(CFFI)</H2>
<p> <p>
CFFI, the Common Foreign Function Interface, is a portable foreign CFFI, the Common Foreign Function Interface, is a portable foreign
function interface for ANSI Common Lisp systems, similar in function interface for ANSI Common Lisp systems, similar in
@ -76,6 +78,7 @@ swig -cffi -module <i>module-name</i> <i>file-name</i>
<H3><a name="Lisp_nn4"></a>21.2.1 Additional Commandline Options </H3> <H3><a name="Lisp_nn4"></a>21.2.1 Additional Commandline Options </H3>
<p> <p>
The following table list the additional commandline options available for the CLISP module. They can also be seen by using: The following table list the additional commandline options available for the CLISP module. They can also be seen by using:
</p> </p>
@ -116,6 +119,7 @@ swig -cffi -help
<H3><a name="Lisp_nn5"></a>21.2.2 Generating CFFI bindings</H3> <H3><a name="Lisp_nn5"></a>21.2.2 Generating CFFI bindings</H3>
As we mentioned earlier the ideal way to use SWIG is to use interface As we mentioned earlier the ideal way to use SWIG is to use interface
files. To illustrate the use of it, lets assume that we have a files. To illustrate the use of it, lets assume that we have a
file named <i>test.h</i> with the following C code: file named <i>test.h</i> with the following C code:
@ -163,7 +167,7 @@ The generated SWIG Code will be:
<div class="targetlang"><pre> <div class="targetlang"><pre>
;;;SWIG wrapper code starts here ;;;SWIG wrapper code starts here
(cl:defmacro defanonenum (&body enums) (cl:defmacro defanonenum (&amp;body enums)
"Converts anonymous enums to defconstants." "Converts anonymous enums to defconstants."
`(cl:progn ,@(cl:loop for value in enums `(cl:progn ,@(cl:loop for value in enums
for index = 0 then (cl:1+ index) for index = 0 then (cl:1+ index)
@ -173,8 +177,8 @@ The generated SWIG Code will be:
(cl:eval-when (:compile-toplevel :load-toplevel) (cl:eval-when (:compile-toplevel :load-toplevel)
(cl:unless (cl:fboundp 'swig-lispify) (cl:unless (cl:fboundp 'swig-lispify)
(cl:defun swig-lispify (name flag cl:&optional (package cl:*package*)) (cl:defun swig-lispify (name flag cl:&amp;optional (package cl:*package*))
(cl:labels ((helper (lst last rest cl:&aux (c (cl:car lst))) (cl:labels ((helper (lst last rest cl:&amp;aux (c (cl:car lst)))
(cl:cond (cl:cond
((cl:null lst) ((cl:null lst)
rest) rest)
@ -389,6 +393,7 @@ The feature <i>intern_function</i> ensures that all C names are
<H3><a name="Lisp_nn6"></a>21.2.3 Generating CFFI bindings for C++ code</H3> <H3><a name="Lisp_nn6"></a>21.2.3 Generating CFFI bindings for C++ code</H3>
<p>This feature to SWIG (for CFFI) is very new and still far from <p>This feature to SWIG (for CFFI) is very new and still far from
complete. Pitch in with your patches, bug reports and feature complete. Pitch in with your patches, bug reports and feature
requests to improve it. requests to improve it.
@ -405,7 +410,7 @@ The feature <i>intern_function</i> ensures that all C names are
%{ %{
#include "Test/test.h" #include "Test/test.h"
%} %}
</div> </pre></div>
<p> <p>
Also, while parsing the C++ file and generating C wrapper code SWIG Also, while parsing the C++ file and generating C wrapper code SWIG
may need to be able to understand various symbols used in other may need to be able to understand various symbols used in other
@ -420,7 +425,7 @@ Also, while parsing the C++ file and generating C wrapper code SWIG
%include "target/header.h" %include "target/header.h"
</div> </pre></div>
Various features which were available for C headers can also be used Various features which were available for C headers can also be used
here. The target header which we are going to use here is: here. The target header which we are going to use here is:
<div class="code"><pre> <div class="code"><pre>
@ -434,27 +439,27 @@ namespace OpenDemo {
Test (float X) {x = X;} Test (float X) {x = X;}
// vector addition // vector addition
Test operator+ (const Test& v) const {return Test (x+v.x);} Test operator+ (const Test&amp; v) const {return Test (x+v.x);}
// length squared // length squared
float lengthSquared (void) const {return this->dot (*this);} float lengthSquared (void) const {return this-&gt;dot (*this);}
static float distance (const Test& a, const Test& b){return(a-b).length();} static float distance (const Test&amp; a, const Test&amp; b){return(a-b).length();}
inline Test parallelComponent (const Test& unitBasis) const { return unitBasis * projection; } inline Test parallelComponent (const Test&amp; unitBasis) const { return unitBasis * projection; }
Test setYtoZero (void) const {return Test (this->x);} Test setYtoZero (void) const {return Test (this-&gt;x);}
static const Test zero; static const Test zero;
}; };
inline Test operator* (float s, const Test& v) {return v*s;} inline Test operator* (float s, const Test&amp; v) {return v*s;}
inline std::ostream& operator<< (std::ostream& o, const Test& v) inline std::ostream&amp; operator&lt;&lt; (std::ostream&amp; o, const Test&amp; v)
{ {
return o << "(" << v.x << ")"; return o &lt;&lt; "(" &lt;&lt; v.x &lt;&lt; ")";
} }
@ -463,12 +468,12 @@ namespace OpenDemo {
return RandomVectorInUnitRadiusSphere().setYtoZero().normalize(); return RandomVectorInUnitRadiusSphere().setYtoZero().normalize();
} }
} }
</div></pre> </pre></div>
<p>The interface used is: </p> <p>The interface used is: </p>
<div class="code"><pre> <div class="code"><pre>
%module test %module test
%include "test.cpp" %include "test.cpp"
</div></pre> </pre></div>
SWIG generates 3 files, the first one is a C wrap which we don't show, SWIG generates 3 files, the first one is a C wrap which we don't show,
the second is the plain CFFI wrapper which is as shown below: the second is the plain CFFI wrapper which is as shown below:
@ -518,7 +523,7 @@ SWIG generates 3 files, the first one is a C wrap which we don't show,
(v :pointer)) (v :pointer))
(cffi:defcfun ("_wrap_RandomUnitVectorOnXZPlane" RandomUnitVectorOnXZPlane) :pointer) (cffi:defcfun ("_wrap_RandomUnitVectorOnXZPlane" RandomUnitVectorOnXZPlane) :pointer)
</div></pre> </pre></div>
The output is pretty good but it fails in disambiguating overloaded The output is pretty good but it fails in disambiguating overloaded
functions such as the constructor, in this case. One way of functions such as the constructor, in this case. One way of
@ -549,7 +554,7 @@ The output is pretty good but it fails in disambiguating overloaded
(clos:defmethod set-yto-zero ((obj test) (self test)) (clos:defmethod set-yto-zero ((obj test) (self test))
(Test_setYtoZero (ff-pointer obj) (ff-pointer self))) (Test_setYtoZero (ff-pointer obj) (ff-pointer self)))
</div></pre> </pre></div>
<p>I agree that the CFFI C++ module needs lot more work. But I hope it <p>I agree that the CFFI C++ module needs lot more work. But I hope it
provides a starting point, on which you can base your work of provides a starting point, on which you can base your work of