From 5f50fc0292f2afb9f93b52e5d04a3695c1558c73 Mon Sep 17 00:00:00 2001
From: William S Fulton
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
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
;;;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" -
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