diff --git a/Doc/Manual/Lisp.html b/Doc/Manual/Lisp.html index 04699bd52..0cd876679 100644 --- a/Doc/Manual/Lisp.html +++ b/Doc/Manual/Lisp.html @@ -50,6 +50,8 @@

21.2 Common Foreign Function Interface(CFFI)

+ +

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 module-name file-name

21.2.1 Additional Commandline Options

+

The following table list the additional commandline options available for the CLISP module. They can also be seen by using:

@@ -116,6 +119,7 @@ swig -cffi -help

21.2.2 Generating CFFI bindings

+ 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 test.h with the following C code: @@ -163,7 +167,7 @@ The generated SWIG Code will be:
 ;;;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 intern_function ensures that all C names are
 
 

21.2.3 Generating CFFI bindings for C++ code

+

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 intern_function ensures that all C names are %{ #include "Test/test.h" %} -

+

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" - + Various features which were available for C headers can also be used here. The target header which we are going to use here is:

@@ -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();
     }
 }
-
+

The interface used is:

 %module test
 %include "test.cpp"
-
+ 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) - + 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))) - +

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