html fixes
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9501 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
9dcf7c6579
commit
0136c1da7c
1 changed files with 22 additions and 17 deletions
|
|
@ -50,6 +50,8 @@
|
|||
</p>
|
||||
|
||||
<H2><a name="Lisp_nn3"></a>21.2 Common Foreign Function Interface(CFFI)</H2>
|
||||
|
||||
|
||||
<p>
|
||||
CFFI, the Common Foreign Function Interface, is a portable foreign
|
||||
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>
|
||||
|
||||
|
||||
<p>
|
||||
The following table list the additional commandline options available for the CLISP module. They can also be seen by using:
|
||||
</p>
|
||||
|
|
@ -116,6 +119,7 @@ swig -cffi -help
|
|||
|
||||
<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
|
||||
files. To illustrate the use of it, lets assume that we have a
|
||||
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>
|
||||
;;;SWIG wrapper code starts here
|
||||
|
||||
(cl:defmacro defanonenum (&body enums)
|
||||
(cl:defmacro defanonenum (&body enums)
|
||||
"Converts anonymous enums to defconstants."
|
||||
`(cl:progn ,@(cl:loop for value in enums
|
||||
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:unless (cl:fboundp 'swig-lispify)
|
||||
(cl:defun swig-lispify (name flag cl:&optional (package cl:*package*))
|
||||
(cl:labels ((helper (lst last rest cl:&aux (c (cl:car lst)))
|
||||
(cl:defun swig-lispify (name flag cl:&optional (package cl:*package*))
|
||||
(cl:labels ((helper (lst last rest cl:&aux (c (cl:car lst)))
|
||||
(cl:cond
|
||||
((cl:null lst)
|
||||
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>
|
||||
|
||||
|
||||
<p>This feature to SWIG (for CFFI) is very new and still far from
|
||||
complete. Pitch in with your patches, bug reports and feature
|
||||
requests to improve it.
|
||||
|
|
@ -405,7 +410,7 @@ The feature <i>intern_function</i> ensures that all C names are
|
|||
%{
|
||||
#include "Test/test.h"
|
||||
%}
|
||||
</div>
|
||||
</pre></div>
|
||||
<p>
|
||||
Also, while parsing the C++ file and generating C wrapper code SWIG
|
||||
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"
|
||||
|
||||
</div>
|
||||
</pre></div>
|
||||
Various features which were available for C headers can also be used
|
||||
here. The target header which we are going to use here is:
|
||||
<div class="code"><pre>
|
||||
|
|
@ -434,27 +439,27 @@ namespace OpenDemo {
|
|||
Test (float X) {x = X;}
|
||||
|
||||
// vector addition
|
||||
Test operator+ (const Test& v) const {return Test (x+v.x);}
|
||||
Test operator+ (const Test& v) const {return Test (x+v.x);}
|
||||
|
||||
// length squared
|
||||
float lengthSquared (void) const {return this->dot (*this);}
|
||||
float lengthSquared (void) const {return this->dot (*this);}
|
||||
|
||||
static float distance (const Test& a, const Test& b){return(a-b).length();}
|
||||
static float distance (const Test& a, const Test& b){return(a-b).length();}
|
||||
|
||||
inline Test parallelComponent (const Test& unitBasis) const { return unitBasis * projection; }
|
||||
inline Test parallelComponent (const Test& unitBasis) const { return unitBasis * projection; }
|
||||
|
||||
Test setYtoZero (void) const {return Test (this->x);}
|
||||
Test setYtoZero (void) const {return Test (this->x);}
|
||||
|
||||
static const Test zero;
|
||||
};
|
||||
|
||||
|
||||
inline Test operator* (float s, const Test& v) {return v*s;}
|
||||
inline Test operator* (float s, const Test& v) {return v*s;}
|
||||
|
||||
|
||||
inline std::ostream& operator<< (std::ostream& o, const Test& v)
|
||||
inline std::ostream& operator<< (std::ostream& o, const Test& v)
|
||||
{
|
||||
return o << "(" << v.x << ")";
|
||||
return o << "(" << v.x << ")";
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -463,12 +468,12 @@ namespace OpenDemo {
|
|||
return RandomVectorInUnitRadiusSphere().setYtoZero().normalize();
|
||||
}
|
||||
}
|
||||
</div></pre>
|
||||
</pre></div>
|
||||
<p>The interface used is: </p>
|
||||
<div class="code"><pre>
|
||||
%module test
|
||||
%include "test.cpp"
|
||||
</div></pre>
|
||||
</pre></div>
|
||||
|
||||
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:
|
||||
|
|
@ -518,7 +523,7 @@ SWIG generates 3 files, the first one is a C wrap which we don't show,
|
|||
(v :pointer))
|
||||
|
||||
(cffi:defcfun ("_wrap_RandomUnitVectorOnXZPlane" RandomUnitVectorOnXZPlane) :pointer)
|
||||
</div></pre>
|
||||
</pre></div>
|
||||
|
||||
The output is pretty good but it fails in disambiguating overloaded
|
||||
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))
|
||||
(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
|
||||
provides a starting point, on which you can base your work of
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue