Replace tabs with spaces in html docs

wkhtmltopdf is not expanding tabs within <pre> elements to 8 spaces as it
should. Workaround the problem by converting all tabs to an appropriate
number of spaces.
This commit is contained in:
William S Fulton 2015-12-29 19:10:57 +00:00
commit 3763beb489
25 changed files with 758 additions and 749 deletions

View file

@ -373,21 +373,21 @@ swig -allegrocl [ options ] filename
-identifier-converter [name] - Binds the variable swig:*swig-identifier-convert* -identifier-converter [name] - Binds the variable swig:*swig-identifier-convert*
in the generated .cl file to <tt>name</tt>. in the generated .cl file to <tt>name</tt>.
This function is used to generate symbols This function is used to generate symbols
for the lisp side of the interface. for the lisp side of the interface.
-cwrap - [default] Generate a .cxx file containing C wrapper function when -cwrap - [default] Generate a .cxx file containing C wrapper function when
wrapping C code. The interface generated is similar to what is wrapping C code. The interface generated is similar to what is
done for C++ code. done for C++ code.
-nocwrap - Explicitly turn off generation of .cxx wrappers for C code. Reasonable -nocwrap - Explicitly turn off generation of .cxx wrappers for C code. Reasonable
for modules with simple interfaces. Can not handle all legal enum for modules with simple interfaces. Can not handle all legal enum
and constant constructs, or take advantage of SWIG customization features. and constant constructs, or take advantage of SWIG customization features.
-isolate - With this command-line argument, all lisp helper functions are defined -isolate - With this command-line argument, all lisp helper functions are defined
in a unique package named <tt>swig.&lt;module-name&gt;</tt> rather than in a unique package named <tt>swig.&lt;module-name&gt;</tt> rather than
<tt>swig</tt>. This prevents conflicts when the module is <tt>swig</tt>. This prevents conflicts when the module is
intended to be used with other swig generated interfaces that may, intended to be used with other swig generated interfaces that may,
for instance, make use of different identifier converters. for instance, make use of different identifier converters.
</pre> </pre>
</div> </div>
@ -472,7 +472,7 @@ interested in generating an interface to C++.
| Foreign Code | What we're generating an interface to. | Foreign Code | What we're generating an interface to.
|______________| |______________|
| |
| |
_______v______ _______v______
| | (foreign side) | | (foreign side)
| Wrapper code | extern "C" wrappers calling C++ | Wrapper code | extern "C" wrappers calling C++
@ -484,18 +484,18 @@ interested in generating an interface to C++.
| FFI Layer | Low level lisp interface. ff:def-foreign-call, | FFI Layer | Low level lisp interface. ff:def-foreign-call,
|______________| ff:def-foreign-variable |______________| ff:def-foreign-variable
| |
+---------------------------- +----------------------------
_______v______ _______v______ _______v______ _______v______
| | | | (lisp side) | | | | (lisp side)
| Defuns | | Defmethods | wrapper for overloaded | Defuns | | Defmethods | wrapper for overloaded
|______________| |______________| functions or those with |______________| |______________| functions or those with
(lisp side) | defaulted arguments (lisp side) | defaulted arguments
Wrapper for non-overloaded | Wrapper for non-overloaded |
functions and methods _______v______ functions and methods _______v______
| | (lisp side) | | (lisp side)
| Defuns | dispatch function | Defuns | dispatch function
|______________| to overloads based |______________| to overloads based
on arity on arity
</pre> </pre>
</div> </div>
@ -799,8 +799,8 @@ namespace car {
</pre> </pre>
</div> </div>
<p> <p>
Users are cautioned to get to know their constants before use, or Users are cautioned to get to know their constants before use, or
not use the <tt>-nocwrap</tt> command-line option. not use the <tt>-nocwrap</tt> command-line option.
</p> </p>
<H3><a name="Allegrocl_nn17">18.3.3 Variables</a></H3> <H3><a name="Allegrocl_nn17">18.3.3 Variables</a></H3>
@ -907,7 +907,7 @@ globalvar&gt; (globalvar.nnn::glob_float)
<p>For example, the following header file <p>For example, the following header file
<div class="code">enum.h: <div class="code">enum.h:
<pre> <pre>
enum COL { RED, GREEN, BLUE }; enum COL { RED, GREEN, BLUE };
enum FOO { FOO1 = 10, FOO2, FOO3 }; enum FOO { FOO1 = 10, FOO2, FOO3 };
</pre> </pre>
</div> </div>
@ -1177,25 +1177,25 @@ namespace BAR {
<H4><a name="Allegrocl_nn26">18.3.7.1 Generating wrapper code for templates</a></H4> <H4><a name="Allegrocl_nn26">18.3.7.1 Generating wrapper code for templates</a></H4>
<p> <p>
SWIG provides support for dealing with templates, but by SWIG provides support for dealing with templates, but by
default, it will not generate any member variable or function default, it will not generate any member variable or function
wrappers for templated classes. In order to create these wrappers for templated classes. In order to create these
wrappers, you need to explicitly tell SWIG to instantiate wrappers, you need to explicitly tell SWIG to instantiate
them. This is done via the them. This is done via the
<a href="SWIGPlus.html#SWIGPlus_nn30"><tt>%template</tt></a> <a href="SWIGPlus.html#SWIGPlus_nn30"><tt>%template</tt></a>
directive. directive.
</p> </p>
<H4><a name="Allegrocl_nn27">18.3.7.2 Implicit Template instantiation</a></H4> <H4><a name="Allegrocl_nn27">18.3.7.2 Implicit Template instantiation</a></H4>
<p> <p>
While no wrapper code is generated for accessing member While no wrapper code is generated for accessing member
variables, or calling member functions, type code is generated variables, or calling member functions, type code is generated
to include these templated classes in the foreign-type and CLOS to include these templated classes in the foreign-type and CLOS
class schema. class schema.
</p> </p>
<H3><a name="Allegrocl_nn28">18.3.8 Typedef, Templates, and Synonym Types</a></H3> <H3><a name="Allegrocl_nn28">18.3.8 Typedef, Templates, and Synonym Types</a></H3>
@ -1243,7 +1243,7 @@ int zzz(A *inst = 0); /* return inst-&gt;x + inst-&gt;y */
definition, we generate a form that expands to: definition, we generate a form that expands to:
</p> </p>
<div class="targetlang"> <div class="targetlang">
<tt>(setf (find-class &lt;synonym&gt;) &lt;primary&gt;)</tt> <tt>(setf (find-class &lt;synonym&gt;) &lt;primary&gt;)</tt>
</div> </div>
<p> <p>
The result is that all references to synonym types in foreign The result is that all references to synonym types in foreign
@ -1285,17 +1285,17 @@ synonym&gt;
criteria from a set of synonym types. criteria from a set of synonym types.
</p> </p>
<ul> <ul>
<li> <li>
If a synonym type has a class definition, it is the primary type. If a synonym type has a class definition, it is the primary type.
</li> </li>
<li> <li>
If a synonym type is a class template and has been explicitly If a synonym type is a class template and has been explicitly
instantiated via <tt>%template</tt>, it is the primary type. instantiated via <tt>%template</tt>, it is the primary type.
</li> </li>
<li> <li>
For all other sets of synonymous types, the synonym which is For all other sets of synonymous types, the synonym which is
parsed first becomes the primary type. parsed first becomes the primary type.
</li> </li>
</ul> </ul>
<H3><a name="Allegrocl_nn30">18.3.9 Function overloading/Parameter defaulting</a></H3> <H3><a name="Allegrocl_nn30">18.3.9 Function overloading/Parameter defaulting</a></H3>
@ -1472,68 +1472,68 @@ overload&gt;
<pre> <pre>
/* name conversion for overloaded operators. */ /* name conversion for overloaded operators. */
#ifdef __cplusplus #ifdef __cplusplus
%rename(__add__) *::operator+; %rename(__add__) *::operator+;
%rename(__pos__) *::operator+(); %rename(__pos__) *::operator+();
%rename(__pos__) *::operator+() const; %rename(__pos__) *::operator+() const;
%rename(__sub__) *::operator-; %rename(__sub__) *::operator-;
%rename(__neg__) *::operator-() const; %rename(__neg__) *::operator-() const;
%rename(__neg__) *::operator-(); %rename(__neg__) *::operator-();
%rename(__mul__) *::operator*; %rename(__mul__) *::operator*;
%rename(__deref__) *::operator*(); %rename(__deref__) *::operator*();
%rename(__deref__) *::operator*() const; %rename(__deref__) *::operator*() const;
%rename(__div__) *::operator/; %rename(__div__) *::operator/;
%rename(__mod__) *::operator%; %rename(__mod__) *::operator%;
%rename(__logxor__) *::operator^; %rename(__logxor__) *::operator^;
%rename(__logand__) *::operator&amp;; %rename(__logand__) *::operator&amp;;
%rename(__logior__) *::operator|; %rename(__logior__) *::operator|;
%rename(__lognot__) *::operator~(); %rename(__lognot__) *::operator~();
%rename(__lognot__) *::operator~() const; %rename(__lognot__) *::operator~() const;
%rename(__not__) *::operator!(); %rename(__not__) *::operator!();
%rename(__not__) *::operator!() const; %rename(__not__) *::operator!() const;
%rename(__assign__) *::operator=; %rename(__assign__) *::operator=;
%rename(__add_assign__) *::operator+=; %rename(__add_assign__) *::operator+=;
%rename(__sub_assign__) *::operator-=; %rename(__sub_assign__) *::operator-=;
%rename(__mul_assign__) *::operator*=; %rename(__mul_assign__) *::operator*=;
%rename(__div_assign__) *::operator/=; %rename(__div_assign__) *::operator/=;
%rename(__mod_assign__) *::operator%=; %rename(__mod_assign__) *::operator%=;
%rename(__logxor_assign__) *::operator^=; %rename(__logxor_assign__) *::operator^=;
%rename(__logand_assign__) *::operator&amp;=; %rename(__logand_assign__) *::operator&amp;=;
%rename(__logior_assign__) *::operator|=; %rename(__logior_assign__) *::operator|=;
%rename(__lshift__) *::operator&lt;&lt;; %rename(__lshift__) *::operator&lt;&lt;;
%rename(__lshift_assign__) *::operator&lt;&lt;=; %rename(__lshift_assign__) *::operator&lt;&lt;=;
%rename(__rshift__) *::operator&gt;&gt;; %rename(__rshift__) *::operator&gt;&gt;;
%rename(__rshift_assign__) *::operator&gt;&gt;=; %rename(__rshift_assign__) *::operator&gt;&gt;=;
%rename(__eq__) *::operator==; %rename(__eq__) *::operator==;
%rename(__ne__) *::operator!=; %rename(__ne__) *::operator!=;
%rename(__lt__) *::operator&lt;; %rename(__lt__) *::operator&lt;;
%rename(__gt__) *::operator&gt;; %rename(__gt__) *::operator&gt;;
%rename(__lte__) *::operator&lt;=; %rename(__lte__) *::operator&lt;=;
%rename(__gte__) *::operator&gt;=; %rename(__gte__) *::operator&gt;=;
%rename(__and__) *::operator&amp;&amp;; %rename(__and__) *::operator&amp;&amp;;
%rename(__or__) *::operator||; %rename(__or__) *::operator||;
%rename(__preincr__) *::operator++(); %rename(__preincr__) *::operator++();
%rename(__postincr__) *::operator++(int); %rename(__postincr__) *::operator++(int);
%rename(__predecr__) *::operator--(); %rename(__predecr__) *::operator--();
%rename(__postdecr__) *::operator--(int); %rename(__postdecr__) *::operator--(int);
%rename(__comma__) *::operator,(); %rename(__comma__) *::operator,();
%rename(__comma__) *::operator,() const; %rename(__comma__) *::operator,() const;
%rename(__member_ref__) *::operator-&gt;; %rename(__member_ref__) *::operator-&gt;;
%rename(__member_func_ref__) *::operator-&gt;*; %rename(__member_func_ref__) *::operator-&gt;*;
%rename(__funcall__) *::operator(); %rename(__funcall__) *::operator();
%rename(__aref__) *::operator[]; %rename(__aref__) *::operator[];
</pre> </pre>
</div> </div>
@ -1821,28 +1821,28 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
<p>The LIN typemap accepts the following <tt>$variable</tt> references. <p>The LIN typemap accepts the following <tt>$variable</tt> references.
</p> </p>
<ul> <ul>
<li><tt>$in</tt> - expands to the name of the parameter being <li><tt>$in</tt> - expands to the name of the parameter being
applied to this typemap applied to this typemap
</li> </li>
<li><tt>$out</tt> - expands to the name of the local variable <li><tt>$out</tt> - expands to the name of the local variable
assigned to this typemap assigned to this typemap
</li> </li>
<li><tt>$in_fftype</tt> - the foreign function type of the C type.</li> <li><tt>$in_fftype</tt> - the foreign function type of the C type.</li>
<li><tt>$*in_fftype</tt> - the foreign function type of the C type <li><tt>$*in_fftype</tt> - the foreign function type of the C type
with one pointer removed. If there is no pointer, then $*in_fftype with one pointer removed. If there is no pointer, then $*in_fftype
is the same as $in_fftype. is the same as $in_fftype.
</li> </li>
<li><tt>$body</tt> - very important. Instructs SWIG where <li><tt>$body</tt> - very important. Instructs SWIG where
subsequent code generation steps should be inserted into the subsequent code generation steps should be inserted into the
current typemap. Leaving out a <tt>$body</tt> reference current typemap. Leaving out a <tt>$body</tt> reference
will result in lisp wrappers that do very little by way of will result in lisp wrappers that do very little by way of
calling into foreign code. Not recommended. calling into foreign code. Not recommended.
</li> </li>
</ul> </ul>
<div class="code"> <div class="code">
<pre> <pre>
%typemap(lin) SWIGTYPE "(cl:let (($out $in))\n $body)"; %typemap(lin) SWIGTYPE "(cl:let (($out $in))\n $body)";
</pre> </pre>
</div> </div>
@ -1858,17 +1858,17 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
<p>The LOUT typemap uses the following $variable <p>The LOUT typemap uses the following $variable
</p> </p>
<ul> <ul>
<li><tt>$lclass</tt> - Expands to the CLOS class that <li><tt>$lclass</tt> - Expands to the CLOS class that
represents foreign-objects of the return type matching this represents foreign-objects of the return type matching this
typemap. typemap.
</li> </li>
<li><tt>$body</tt> - Same as for the LIN map. Place this <li><tt>$body</tt> - Same as for the LIN map. Place this
variable where you want the foreign-function call to occur. variable where you want the foreign-function call to occur.
</li> </li>
<li><tt>$ldestructor</tt> - Expands to the symbol naming the destructor for this <li><tt>$ldestructor</tt> - Expands to the symbol naming the destructor for this
class ($lclass) of object. Allows you to insert finalization or automatic garbage class ($lclass) of object. Allows you to insert finalization or automatic garbage
collection into the wrapper code (see default mappings below). collection into the wrapper code (see default mappings below).
</li> </li>
</ul> </ul>
<div class="code"> <div class="code">

View file

@ -210,7 +210,7 @@ When complete your device should be listed in those attached, something like:
<pre> <pre>
$ adb devices $ adb devices
List of devices attached List of devices attached
A32-6DBE0001-9FF80000-015D62C3-02018028 device A32-6DBE0001-9FF80000-015D62C3-02018028 device
</pre> </pre>
</div> </div>
@ -222,7 +222,7 @@ This means you are now ready to install the application...
<pre> <pre>
$ adb install bin/SwigSimple-debug.apk $ adb install bin/SwigSimple-debug.apk
95 KB/s (4834 bytes in 0.049s) 95 KB/s (4834 bytes in 0.049s)
pkg: /data/local/tmp/SwigSimple-debug.apk pkg: /data/local/tmp/SwigSimple-debug.apk
Success Success
</pre> </pre>
</div> </div>

View file

@ -60,7 +60,7 @@ Suppose you had a C function like this:
<div class="code"><pre> <div class="code"><pre>
void add(double a, double b, double *result) { void add(double a, double b, double *result) {
*result = a + b; *result = a + b;
} }
</pre></div> </pre></div>
@ -204,7 +204,7 @@ input value:
</p> </p>
<div class="code"><pre> <div class="code"><pre>
int *INPUT int *INPUT
short *INPUT short *INPUT
long *INPUT long *INPUT
unsigned int *INPUT unsigned int *INPUT
@ -221,7 +221,7 @@ function:
<div class="code"><pre> <div class="code"><pre>
double add(double *a, double *b) { double add(double *a, double *b) {
return *a+*b; return *a+*b;
} }
</pre></div> </pre></div>
@ -273,7 +273,7 @@ These methods can be used as shown in an earlier example. For example, if you ha
<div class="code"><pre> <div class="code"><pre>
void add(double a, double b, double *c) { void add(double a, double b, double *c) {
*c = a+b; *c = a+b;
} }
</pre></div> </pre></div>
@ -339,7 +339,7 @@ A C function that uses this might be something like this:</p>
<div class="code"><pre> <div class="code"><pre>
void negate(double *x) { void negate(double *x) {
*x = -(*x); *x = -(*x);
} }
</pre></div> </pre></div>

View file

@ -55,10 +55,10 @@
</p> </p>
<ol> <ol>
<li>generates portable C code</li> <li>generates portable C code</li>
<li>includes a customizable interpreter</li> <li>includes a customizable interpreter</li>
<li>links to C libraries with a simple Foreign Function Interface</li> <li>links to C libraries with a simple Foreign Function Interface</li>
<li>supports full tail-recursion and first-class continuations</li> <li>supports full tail-recursion and first-class continuations</li>
</ol> </ol>
<p> <p>
@ -98,7 +98,7 @@
</p> </p>
<div class="shell"> <div class="shell">
<pre>% swig -chicken example.i</pre> <pre>% swig -chicken example.i</pre>
</div> </div>
<p> <p>
@ -131,7 +131,7 @@
</p> </p>
<div class="shell"> <div class="shell">
<pre>% swig -chicken -c++ example.i</pre> <pre>% swig -chicken -c++ example.i</pre>
</div> </div>
<p> <p>
@ -142,7 +142,7 @@
</p> </p>
<div class="shell"> <div class="shell">
<pre>% chicken example.scm -output-file oexample.c</pre> <pre>% chicken example.scm -output-file oexample.c</pre>
</div> </div>
<p> <p>
@ -176,10 +176,10 @@
<p> <p>
The name of the module must be declared one of two ways: The name of the module must be declared one of two ways:
<ul> <ul>
<li>Placing <tt>%module example</tt> in the SWIG interface <li>Placing <tt>%module example</tt> in the SWIG interface
file.</li> file.</li>
<li>Using <tt>-module example</tt> on the SWIG command <li>Using <tt>-module example</tt> on the SWIG command
line.</li> line.</li>
</ul> </ul>
<p> <p>
@ -189,7 +189,7 @@
<p> <p>
CHICKEN will be able to access the module using the <code>(declare CHICKEN will be able to access the module using the <code>(declare
(uses <i>modulename</i>))</code> CHICKEN Scheme form. (uses <i>modulename</i>))</code> CHICKEN Scheme form.
</p> </p>
<H3><a name="Chicken_nn8">21.2.3 Constants and Variables</a></H3> <H3><a name="Chicken_nn8">21.2.3 Constants and Variables</a></H3>
@ -200,10 +200,10 @@
the interface file: the interface file:
</p> </p>
<ol> <ol>
<li><code>#define MYCONSTANT1 ...</code></li> <li><code>#define MYCONSTANT1 ...</code></li>
<li><code>%constant int MYCONSTANT2 = ...</code></li> <li><code>%constant int MYCONSTANT2 = ...</code></li>
<li><code>const int MYCONSTANT3 = ...</code></li> <li><code>const int MYCONSTANT3 = ...</code></li>
<li><code>enum { MYCONSTANT4 = ... };</code></li> <li><code>enum { MYCONSTANT4 = ... };</code></li>
</ol> </ol>
<p> <p>
@ -295,11 +295,11 @@
<p> <p>
The author of TinyCLOS, Gregor Kiczales, describes TinyCLOS as: The author of TinyCLOS, Gregor Kiczales, describes TinyCLOS as:
"Tiny CLOS is a Scheme implementation of a `kernelized' CLOS, with a "Tiny CLOS is a Scheme implementation of a `kernelized' CLOS, with a
metaobject protocol. The implementation is even simpler than metaobject protocol. The implementation is even simpler than
the simple CLOS found in `The Art of the Metaobject Protocol,' the simple CLOS found in `The Art of the Metaobject Protocol,'
weighing in at around 850 lines of code, including (some) weighing in at around 850 lines of code, including (some)
comments and documentation." comments and documentation."
</p> </p>
<p> <p>

View file

@ -116,16 +116,18 @@ static char error_message[256];
static int error_status = 0; static int error_status = 0;
void throw_exception(char *msg) { void throw_exception(char *msg) {
strncpy(error_message,msg,256); strncpy(error_message,msg,256);
error_status = 1; error_status = 1;
} }
void clear_exception() { void clear_exception() {
error_status = 0; error_status = 0;
} }
char *check_exception() { char *check_exception() {
if (error_status) return error_message; if (error_status)
else return NULL; return error_message;
else
return NULL;
} }
</pre></div> </pre></div>
@ -137,13 +139,13 @@ To use these functions, functions simply call
<div class="code"><pre> <div class="code"><pre>
double inv(double x) { double inv(double x) {
if (x != 0) return 1.0/x; if (x != 0)
else { return 1.0/x;
throw_exception("Division by zero"); else {
return 0; throw_exception("Division by zero");
} return 0;
}
} }
</pre></div> </pre></div>
<p> <p>
@ -152,12 +154,12 @@ as the following (shown for Perl5) :</p>
<div class="code"><pre> <div class="code"><pre>
%exception { %exception {
char *err; char *err;
clear_exception(); clear_exception();
$action $action
if ((err = check_exception())) { if ((err = check_exception())) {
croak(err); croak(err);
} }
} }
</pre></div> </pre></div>
@ -207,8 +209,10 @@ Now, within a C program, you can do the following :</p>
<div class="code"><pre> <div class="code"><pre>
double inv(double x) { double inv(double x) {
if (x) return 1.0/x; if (x)
else throw(DivisionByZero); return 1.0/x;
else
throw(DivisionByZero);
} }
</pre></div> </pre></div>
@ -222,17 +226,17 @@ Finally, to create a SWIG exception handler, write the following :</p>
%} %}
%exception { %exception {
try { try {
$action $action
} catch(RangeError) { } catch(RangeError) {
croak("Range Error"); croak("Range Error");
} catch(DivisionByZero) { } catch(DivisionByZero) {
croak("Division by zero"); croak("Division by zero");
} catch(OutOfMemory) { } catch(OutOfMemory) {
croak("Out of memory"); croak("Out of memory");
} finally { } finally {
croak("Unknown exception"); croak("Unknown exception");
} }
} }
</pre></div> </pre></div>
@ -250,17 +254,17 @@ Handling C++ exceptions is also straightforward. For example:
<div class="code"><pre> <div class="code"><pre>
%exception { %exception {
try { try {
$action $action
} catch(RangeError) { } catch(RangeError) {
croak("Range Error"); croak("Range Error");
} catch(DivisionByZero) { } catch(DivisionByZero) {
croak("Division by zero"); croak("Division by zero");
} catch(OutOfMemory) { } catch(OutOfMemory) {
croak("Out of memory"); croak("Out of memory");
} catch(...) { } catch(...) {
croak("Unknown exception"); croak("Unknown exception");
} }
} }
</pre></div> </pre></div>
@ -320,7 +324,7 @@ critical pieces of code. For example:
<div class="code"><pre> <div class="code"><pre>
%exception { %exception {
... your exception handler ... ... your exception handler ...
} }
/* Define critical operations that can throw exceptions here */ /* Define critical operations that can throw exceptions here */

View file

@ -477,10 +477,10 @@ objects and fits nicely C++'s RAII idiom. Example:
<div class="code"> <div class="code">
<pre> <pre>
func UseClassName(...) ... { func UseClassName(...) ... {
o := NewClassName(...) o := NewClassName(...)
defer DeleteClassName(o) defer DeleteClassName(o)
// Use the ClassName object // Use the ClassName object
return ... return ...
} }
</pre> </pre>
</div> </div>
@ -495,17 +495,17 @@ that creates a C++ object and functions called by this function. Example:
<div class="code"> <div class="code">
<pre> <pre>
func WithClassName(constructor args, f func(ClassName, ...interface{}) error, data ...interface{}) error { func WithClassName(constructor args, f func(ClassName, ...interface{}) error, data ...interface{}) error {
o := NewClassName(constructor args) o := NewClassName(constructor args)
defer DeleteClassName(o) defer DeleteClassName(o)
return f(o, data...) return f(o, data...)
} }
func UseClassName(o ClassName, data ...interface{}) (err error) { func UseClassName(o ClassName, data ...interface{}) (err error) {
// Use the ClassName object and additional data and return error. // Use the ClassName object and additional data and return error.
} }
func main() { func main() {
WithClassName(constructor args, UseClassName, additional data) WithClassName(constructor args, UseClassName, additional data)
} }
</pre> </pre>
</div> </div>
@ -547,33 +547,33 @@ problematic with C++ code that uses thread-local storage.
<div class="code"> <div class="code">
<pre> <pre>
import ( import (
"runtime" "runtime"
"wrap" // SWIG generated wrapper code "wrap" // SWIG generated wrapper code
) )
type GoClassName struct { type GoClassName struct {
wcn wrap.ClassName wcn wrap.ClassName
} }
func NewGoClassName() *GoClassName { func NewGoClassName() *GoClassName {
o := &amp;GoClassName{wcn: wrap.NewClassName()} o := &amp;GoClassName{wcn: wrap.NewClassName()}
runtime.SetFinalizer(o, deleteGoClassName) runtime.SetFinalizer(o, deleteGoClassName)
return o return o
} }
func deleteGoClassName(o *GoClassName) { func deleteGoClassName(o *GoClassName) {
// Runs typically in a different OS thread! // Runs typically in a different OS thread!
wrap.DeleteClassName(o.wcn) wrap.DeleteClassName(o.wcn)
o.wcn = nil o.wcn = nil
} }
func (o *GoClassName) Close() { func (o *GoClassName) Close() {
// If the C++ object has a Close method. // If the C++ object has a Close method.
o.wcn.Close() o.wcn.Close()
// If the GoClassName object is no longer in an usable state. // If the GoClassName object is no longer in an usable state.
runtime.SetFinalizer(o, nil) // Remove finalizer. runtime.SetFinalizer(o, nil) // Remove finalizer.
deleteGoClassName() // Free the C++ object. deleteGoClassName() // Free the C++ object.
} }
</pre> </pre>
</div> </div>
@ -635,19 +635,19 @@ explains how to implement a FooBarGo class similar to the FooBarCpp class.
class FooBarAbstract class FooBarAbstract
{ {
public: public:
FooBarAbstract() {}; FooBarAbstract() {};
virtual ~FooBarAbstract() {}; virtual ~FooBarAbstract() {};
std::string FooBar() { std::string FooBar() {
return this->Foo() + ", " + this->Bar(); return this->Foo() + ", " + this->Bar();
}; };
protected: protected:
virtual std::string Foo() { virtual std::string Foo() {
return "Foo"; return "Foo";
}; };
virtual std::string Bar() = 0; virtual std::string Bar() = 0;
}; };
</pre> </pre>
</div> </div>
@ -661,13 +661,13 @@ protected:
class FooBarCpp : public FooBarAbstract class FooBarCpp : public FooBarAbstract
{ {
protected: protected:
virtual std::string Foo() { virtual std::string Foo() {
return "C++ " + FooBarAbstract::Foo(); return "C++ " + FooBarAbstract::Foo();
} }
virtual std::string Bar() { virtual std::string Bar() {
return "C++ Bar"; return "C++ Bar";
} }
}; };
</pre> </pre>
</div> </div>
@ -758,9 +758,9 @@ determine if an object instance was created via <tt>NewDirectorClassName</tt>:
<div class="code"> <div class="code">
<pre> <pre>
if o.DirectorInterface() != nil { if o.DirectorInterface() != nil {
DeleteDirectorClassName(o) DeleteDirectorClassName(o)
} else { } else {
DeleteClassName(o) DeleteClassName(o)
} }
</pre> </pre>
</div> </div>
@ -798,22 +798,22 @@ As an example see part of the <tt>FooBarGo</tt> class:
<div class="code"> <div class="code">
<pre> <pre>
type overwrittenMethodsOnFooBarAbstract struct { type overwrittenMethodsOnFooBarAbstract struct {
fb FooBarAbstract fb FooBarAbstract
} }
func (om *overwrittenMethodsOnFooBarAbstract) Foo() string { func (om *overwrittenMethodsOnFooBarAbstract) Foo() string {
... ...
} }
func (om *overwrittenMethodsOnFooBarAbstract) Bar() string { func (om *overwrittenMethodsOnFooBarAbstract) Bar() string {
... ...
} }
func NewFooBarGo() FooBarGo { func NewFooBarGo() FooBarGo {
om := &amp;overwrittenMethodsOnFooBarAbstract{} om := &amp;overwrittenMethodsOnFooBarAbstract{}
fb := NewDirectorFooBarAbstract(om) fb := NewDirectorFooBarAbstract(om)
om.fb = fb om.fb = fb
... ...
} }
</pre> </pre>
</div> </div>
@ -855,7 +855,7 @@ the method in the base class. This is also the case for the
<div class="code"> <div class="code">
<pre> <pre>
virtual std::string Foo() { virtual std::string Foo() {
return "C++ " + FooBarAbstract::Foo(); return "C++ " + FooBarAbstract::Foo();
} }
</pre> </pre>
</div> </div>
@ -869,7 +869,7 @@ The <tt>FooBarGo.Foo</tt> implementation in the example looks like this:
<div class="code"> <div class="code">
<pre> <pre>
func (om *overwrittenMethodsOnFooBarAbstract) Foo() string { func (om *overwrittenMethodsOnFooBarAbstract) Foo() string {
return "Go " + DirectorFooBarAbstractFoo(om.fb) return "Go " + DirectorFooBarAbstractFoo(om.fb)
} }
</pre> </pre>
</div> </div>
@ -902,31 +902,31 @@ this:
<div class="code"> <div class="code">
<pre> <pre>
type FooBarGo interface { type FooBarGo interface {
FooBarAbstract FooBarAbstract
deleteFooBarAbstract() deleteFooBarAbstract()
IsFooBarGo() IsFooBarGo()
} }
type fooBarGo struct { type fooBarGo struct {
FooBarAbstract FooBarAbstract
} }
func (fbgs *fooBarGo) deleteFooBarAbstract() { func (fbgs *fooBarGo) deleteFooBarAbstract() {
DeleteDirectorFooBarAbstract(fbgs.FooBarAbstract) DeleteDirectorFooBarAbstract(fbgs.FooBarAbstract)
} }
func (fbgs *fooBarGo) IsFooBarGo() {} func (fbgs *fooBarGo) IsFooBarGo() {}
func NewFooBarGo() FooBarGo { func NewFooBarGo() FooBarGo {
om := &amp;overwrittenMethodsOnFooBarAbstract{} om := &amp;overwrittenMethodsOnFooBarAbstract{}
fb := NewDirectorFooBarAbstract(om) fb := NewDirectorFooBarAbstract(om)
om.fb = fb om.fb = fb
return &amp;fooBarGo{FooBarAbstract: fb} return &amp;fooBarGo{FooBarAbstract: fb}
} }
func DeleteFooBarGo(fbg FooBarGo) { func DeleteFooBarGo(fbg FooBarGo) {
fbg.deleteFooBarAbstract() fbg.deleteFooBarAbstract()
} }
</pre> </pre>
</div> </div>
@ -962,14 +962,14 @@ in the <tt>FooBarGo</tt> class is here:
<div class="code"> <div class="code">
<pre> <pre>
type overwrittenMethodsOnFooBarAbstract struct { type overwrittenMethodsOnFooBarAbstract struct {
fb FooBarAbstract fb FooBarAbstract
} }
func NewFooBarGo() FooBarGo { func NewFooBarGo() FooBarGo {
om := &amp;overwrittenMethodsOnFooBarAbstract{} om := &amp;overwrittenMethodsOnFooBarAbstract{}
fb := NewDirectorFooBarAbstract(om) // fb.v = om fb := NewDirectorFooBarAbstract(om) // fb.v = om
om.fb = fb // Backlink causes cycle as fb.v = om! om.fb = fb // Backlink causes cycle as fb.v = om!
... ...
} }
</pre> </pre>
</div> </div>
@ -985,21 +985,21 @@ the finalizer on <tt>fooBarGo</tt>:
<div class="code"> <div class="code">
<pre> <pre>
type fooBarGo struct { type fooBarGo struct {
FooBarAbstract FooBarAbstract
} }
type overwrittenMethodsOnFooBarAbstract struct { type overwrittenMethodsOnFooBarAbstract struct {
fb FooBarAbstract fb FooBarAbstract
} }
func NewFooBarGo() FooBarGo { func NewFooBarGo() FooBarGo {
om := &amp;overwrittenMethodsOnFooBarAbstract{} om := &amp;overwrittenMethodsOnFooBarAbstract{}
fb := NewDirectorFooBarAbstract(om) fb := NewDirectorFooBarAbstract(om)
om.fb = fb // Backlink causes cycle as fb.v = om! om.fb = fb // Backlink causes cycle as fb.v = om!
fbgs := &amp;fooBarGo{FooBarAbstract: fb} fbgs := &amp;fooBarGo{FooBarAbstract: fb}
runtime.SetFinalizer(fbgs, FooBarGo.deleteFooBarAbstract) runtime.SetFinalizer(fbgs, FooBarGo.deleteFooBarAbstract)
return fbgs return fbgs
} }
</pre> </pre>
</div> </div>
@ -1026,18 +1026,18 @@ The complete and annotated <tt>FooBarGo</tt> class looks like this:
// drop in replacement for FooBarAbstract but the reverse causes a compile time // drop in replacement for FooBarAbstract but the reverse causes a compile time
// error. // error.
type FooBarGo interface { type FooBarGo interface {
FooBarAbstract FooBarAbstract
deleteFooBarAbstract() deleteFooBarAbstract()
IsFooBarGo() IsFooBarGo()
} }
// Via embedding fooBarGo "inherits" all methods of FooBarAbstract. // Via embedding fooBarGo "inherits" all methods of FooBarAbstract.
type fooBarGo struct { type fooBarGo struct {
FooBarAbstract FooBarAbstract
} }
func (fbgs *fooBarGo) deleteFooBarAbstract() { func (fbgs *fooBarGo) deleteFooBarAbstract() {
DeleteDirectorFooBarAbstract(fbgs.FooBarAbstract) DeleteDirectorFooBarAbstract(fbgs.FooBarAbstract)
} }
// The IsFooBarGo method ensures that FooBarGo is a superset of FooBarAbstract. // The IsFooBarGo method ensures that FooBarGo is a superset of FooBarAbstract.
@ -1049,48 +1049,48 @@ func (fbgs *fooBarGo) IsFooBarGo() {}
// Go type that defines the DirectorInterface. It contains the Foo and Bar // Go type that defines the DirectorInterface. It contains the Foo and Bar
// methods that overwrite the respective virtual C++ methods on FooBarAbstract. // methods that overwrite the respective virtual C++ methods on FooBarAbstract.
type overwrittenMethodsOnFooBarAbstract struct { type overwrittenMethodsOnFooBarAbstract struct {
// Backlink to FooBarAbstract so that the rest of the class can be used by // Backlink to FooBarAbstract so that the rest of the class can be used by
// the overridden methods. // the overridden methods.
fb FooBarAbstract fb FooBarAbstract
// If additional constructor arguments have been given they are typically // If additional constructor arguments have been given they are typically
// stored here so that the overriden methods can use them. // stored here so that the overriden methods can use them.
} }
func (om *overwrittenMethodsOnFooBarAbstract) Foo() string { func (om *overwrittenMethodsOnFooBarAbstract) Foo() string {
// DirectorFooBarAbstractFoo calls the base method FooBarAbstract::Foo. // DirectorFooBarAbstractFoo calls the base method FooBarAbstract::Foo.
return "Go " + DirectorFooBarAbstractFoo(om.fb) return "Go " + DirectorFooBarAbstractFoo(om.fb)
} }
func (om *overwrittenMethodsOnFooBarAbstract) Bar() string { func (om *overwrittenMethodsOnFooBarAbstract) Bar() string {
return "Go Bar" return "Go Bar"
} }
func NewFooBarGo() FooBarGo { func NewFooBarGo() FooBarGo {
// Instantiate FooBarAbstract with selected methods overridden. The methods // Instantiate FooBarAbstract with selected methods overridden. The methods
// that will be overwritten are defined on // that will be overwritten are defined on
// overwrittenMethodsOnFooBarAbstract and have a compatible signature to the // overwrittenMethodsOnFooBarAbstract and have a compatible signature to the
// respective virtual C++ methods. Furthermore additional constructor // respective virtual C++ methods. Furthermore additional constructor
// arguments will be typically stored in the // arguments will be typically stored in the
// overwrittenMethodsOnFooBarAbstract struct. // overwrittenMethodsOnFooBarAbstract struct.
om := &amp;overwrittenMethodsOnFooBarAbstract{} om := &amp;overwrittenMethodsOnFooBarAbstract{}
fb := NewDirectorFooBarAbstract(om) fb := NewDirectorFooBarAbstract(om)
om.fb = fb // Backlink causes cycle as fb.v = om! om.fb = fb // Backlink causes cycle as fb.v = om!
fbgs := &amp;fooBarGo{FooBarAbstract: fb} fbgs := &amp;fooBarGo{FooBarAbstract: fb}
// The memory of the FooBarAbstract director object instance can be // The memory of the FooBarAbstract director object instance can be
// automatically freed once the FooBarGo instance is garbage collected by // automatically freed once the FooBarGo instance is garbage collected by
// uncommenting the following line. Please make sure to understand the // uncommenting the following line. Please make sure to understand the
// runtime.SetFinalizer specific gotchas before doing this. Furthemore // runtime.SetFinalizer specific gotchas before doing this. Furthemore
// DeleteFooBarGo should be deleted if a finalizer is in use or the fooBarGo // DeleteFooBarGo should be deleted if a finalizer is in use or the fooBarGo
// struct needs additional data to prevent double deletion. // struct needs additional data to prevent double deletion.
// runtime.SetFinalizer(fbgs, FooBarGo.deleteFooBarAbstract) // runtime.SetFinalizer(fbgs, FooBarGo.deleteFooBarAbstract)
return fbgs return fbgs
} }
// Recommended to be removed if runtime.SetFinalizer is in use. // Recommended to be removed if runtime.SetFinalizer is in use.
func DeleteFooBarGo(fbg FooBarGo) { func DeleteFooBarGo(fbg FooBarGo) {
fbg.deleteFooBarAbstract() fbg.deleteFooBarAbstract()
} }
</pre> </pre>
</div> </div>
@ -1114,13 +1114,13 @@ For comparison the <tt>FooBarCpp</tt> class looks like this:
class FooBarCpp : public FooBarAbstract class FooBarCpp : public FooBarAbstract
{ {
protected: protected:
virtual std::string Foo() { virtual std::string Foo() {
return "C++ " + FooBarAbstract::Foo(); return "C++ " + FooBarAbstract::Foo();
} }
virtual std::string Bar() { virtual std::string Bar() {
return "C++ Bar"; return "C++ Bar";
} }
}; };
</pre> </pre>
</div> </div>

View file

@ -158,8 +158,8 @@ following module-system hack:
<div class="targetlang"> <div class="targetlang">
<pre> <pre>
(module-map (lambda (sym var) (module-map (lambda (sym var)
(module-export! (current-module) (list sym))) (module-export! (current-module) (list sym)))
(current-module)) (current-module))
</pre> </pre>
</div> </div>
@ -462,16 +462,16 @@ mapping:
<div class="code"> <div class="code">
<pre> <pre>
MAP(SWIG_MemoryError, "swig-memory-error"); MAP(SWIG_MemoryError, "swig-memory-error");
MAP(SWIG_IOError, "swig-io-error"); MAP(SWIG_IOError, "swig-io-error");
MAP(SWIG_RuntimeError, "swig-runtime-error"); MAP(SWIG_RuntimeError, "swig-runtime-error");
MAP(SWIG_IndexError, "swig-index-error"); MAP(SWIG_IndexError, "swig-index-error");
MAP(SWIG_TypeError, "swig-type-error"); MAP(SWIG_TypeError, "swig-type-error");
MAP(SWIG_DivisionByZero, "swig-division-by-zero"); MAP(SWIG_DivisionByZero, "swig-division-by-zero");
MAP(SWIG_OverflowError, "swig-overflow-error"); MAP(SWIG_OverflowError, "swig-overflow-error");
MAP(SWIG_SyntaxError, "swig-syntax-error"); MAP(SWIG_SyntaxError, "swig-syntax-error");
MAP(SWIG_ValueError, "swig-value-error"); MAP(SWIG_ValueError, "swig-value-error");
MAP(SWIG_SystemError, "swig-system-error"); MAP(SWIG_SystemError, "swig-system-error");
</pre> </pre>
</div> </div>

View file

@ -158,14 +158,16 @@ following C code:
double My_variable = 3.0; double My_variable = 3.0;
/* Compute factorial of n */ /* Compute factorial of n */
int fact(int n) { int fact(int n) {
if (n &lt;= 1) return 1; if (n &lt;= 1)
else return n*fact(n-1); return 1;
else
return n*fact(n-1);
} }
/* Compute n mod m */ /* Compute n mod m */
int my_mod(int n, int m) { int my_mod(int n, int m) {
return(n % m); return(n % m);
} }
</pre></div> </pre></div>
@ -222,8 +224,7 @@ unix &gt; <b>tclsh</b>
7.5 7.5
% %
</pre></div> </pre></div>
<p> <p>
The <tt>swig</tt> command produced a new file called The <tt>swig</tt> command produced a new file called
<tt>example_wrap.c</tt> that should be compiled along with the <tt>example_wrap.c</tt> that should be compiled along with the
<tt>example.c</tt> file. Most operating systems and scripting <tt>example.c</tt> file. Most operating systems and scripting
@ -245,8 +246,8 @@ any changes type the following (shown for Solaris):
<div class="shell"><pre> <div class="shell"><pre>
unix &gt; <b>swig -perl5 example.i</b> unix &gt; <b>swig -perl5 example.i</b>
unix &gt; <b>gcc -c example.c example_wrap.c \ unix &gt; <b>gcc -c example.c example_wrap.c \
-I/usr/local/lib/perl5/sun4-solaris/5.003/CORE</b> -I/usr/local/lib/perl5/sun4-solaris/5.003/CORE</b>
unix &gt; <b>ld -G example.o example_wrap.o -o example.so</b> # This is for Solaris unix &gt; <b>ld -G example.o example_wrap.o -o example.so</b> # This is for Solaris
unix &gt; <b>perl5.003 unix &gt; <b>perl5.003
use example; use example;
print example::fact(4), "\n"; print example::fact(4), "\n";
@ -297,7 +298,7 @@ SWIG on the C header file and specifying a module name as follows
<div class="shell"><pre> <div class="shell"><pre>
unix &gt; <b>swig -perl5 -module example example.h</b> unix &gt; <b>swig -perl5 -module example example.h</b>
unix &gt; <b>gcc -c example.c example_wrap.c \ unix &gt; <b>gcc -c example.c example_wrap.c \
-I/usr/local/lib/perl5/sun4-solaris/5.003/CORE</b> -I/usr/local/lib/perl5/sun4-solaris/5.003/CORE</b>
unix &gt; <b>ld -G example.o example_wrap.o -o example.so</b> unix &gt; <b>ld -G example.o example_wrap.o -o example.so</b>
unix &gt; <b>perl5.003 unix &gt; <b>perl5.003
use example; use example;

View file

@ -464,9 +464,9 @@ If you forget to compile and link in the SWIG wrapper file into your native libr
<div class="code"><pre> <div class="code"><pre>
$ java runme $ java runme
Exception in thread "main" java.lang.UnsatisfiedLinkError: exampleJNI.gcd(II)I Exception in thread "main" java.lang.UnsatisfiedLinkError: exampleJNI.gcd(II)I
at exampleJNI.gcd(Native Method) at exampleJNI.gcd(Native Method)
at example.gcd(example.java:12) at example.gcd(example.java:12)
at runme.main(runme.java:18) at runme.main(runme.java:18)
</pre></div> </pre></div>
<p> <p>
@ -630,11 +630,11 @@ CFLAGS = /Z7 /Od /c /nologo
JAVA_INCLUDE = -ID:\jdk1.3\include -ID:\jdk1.3\include\win32 JAVA_INCLUDE = -ID:\jdk1.3\include -ID:\jdk1.3\include\win32
java:: java::
swig -java -o $(WRAPFILE) $(INTERFACE) swig -java -o $(WRAPFILE) $(INTERFACE)
$(CC) $(CFLAGS) $(JAVA_INCLUDE) $(SRCS) $(WRAPFILE) $(CC) $(CFLAGS) $(JAVA_INCLUDE) $(SRCS) $(WRAPFILE)
set LIB=$(TOOLS)\lib set LIB=$(TOOLS)\lib
$(LINK) $(LOPT) -out:example.dll $(LIBS) example.obj example_wrap.obj $(LINK) $(LOPT) -out:example.dll $(LIBS) example.obj example_wrap.obj
javac *.java javac *.java
</pre></div> </pre></div>
<p> <p>
@ -1340,7 +1340,7 @@ member variables. For example,
<div class="code"><pre> <div class="code"><pre>
struct Vector { struct Vector {
double x,y,z; double x,y,z;
}; };
</pre></div> </pre></div>

View file

@ -349,7 +349,7 @@ It has some extras to configure <code>node-webkit</code>. See the <a href="https
</p> </p>
<p> <p>
<code>package.json</code>: <code>package.json</code>:
</p> </p>
<div class="code"> <div class="code">
<pre> <pre>
@ -369,7 +369,7 @@ The <code>'main'</code> property of <code>package.json</code> specifies a web-pa
the main window.</p> the main window.</p>
<p> <p>
<code>app.html</code>: <code>app.html</code>:
</p> </p>
<div class="code"> <div class="code">
@ -396,7 +396,7 @@ open new windows, and many more things.
</p> </p>
<p> <p>
<code>app.js</code>: <code>app.js</code>:
</p> </p>
<div class="code"> <div class="code">

View file

@ -220,19 +220,19 @@ The generated SWIG Code will be:
(cl:defconstant x (cl:ash 5 -1)) (cl:defconstant x (cl:ash 5 -1))
(cffi:defcstruct bar (cffi:defcstruct bar
(p :short) (p :short)
(q :short) (q :short)
(a :char) (a :char)
(b :char) (b :char)
(z :pointer) (z :pointer)
(n :pointer)) (n :pointer))
(cffi:defcvar ("my_struct" my_struct) (cffi:defcvar ("my_struct" my_struct)
:pointer) :pointer)
(cffi:defcstruct foo (cffi:defcstruct foo
(a :int) (a :int)
(b :pointer)) (b :pointer))
(cffi:defcfun ("pointer_func" pointer_func) :int (cffi:defcfun ("pointer_func" pointer_func) :int
(ClosureFun :pointer) (ClosureFun :pointer)
@ -248,9 +248,9 @@ The generated SWIG Code will be:
(array :pointer)) (array :pointer))
(cffi:defcenum color (cffi:defcenum color
:RED :RED
:BLUE :BLUE
:GREEN) :GREEN)
</pre></div> </pre></div>
<p> <p>
@ -336,12 +336,12 @@ The feature <i>intern_function</i> ensures that all C names are
(cl:export '#.(swig-lispify "x" 'constant)) (cl:export '#.(swig-lispify "x" 'constant))
(cffi:defcstruct #.(swig-lispify "bar" 'classname) (cffi:defcstruct #.(swig-lispify "bar" 'classname)
(#.(swig-lispify "p" 'slotname) :short) (#.(swig-lispify "p" 'slotname) :short)
(#.(swig-lispify "q" 'slotname) :short) (#.(swig-lispify "q" 'slotname) :short)
(#.(swig-lispify "a" 'slotname) :char) (#.(swig-lispify "a" 'slotname) :char)
(#.(swig-lispify "b" 'slotname) :char) (#.(swig-lispify "b" 'slotname) :char)
(#.(swig-lispify "z" 'slotname) :pointer) (#.(swig-lispify "z" 'slotname) :pointer)
(#.(swig-lispify "n" 'slotname) :pointer)) (#.(swig-lispify "n" 'slotname) :pointer))
(cl:export '#.(swig-lispify "bar" 'classname)) (cl:export '#.(swig-lispify "bar" 'classname))
@ -363,8 +363,8 @@ The feature <i>intern_function</i> ensures that all C names are
(cl:export '#.(swig-lispify "my_struct" 'variable)) (cl:export '#.(swig-lispify "my_struct" 'variable))
(cffi:defcstruct #.(swig-lispify "foo" 'classname) (cffi:defcstruct #.(swig-lispify "foo" 'classname)
(#.(swig-lispify "a" 'slotname) :int) (#.(swig-lispify "a" 'slotname) :int)
(#.(swig-lispify "b" 'slotname) :pointer)) (#.(swig-lispify "b" 'slotname) :pointer))
(cl:export '#.(swig-lispify "foo" 'classname)) (cl:export '#.(swig-lispify "foo" 'classname))
@ -388,9 +388,9 @@ The feature <i>intern_function</i> ensures that all C names are
(cl:export '#.(my-lispify "lispsort_double" 'function) 'some-other-package) (cl:export '#.(my-lispify "lispsort_double" 'function) 'some-other-package)
(cffi:defcenum #.(swig-lispify "color" 'enumname) (cffi:defcenum #.(swig-lispify "color" 'enumname)
#.(swig-lispify "RED" 'enumvalue :keyword) #.(swig-lispify "RED" 'enumvalue :keyword)
#.(swig-lispify "BLUE" 'enumvalue :keyword) #.(swig-lispify "BLUE" 'enumvalue :keyword)
#.(swig-lispify "GREEN" 'enumvalue :keyword)) #.(swig-lispify "GREEN" 'enumvalue :keyword))
(cl:export '#.(swig-lispify "color" 'enumname)) (cl:export '#.(swig-lispify "color" 'enumname))
@ -662,14 +662,14 @@ swig -clisp -help
<td>-extern-all</td> <td>-extern-all</td>
<td>If this option is given then clisp definitions for all the functions<br/> <td>If this option is given then clisp definitions for all the functions<br/>
and global variables will be created otherwise only definitions for<br/> and global variables will be created otherwise only definitions for<br/>
externed functions and variables are created. externed functions and variables are created.
</td> </td>
</tr> </tr>
<tr> <tr>
<td>-generate-typedef</td> <td>-generate-typedef</td>
<td>If this option is given then def-c-type will be used to generate<br/> <td>If this option is given then def-c-type will be used to generate<br/>
shortcuts according to the typedefs in the input. shortcuts according to the typedefs in the input.
</td> </td>
</tr> </tr>
@ -680,15 +680,15 @@ and global variables will be created otherwise only definitions for<br/>
<p> <p>
As mentioned earlier the CLISP bindings generated by SWIG may need As mentioned earlier the CLISP bindings generated by SWIG may need
some modifications. The clisp module creates a lisp file with some modifications. The clisp module creates a lisp file with
the same name as the module name. This the same name as the module name. This
lisp file contains a 'defpackage' declaration, with the lisp file contains a 'defpackage' declaration, with the
package name same as the module name. This package uses the package name same as the module name. This package uses the
'common-lisp' and 'ffi' packages. Also, package exports all 'common-lisp' and 'ffi' packages. Also, package exports all
the functions, structures and variables for which an ffi the functions, structures and variables for which an ffi
binding was generated.<br/> binding was generated.<br/>
After generating the defpackage statement, the clisp module also After generating the defpackage statement, the clisp module also
sets the default language. sets the default language.
<div class="targetlang"><pre> <div class="targetlang"><pre>
(defpackage :test (defpackage :test
@ -738,18 +738,18 @@ void test123(float x , double y);
(ffi:def-call-out pointer_func (ffi:def-call-out pointer_func
(:name "pointer_func") (:name "pointer_func")
(:arguments (ClosureFun (ffi:c-function (:arguments (arg0 (ffi:c-pointer NIL)) (:arguments (ClosureFun (ffi:c-function (:arguments (arg0 (ffi:c-pointer NIL))
(arg1 (ffi:c-pointer NIL)) (arg1 (ffi:c-pointer NIL))
(arg2 (ffi:c-pointer NIL))) (arg2 (ffi:c-pointer NIL)))
(:return-type NIL))) (:return-type NIL)))
(y ffi:int)) (y ffi:int))
(:return-type ffi:int) (:return-type ffi:int)
(:library +library-name+)) (:library +library-name+))
(ffi:def-call-out func123 (ffi:def-call-out func123
(:name "func123") (:name "func123")
(:arguments (x (ffi:c-pointer div_t)) (:arguments (x (ffi:c-pointer div_t))
(z (ffi:c-ptr (ffi:c-array (ffi:c-ptr (ffi:c-ptr ffi:int)) 100))) (z (ffi:c-ptr (ffi:c-array (ffi:c-ptr (ffi:c-ptr ffi:int)) 100)))
(y (ffi:c-ptr (ffi:c-ptr (ffi:c-array ffi:int (1000 10)))))) (y (ffi:c-ptr (ffi:c-ptr (ffi:c-array ffi:int (1000 10))))))
(:return-type ffi:int) (:return-type ffi:int)
(:library +library-name+)) (:library +library-name+))
@ -757,14 +757,14 @@ void test123(float x , double y);
(ffi:def-call-out lispsort_double (ffi:def-call-out lispsort_double
(:name "lispsort_double") (:name "lispsort_double")
(:arguments (n ffi:int) (:arguments (n ffi:int)
(array (ffi:c-ptr DOUBLE-FLOAT))) (array (ffi:c-ptr DOUBLE-FLOAT)))
(:return-type NIL) (:return-type NIL)
(:library +library-name+)) (:library +library-name+))
(ffi:def-call-out test123 (ffi:def-call-out test123
(:name "test") (:name "test")
(:arguments (x SINGLE-FLOAT) (:arguments (x SINGLE-FLOAT)
(y DOUBLE-FLOAT)) (y DOUBLE-FLOAT))
(:return-type NIL) (:return-type NIL)
(:library +library-name+)) (:library +library-name+))

View file

@ -202,8 +202,8 @@ int main(int argc,char* argv[])
return 0; return 0;
} }
L=lua_open(); L=lua_open();
luaopen_base(L); // load basic libs (eg. print) luaopen_base(L); // load basic libs (eg. print)
luaopen_example(L); // load the wrapped module luaopen_example(L); // load the wrapped module
if (luaL_loadfile(L,argv[1])==0) // load and run the file if (luaL_loadfile(L,argv[1])==0) // load and run the file
lua_pcall(L,0,0,0); lua_pcall(L,0,0,0);
else else
@ -1536,8 +1536,8 @@ function
<div class="code"><pre>%module example <div class="code"><pre>%module example
%typemap(in) int { %typemap(in) int {
$1 = (int) lua_tonumber(L,$input); $1 = (int) lua_tonumber(L,$input);
printf("Received an integer : %d\n",$1); printf("Received an integer : %d\n",$1);
} }
%inline %{ %inline %{
extern int fact(int n); extern int fact(int n);

View file

@ -56,12 +56,12 @@ Then in scheme, you can use regular struct access procedures like
<div class="code"> <div class="code">
<pre> <pre>
; suppose a function created a struct foo as ; suppose a function created a struct foo as
; (define foo (make-diag-cntrs (#x1 #x2 #x3) (make-inspector)) ; (define foo (make-diag-cntrs (#x1 #x2 #x3) (make-inspector))
; Then you can do ; Then you can do
(format "0x~x" (diag-cntrs-field1 foo)) (format "0x~x" (diag-cntrs-field1 foo))
(format "0x~x" (diag-cntrs-field2 foo)) (format "0x~x" (diag-cntrs-field2 foo))
;etc... ;etc...
</pre> </pre>
</div> </div>

View file

@ -308,19 +308,19 @@ A few functions exist which generate and return these:
<ul> <ul>
<li>caml_ptr_val receives a c_obj and returns a void *. This <li>caml_ptr_val receives a c_obj and returns a void *. This
should be used for all pointer purposes.</li> should be used for all pointer purposes.</li>
<li>caml_long_val receives a c_obj and returns a long. This <li>caml_long_val receives a c_obj and returns a long. This
should be used for most integral purposes.</li> should be used for most integral purposes.</li>
<li>caml_val_ptr receives a void * and returns a c_obj.</li> <li>caml_val_ptr receives a void * and returns a c_obj.</li>
<li>caml_val_bool receives a C int and returns a c_obj representing <li>caml_val_bool receives a C int and returns a c_obj representing
its bool value.</li> its bool value.</li>
<li>caml_val_(u)?(char|short|int|long|float|double) receives an <li>caml_val_(u)?(char|short|int|long|float|double) receives an
appropriate C value and returns a c_obj representing it.</li> appropriate C value and returns a c_obj representing it.</li>
<li>caml_val_string receives a char * and returns a string value.</li> <li>caml_val_string receives a char * and returns a string value.</li>
<li>caml_val_string_len receives a char * and a length and returns <li>caml_val_string_len receives a char * and a length and returns
a string value.</li> a string value.</li>
<li>caml_val_obj receives a void * and an object type and returns <li>caml_val_obj receives a void * and an object type and returns
a C_obj, which contains a closure giving method access.</li> a C_obj, which contains a closure giving method access.</li>
</ul> </ul>
<p> <p>
@ -544,24 +544,24 @@ into this type of function convenient.
#include &lt;stdio.h&gt; #include &lt;stdio.h&gt;
void printfloats( float *tab, int len ) { void printfloats( float *tab, int len ) {
int i; int i;
for( i = 0; i &lt; len; i++ ) { for( i = 0; i &lt; len; i++ ) {
printf( "%f ", tab[i] ); printf( "%f ", tab[i] );
} }
printf( "\n" ); printf( "\n" );
} }
%} %}
%typemap(in) (float *tab, int len) { %typemap(in) (float *tab, int len) {
int i; int i;
/* $*1_type */ /* $*1_type */
$2 = caml_array_len($input); $2 = caml_array_len($input);
$1 = ($*1_type *)malloc( $2 * sizeof( float ) ); $1 = ($*1_type *)malloc( $2 * sizeof( float ) );
for( i = 0; i &lt; $2; i++ ) { for( i = 0; i &lt; $2; i++ ) {
$1[i] = caml_double_val(caml_array_nth($input,i)); $1[i] = caml_double_val(caml_array_nth($input,i));
} }
} }
void printfloats( float *tab, int len ); void printfloats( float *tab, int len );
@ -640,7 +640,7 @@ length. Instead, use multiple returns, as in the argout_ref example.
%include &lt;stl.i&gt; %include &lt;stl.i&gt;
namespace std { namespace std {
%template(StringVector) std::vector &lt; string &gt;; %template(StringVector) std::vector &lt; string &gt;;
}; };
%include "example.h" %include "example.h"
@ -715,16 +715,16 @@ Here's a simple example using Trolltech's Qt Library:
%} %}
class QApplication { class QApplication {
public: public:
QApplication( int argc, char **argv ); QApplication( int argc, char **argv );
void setMainWidget( QWidget *widget ); void setMainWidget( QWidget *widget );
void exec(); void exec();
}; };
class QPushButton { class QPushButton {
public: public:
QPushButton( char *str, QWidget *w ); QPushButton( char *str, QWidget *w );
void resize( int x, int y ); void resize( int x, int y );
void show(); void show();
}; };
</pre></td></tr></table> </pre></td></tr></table>
@ -848,9 +848,9 @@ let triangle_class pts ob meth args =
"cover" -&gt; "cover" -&gt;
(match args with (match args with
C_list [ x_arg ; y_arg ] -&gt; C_list [ x_arg ; y_arg ] -&gt;
let xa = x_arg as float let xa = x_arg as float
and ya = y_arg as float in and ya = y_arg as float in
(point_in_triangle pts xa ya) to bool (point_in_triangle pts xa ya) to bool
| _ -&gt; raise (Failure "cover needs two double arguments.")) | _ -&gt; raise (Failure "cover needs two double arguments."))
| _ -&gt; (invoke ob) meth args ;; | _ -&gt; (invoke ob) meth args ;;

View file

@ -220,9 +220,9 @@ script such as the following:</p>
# File : Makefile.PL # File : Makefile.PL
use ExtUtils::MakeMaker; use ExtUtils::MakeMaker;
WriteMakefile( WriteMakefile(
`NAME' =&gt; `example', # Name of package `NAME' =&gt; `example', # Name of package
`LIBS' =&gt; [`-lm'], # Name of custom libraries `LIBS' =&gt; [`-lm'], # Name of custom libraries
`OBJECT' =&gt; `example.o example_wrap.o' # Object files `OBJECT' =&gt; `example.o example_wrap.o' # Object files
); );
</pre></div> </pre></div>
@ -301,7 +301,7 @@ for a dynamic module, but change the link line to something like this:
<div class="code"><pre> <div class="code"><pre>
$ gcc example.o example_wrap.o -L/usr/lib/perl/5.14/CORE \ $ gcc example.o example_wrap.o -L/usr/lib/perl/5.14/CORE \
-lperl -lsocket -lnsl -lm -o myperl -lperl -lsocket -lnsl -lm -o myperl
</pre></div> </pre></div>
<p> <p>
@ -892,9 +892,9 @@ To check to see if a value is the NULL pointer, use the
<div class="targetlang"><pre> <div class="targetlang"><pre>
if (defined($ptr)) { if (defined($ptr)) {
print "Not a NULL pointer."; print "Not a NULL pointer.";
} else { } else {
print "Is a NULL pointer."; print "Is a NULL pointer.";
} }
</pre></div> </pre></div>
@ -917,9 +917,9 @@ dereference them as follows:
<div class="targetlang"><pre> <div class="targetlang"><pre>
if ($$a == $$b) { if ($$a == $$b) {
print "a and b point to the same thing in C"; print "a and b point to the same thing in C";
} else { } else {
print "a and b point to different objects."; print "a and b point to different objects.";
} }
</pre></div> </pre></div>
@ -978,7 +978,7 @@ accessor functions as described in the "SWIG Basics" chapter. For example,
<div class="code"><pre> <div class="code"><pre>
struct Vector { struct Vector {
double x,y,z; double x,y,z;
}; };
</pre></div> </pre></div>
@ -1259,17 +1259,17 @@ The following C++ operators are currently supported by the Perl module:
</p> </p>
<ul> <ul>
<li>operator++ </li> <li>operator++</li>
<li>operator-- </li> <li>operator--</li>
<li>operator+ </li> <li>operator+</li>
<li>operator- </li> <li>operator-</li>
<li>operator* </li> <li>operator*</li>
<li>operator/ </li> <li>operator/</li>
<li>operator== </li> <li>operator==</li>
<li>operator!= </li> <li>operator!=</li>
<li>operator% </li> <li>operator%</li>
<li>operator&gt; </li> <li>operator&gt;</li>
<li>operator&lt; </li> <li>operator&lt;</li>
<li>operator and </li> <li>operator and </li>
<li>operator or </li> <li>operator or </li>
</ul> </ul>
@ -1783,8 +1783,8 @@ you might define a typemap like this:
%module example %module example
%typemap(in) int { %typemap(in) int {
$1 = (int) SvIV($input); $1 = (int) SvIV($input);
printf("Received an integer : %d\n", $1); printf("Received an integer : %d\n", $1);
} }
... ...
%inline %{ %inline %{
@ -1829,8 +1829,8 @@ the typemap system follows <tt>typedef</tt> declarations. For example:
<div class="targetlang"> <div class="targetlang">
<pre> <pre>
%typemap(in) int n { %typemap(in) int n {
$1 = (int) SvIV($input); $1 = (int) SvIV($input);
printf("n = %d\n",$1); printf("n = %d\n",$1);
} }
%inline %{ %inline %{
typedef int Integer; typedef int Integer;
@ -2143,47 +2143,47 @@ reference to be used as a char ** datatype.
// This tells SWIG to treat char ** as a special case // This tells SWIG to treat char ** as a special case
%typemap(in) char ** { %typemap(in) char ** {
AV *tempav; AV *tempav;
I32 len; I32 len;
int i; int i;
SV **tv; SV **tv;
if (!SvROK($input)) if (!SvROK($input))
croak("Argument $argnum is not a reference."); croak("Argument $argnum is not a reference.");
if (SvTYPE(SvRV($input)) != SVt_PVAV) if (SvTYPE(SvRV($input)) != SVt_PVAV)
croak("Argument $argnum is not an array."); croak("Argument $argnum is not an array.");
tempav = (AV*)SvRV($input); tempav = (AV*)SvRV($input);
len = av_len(tempav); len = av_len(tempav);
$1 = (char **) malloc((len+2)*sizeof(char *)); $1 = (char **) malloc((len+2)*sizeof(char *));
for (i = 0; i &lt;= len; i++) { for (i = 0; i &lt;= len; i++) {
tv = av_fetch(tempav, i, 0); tv = av_fetch(tempav, i, 0);
$1[i] = (char *) SvPV(*tv,PL_na); $1[i] = (char *) SvPV(*tv,PL_na);
} }
$1[i] = NULL; $1[i] = NULL;
}; };
// This cleans up the char ** array after the function call // This cleans up the char ** array after the function call
%typemap(freearg) char ** { %typemap(freearg) char ** {
free($1); free($1);
} }
// Creates a new Perl array and places a NULL-terminated char ** into it // Creates a new Perl array and places a NULL-terminated char ** into it
%typemap(out) char ** { %typemap(out) char ** {
AV *myav; AV *myav;
SV **svs; SV **svs;
int i = 0,len = 0; int i = 0,len = 0;
/* Figure out how many elements we have */ /* Figure out how many elements we have */
while ($1[len]) while ($1[len])
len++; len++;
svs = (SV **) malloc(len*sizeof(SV *)); svs = (SV **) malloc(len*sizeof(SV *));
for (i = 0; i &lt; len ; i++) { for (i = 0; i &lt; len ; i++) {
svs[i] = sv_newmortal(); svs[i] = sv_newmortal();
sv_setpv((SV*)svs[i],$1[i]); sv_setpv((SV*)svs[i],$1[i]);
}; };
myav = av_make(len,svs); myav = av_make(len,svs);
free(svs); free(svs);
$result = newRV_noinc((SV*)myav); $result = newRV_noinc((SV*)myav);
sv_2mortal($result); sv_2mortal($result);
argvi++; argvi++;
} }
// Now a few test functions // Now a few test functions
@ -2240,12 +2240,12 @@ can be done using the <tt>EXTEND()</tt> macro as in:
<div class="code"><pre> <div class="code"><pre>
%typemap(argout) int *OUTPUT { %typemap(argout) int *OUTPUT {
if (argvi &gt;= items) { if (argvi &gt;= items) {
EXTEND(sp,1); /* Extend the stack by 1 object */ EXTEND(sp,1); /* Extend the stack by 1 object */
} }
$result = sv_newmortal(); $result = sv_newmortal();
sv_setiv($target,(IV) *($1)); sv_setiv($target,(IV) *($1));
argvi++; argvi++;
} }
</pre></div> </pre></div>
@ -2264,24 +2264,24 @@ its arguments. This example describes the implementation of the <tt>OUTPUT</tt>
// an output value. // an output value.
%typemap(argout) double *OUTPUT { %typemap(argout) double *OUTPUT {
$result = sv_newmortal(); $result = sv_newmortal();
sv_setnv($result, *$input); sv_setnv($result, *$input);
argvi++; /* Increment return count -- important! */ argvi++; /* Increment return count -- important! */
} }
// We don't care what the input value is. Ignore, but set to a temporary variable // We don't care what the input value is. Ignore, but set to a temporary variable
%typemap(in,numinputs=0) double *OUTPUT(double junk) { %typemap(in,numinputs=0) double *OUTPUT(double junk) {
$1 = &amp;junk; $1 = &amp;junk;
} }
// Now a function to test it // Now a function to test it
%{ %{
/* Returns the first two input arguments */ /* Returns the first two input arguments */
int multout(double a, double b, double *out1, double *out2) { int multout(double a, double b, double *out1, double *out2) {
*out1 = a; *out1 = a;
*out2 = b; *out2 = b;
return 0; return 0;
}; };
%} %}
@ -2377,7 +2377,7 @@ have a C function that modifies its arguments like this:
<div class="code"><pre> <div class="code"><pre>
void add(double a, double b, double *c) { void add(double a, double b, double *c) {
*c = a + b; *c = a + b;
} }
</pre></div> </pre></div>
@ -2558,9 +2558,9 @@ Suppose you have the following SWIG interface file:
<div class="code"><pre> <div class="code"><pre>
%module example %module example
struct Vector { struct Vector {
Vector(double x, double y, double z); Vector(double x, double y, double z);
~Vector(); ~Vector();
double x,y,z; double x,y,z;
}; };
</pre></div> </pre></div>
@ -2610,8 +2610,9 @@ sub DESTROY {
my $self = tied(%{$_[0]}); my $self = tied(%{$_[0]});
delete $ITERATORS{$self}; delete $ITERATORS{$self};
if (exists $OWNER{$self}) { if (exists $OWNER{$self}) {
examplec::delete_Vector($self)); examplec::delete_Vector($self));
delete $OWNER{$self}; delete $OWNER{$self};
}
} }
sub FETCH { sub FETCH {
@ -2663,8 +2664,8 @@ $v-&gt;{x} = 7.5;
# Assignment of all members # Assignment of all members
%$v = ( x=&gt;3, %$v = ( x=&gt;3,
y=&gt;9, y=&gt;9,
z=&gt;-2); z=&gt;-2);
# Reading members # Reading members
$x = $v-&gt;{x}; $x = $v-&gt;{x};
@ -2685,7 +2686,7 @@ problem---suppose you had a function like this:
<div class="code"><pre> <div class="code"><pre>
Vector *Vector_get(Vector *v, int index) { Vector *Vector_get(Vector *v, int index) {
return &amp;v[i]; return &amp;v[i];
} }
</pre></div> </pre></div>
@ -2698,9 +2699,9 @@ Vector object:
<div class="code"><pre> <div class="code"><pre>
Vector *new_Vector(double x, double y, double z) { Vector *new_Vector(double x, double y, double z) {
Vector *v; Vector *v;
v = new Vector(x,y,z); // Call C++ constructor v = new Vector(x,y,z); // Call C++ constructor
return v; return v;
} }
</pre></div> </pre></div>
@ -2770,10 +2771,10 @@ Suppose that we have a new object that looks like this:
<div class="code"><pre> <div class="code"><pre>
struct Particle { struct Particle {
Vector r; Vector r;
Vector v; Vector v;
Vector f; Vector f;
int type; int type;
} }
</pre></div> </pre></div>
@ -2789,9 +2790,9 @@ look like this (along with some supporting code):
package Particle; package Particle;
... ...
%BLESSEDMEMBERS = ( %BLESSEDMEMBERS = (
r =&gt; `Vector', r =&gt; `Vector',
v =&gt; `Vector', v =&gt; `Vector',
f =&gt; `Vector', f =&gt; `Vector',
); );
</pre></div> </pre></div>
@ -2867,23 +2868,23 @@ interface file:
class Shape { class Shape {
public: public:
virtual double area() = 0; virtual double area() = 0;
virtual double perimeter() = 0; virtual double perimeter() = 0;
void set_location(double x, double y); void set_location(double x, double y);
}; };
class Circle : public Shape { class Circle : public Shape {
public: public:
Circle(double radius); Circle(double radius);
~Circle(); ~Circle();
double area(); double area();
double perimeter(); double perimeter();
}; };
class Square : public Shape { class Square : public Shape {
public: public:
Square(double size); Square(double size);
~Square(); ~Square();
double area(); double area();
double perimeter(); double perimeter();
} }
</pre></div> </pre></div>

View file

@ -136,8 +136,8 @@ least work for Linux though):
</p> </p>
<div class="code"><pre> <div class="code"><pre>
gcc `php-config --includes` -fpic -c example_wrap.c example.c gcc `php-config --includes` -fpic -c example_wrap.c example.c
gcc -shared example_wrap.o example.o -o example.so gcc -shared example_wrap.o example.o -o example.so
</pre></div> </pre></div>
<H3><a name="Php_nn1_3">34.1.2 Using PHP Extensions</a></H3> <H3><a name="Php_nn1_3">34.1.2 Using PHP Extensions</a></H3>
@ -150,7 +150,7 @@ load it. To do this, add a line like this to the <tt>[PHP]</tt> section of
</p> </p>
<div class="code"><pre> <div class="code"><pre>
extension=/path/to/modulename.so extension=/path/to/modulename.so
</pre></div> </pre></div>
<p> <p>
@ -165,7 +165,7 @@ PHP script which uses your extension:
</p> </p>
<div class="code"><pre> <div class="code"><pre>
dl("/path/to/modulename.so"); // Load the module dl("/path/to/modulename.so"); // Load the module
</pre></div> </pre></div>
<p> <p>
@ -180,7 +180,7 @@ call for you if the extension isn't already loaded:
</p> </p>
<div class="code"><pre> <div class="code"><pre>
include("example.php"); include("example.php");
</pre></div> </pre></div>
<p> <p>
@ -249,7 +249,7 @@ For example,
<div class="code"><pre> <div class="code"><pre>
%module example %module example
#define EASY_TO_MISPELL 0 #define EASY_TO_MISPELL 0
</pre> </pre>
</div> </div>
@ -262,9 +262,9 @@ accessed incorrectly in PHP,
include("example.php"); include("example.php");
if(EASY_TO_MISPEL) { if(EASY_TO_MISPEL) {
.... ...
} else { } else {
.... ...
} }
</pre> </pre>
@ -303,7 +303,7 @@ is accessed as follows:
<div class="code"><pre> <div class="code"><pre>
include("example.php"); include("example.php");
print seki_get(); print seki_get();
seki_set( seki_get() * 2); # The C variable is now 4. seki_set( seki_get() * 2); # The C variable is now 4.
print seki_get(); print seki_get();
</pre></div> </pre></div>
@ -348,7 +348,7 @@ Will be accessed in PHP like this :
include("example.php"); include("example.php");
$a = foo(2); $a = foo(2);
$b = bar(3.5, -1.5); $b = bar(3.5, -1.5);
$c = bar(3.5); # Use default argument for 2nd parameter $c = bar(3.5); # Use default argument for 2nd parameter
</pre></div> </pre></div>
@ -599,10 +599,10 @@ This interface file
class Vector { class Vector {
public: public:
double x,y,z; double x,y,z;
Vector(); Vector();
~Vector(); ~Vector();
double magnitude(); double magnitude();
}; };
struct Complex { struct Complex {
@ -722,7 +722,7 @@ returns the current value of the class variable. For example
%module example %module example
class Ko { class Ko {
static int threats; static int threats;
}; };
</pre></div> </pre></div>

View file

@ -466,9 +466,9 @@ $ swig -python example.i
$ gcc example.c example_wrap.c \ $ gcc example.c example_wrap.c \
-Xlinker -export-dynamic \ -Xlinker -export-dynamic \
-DHAVE_CONFIG_H -I/usr/local/include/python2.1 \ -DHAVE_CONFIG_H -I/usr/local/include/python2.1 \
-I/usr/local/lib/python2.1/config \ -I/usr/local/lib/python2.1/config \
-L/usr/local/lib/python2.1/config -lpython2.1 -lm -ldl \ -L/usr/local/lib/python2.1/config -lpython2.1 -lm -ldl \
-o mypython -o mypython
</pre></div> </pre></div>
<p> <p>
@ -1286,7 +1286,7 @@ a very natural interface. For example,
<div class="code"><pre> <div class="code"><pre>
struct Vector { struct Vector {
double x,y,z; double x,y,z;
}; };
</pre></div> </pre></div>
@ -4310,8 +4310,8 @@ you might define a typemap like this:
%module example %module example
%typemap(in) int { %typemap(in) int {
$1 = (int) PyLong_AsLong($input); $1 = (int) PyLong_AsLong($input);
printf("Received an integer : %d\n",$1); printf("Received an integer : %d\n",$1);
} }
%inline %{ %inline %{
extern int fact(int n); extern int fact(int n);
@ -4348,11 +4348,11 @@ You can refine this by supplying an optional parameter name. For example:
%module example %module example
%typemap(in) int nonnegative { %typemap(in) int nonnegative {
$1 = (int) PyLong_AsLong($input); $1 = (int) PyLong_AsLong($input);
if ($1 &lt; 0) { if ($1 &lt; 0) {
PyErr_SetString(PyExc_ValueError,"Expected a nonnegative value."); PyErr_SetString(PyExc_ValueError,"Expected a nonnegative value.");
return NULL; return NULL;
} }
} }
%inline %{ %inline %{
extern int fact(int nonnegative); extern int fact(int nonnegative);
@ -4374,8 +4374,8 @@ the typemap system follows <tt>typedef</tt> declarations. For example:
<div class="code"> <div class="code">
<pre> <pre>
%typemap(in) int n { %typemap(in) int n {
$1 = (int) PyLong_AsLong($input); $1 = (int) PyLong_AsLong($input);
printf("n = %d\n",$1); printf("n = %d\n",$1);
} }
%inline %{ %inline %{
typedef int Integer; typedef int Integer;
@ -4685,11 +4685,11 @@ object to be used as a <tt>char **</tt> object.
for (i = 0; i &lt; size; i++) { for (i = 0; i &lt; size; i++) {
PyObject *o = PyList_GetItem($input,i); PyObject *o = PyList_GetItem($input,i);
if (PyString_Check(o)) if (PyString_Check(o))
$1[i] = PyString_AsString(PyList_GetItem($input,i)); $1[i] = PyString_AsString(PyList_GetItem($input,i));
else { else {
PyErr_SetString(PyExc_TypeError,"list must contain strings"); PyErr_SetString(PyExc_TypeError,"list must contain strings");
free($1); free($1);
return NULL; return NULL;
} }
} }
$1[i] = 0; $1[i] = 0;
@ -4784,11 +4784,11 @@ previous example:
for (i = 0; i &lt; $1; i++) { for (i = 0; i &lt; $1; i++) {
PyObject *o = PyList_GetItem($input,i); PyObject *o = PyList_GetItem($input,i);
if (PyString_Check(o)) if (PyString_Check(o))
$2[i] = PyString_AsString(PyList_GetItem($input,i)); $2[i] = PyString_AsString(PyList_GetItem($input,i));
else { else {
PyErr_SetString(PyExc_TypeError,"list must contain strings"); PyErr_SetString(PyExc_TypeError,"list must contain strings");
free($2); free($2);
return NULL; return NULL;
} }
} }
$2[i] = 0; $2[i] = 0;
@ -4832,10 +4832,10 @@ arguments rather than in the return value of a function. For example:
<div class="code"><pre> <div class="code"><pre>
/* Returns a status value and two values in out1 and out2 */ /* Returns a status value and two values in out1 and out2 */
int spam(double a, double b, double *out1, double *out2) { int spam(double a, double b, double *out1, double *out2) {
... Do a bunch of stuff ... ... Do a bunch of stuff ...
*out1 = result1; *out1 = result1;
*out2 = result2; *out2 = result2;
return status; return status;
} }
</pre></div> </pre></div>

View file

@ -4190,10 +4190,10 @@ this:
<pre>function_name(int x, int y, Foo foo=nil, Bar bar=nil) -&gt; bool <pre>function_name(int x, int y, Foo foo=nil, Bar bar=nil) -&gt; bool
Parameters: Parameters:
x - int x - int
y - int y - int
foo - Foo foo - Foo
bar - Bar</pre> bar - Bar</pre>
</div> </div>
<H4><a name="Ruby_nn70">38.8.2.5 %feature("autodoc", "docstring")</a></H4> <H4><a name="Ruby_nn70">38.8.2.5 %feature("autodoc", "docstring")</a></H4>
@ -5251,8 +5251,7 @@ existing Ruby object to the destroyed C++ object and raise an exception.
#include "example.h" #include "example.h"
%} %}
/* Specify that ownership is transferred to the zoo /* Specify that ownership is transferred to the zoo when calling add_animal */
when calling add_animal */
%apply SWIGTYPE *DISOWN { Animal* animal }; %apply SWIGTYPE *DISOWN { Animal* animal };
/* Track objects */ /* Track objects */

View file

@ -1037,15 +1037,14 @@ expect :</p>
<div class="targetlang"><pre> <div class="targetlang"><pre>
# Copy a file # Copy a file
def filecopy(source,target): def filecopy(source,target):
f1 = fopen(source,"r") f1 = fopen(source,"r")
f2 = fopen(target,"w") f2 = fopen(target,"w")
buffer = malloc(8192) buffer = malloc(8192)
nbytes = fread(buffer,8192,1,f1) nbytes = fread(buffer,8192,1,f1)
while (nbytes &gt; 0): while (nbytes &gt; 0):
fwrite(buffer,8192,1,f2) fwrite(buffer,8192,1,f2)
nbytes = fread(buffer,8192,1,f1) nbytes = fread(buffer,8192,1,f1)
free(buffer) free(buffer)
</pre></div> </pre></div>
<p> <p>
@ -1315,10 +1314,10 @@ gets mapped to an underlying pair of set/get functions like this :</p>
<div class="code"><pre> <div class="code"><pre>
Vector *unit_i_get() { Vector *unit_i_get() {
return &amp;unit_i; return &amp;unit_i;
} }
void unit_i_set(Vector *value) { void unit_i_set(Vector *value) {
unit_i = *value; unit_i = *value;
} }
</pre></div> </pre></div>
@ -1605,11 +1604,11 @@ directive as shown :</p>
<div class="code"><pre> <div class="code"><pre>
// File : interface.i // File : interface.i
int a; // Can read/write int a; // Can read/write
%immutable; %immutable;
int b,c,d // Read only variables int b,c,d; // Read only variables
%mutable; %mutable;
double x,y // read/write double x,y; // read/write
</pre></div> </pre></div>
<p> <p>
@ -2129,8 +2128,8 @@ default arguments are optional in the target language. For example, this functio
used in Tcl as follows :</p> used in Tcl as follows :</p>
<div class="targetlang"><pre> <div class="targetlang"><pre>
% plot -3.4 7.5 # Use default value % plot -3.4 7.5 # Use default value
% plot -3.4 7.5 10 # set color to 10 instead % plot -3.4 7.5 10 # set color to 10 instead
</pre></div> </pre></div>
@ -2320,7 +2319,7 @@ to an individual member. For example, the declaration :</p>
<div class="code"><pre> <div class="code"><pre>
struct Vector { struct Vector {
double x,y,z; double x,y,z;
} }
</pre></div> </pre></div>
@ -2330,22 +2329,22 @@ gets transformed into the following set of accessor functions :</p>
<div class="code"><pre> <div class="code"><pre>
double Vector_x_get(struct Vector *obj) { double Vector_x_get(struct Vector *obj) {
return obj-&gt;x; return obj-&gt;x;
} }
double Vector_y_get(struct Vector *obj) { double Vector_y_get(struct Vector *obj) {
return obj-&gt;y; return obj-&gt;y;
} }
double Vector_z_get(struct Vector *obj) { double Vector_z_get(struct Vector *obj) {
return obj-&gt;z; return obj-&gt;z;
} }
void Vector_x_set(struct Vector *obj, double value) { void Vector_x_set(struct Vector *obj, double value) {
obj-&gt;x = value; obj-&gt;x = value;
} }
void Vector_y_set(struct Vector *obj, double value) { void Vector_y_set(struct Vector *obj, double value) {
obj-&gt;y = value; obj-&gt;y = value;
} }
void Vector_z_set(struct Vector *obj, double value) { void Vector_z_set(struct Vector *obj, double value) {
obj-&gt;z = value; obj-&gt;z = value;
} }
</pre></div> </pre></div>
@ -2393,7 +2392,7 @@ programs :</p>
<div class="code"><pre> <div class="code"><pre>
typedef struct { typedef struct {
double x,y,z; double x,y,z;
} Vector; } Vector;
</pre></div> </pre></div>
@ -2408,7 +2407,7 @@ that the use of <tt>typedef</tt> allows SWIG to drop the
<div class="code"> <div class="code">
<pre> <pre>
double Vector_x_get(Vector *obj) { double Vector_x_get(Vector *obj) {
return obj-&gt;x; return obj-&gt;x;
} }
</pre> </pre>
</div> </div>
@ -2418,7 +2417,7 @@ If two different names are used like this :</p>
<div class="code"><pre> <div class="code"><pre>
typedef struct vector_struct { typedef struct vector_struct {
double x,y,z; double x,y,z;
} Vector; } Vector;
</pre></div> </pre></div>
@ -2444,8 +2443,8 @@ will be released, and the new contents allocated. For example :</p>
%module mymodule %module mymodule
... ...
struct Foo { struct Foo {
char *name; char *name;
... ...
} }
</pre></div> </pre></div>
@ -2455,14 +2454,15 @@ This results in the following accessor functions :</p>
<div class="code"><pre> <div class="code"><pre>
char *Foo_name_get(Foo *obj) { char *Foo_name_get(Foo *obj) {
return Foo-&gt;name; return Foo-&gt;name;
} }
char *Foo_name_set(Foo *obj, char *c) { char *Foo_name_set(Foo *obj, char *c) {
if (obj-&gt;name) free(obj-&gt;name); if (obj-&gt;name)
obj-&gt;name = (char *) malloc(strlen(c)+1); free(obj-&gt;name);
strcpy(obj-&gt;name,c); obj-&gt;name = (char *) malloc(strlen(c)+1);
return obj-&gt;name; strcpy(obj-&gt;name,c);
return obj-&gt;name;
} }
</pre></div> </pre></div>
@ -2714,7 +2714,7 @@ the following declaration :</p>
/* file : vector.h */ /* file : vector.h */
... ...
typedef struct Vector { typedef struct Vector {
double x,y,z; double x,y,z;
} Vector; } Vector;
</pre></div> </pre></div>
@ -2732,23 +2732,23 @@ You can make a <tt>Vector</tt> look a lot like a class by writing a SWIG interfa
%include "vector.h" // Just grab original C header file %include "vector.h" // Just grab original C header file
%extend Vector { // Attach these functions to struct Vector %extend Vector { // Attach these functions to struct Vector
Vector(double x, double y, double z) { Vector(double x, double y, double z) {
Vector *v; Vector *v;
v = (Vector *) malloc(sizeof(Vector)); v = (Vector *) malloc(sizeof(Vector));
v-&gt;x = x; v-&gt;x = x;
v-&gt;y = y; v-&gt;y = y;
v-&gt;z = z; v-&gt;z = z;
return v; return v;
} }
~Vector() { ~Vector() {
free($self); free($self);
} }
double magnitude() { double magnitude() {
return sqrt($self-&gt;x*$self-&gt;x+$self-&gt;y*$self-&gt;y+$self-&gt;z*$self-&gt;z); return sqrt($self-&gt;x*$self-&gt;x+$self-&gt;y*$self-&gt;y+$self-&gt;z*$self-&gt;z);
} }
void print() { void print() {
printf("Vector [%g, %g, %g]\n", $self-&gt;x,$self-&gt;y,$self-&gt;z); printf("Vector [%g, %g, %g]\n", $self-&gt;x,$self-&gt;y,$self-&gt;z);
} }
}; };
</pre></div> </pre></div>
@ -2787,12 +2787,12 @@ of the Vector structure. For example:</p>
%} %}
typedef struct Vector { typedef struct Vector {
double x,y,z; double x,y,z;
%extend { %extend {
Vector(double x, double y, double z) { ... } Vector(double x, double y, double z) { ... }
~Vector() { ... } ~Vector() { ... }
... ...
} }
} Vector; } Vector;
</pre></div> </pre></div>
@ -2806,19 +2806,19 @@ example :</p>
/* Vector methods */ /* Vector methods */
#include "vector.h" #include "vector.h"
Vector *new_Vector(double x, double y, double z) { Vector *new_Vector(double x, double y, double z) {
Vector *v; Vector *v;
v = (Vector *) malloc(sizeof(Vector)); v = (Vector *) malloc(sizeof(Vector));
v-&gt;x = x; v-&gt;x = x;
v-&gt;y = y; v-&gt;y = y;
v-&gt;z = z; v-&gt;z = z;
return v; return v;
} }
void delete_Vector(Vector *v) { void delete_Vector(Vector *v) {
free(v); free(v);
} }
double Vector_magnitude(Vector *v) { double Vector_magnitude(Vector *v) {
return sqrt(v-&gt;x*v-&gt;x+v-&gt;y*v-&gt;y+v-&gt;z*v-&gt;z); return sqrt(v-&gt;x*v-&gt;x+v-&gt;y*v-&gt;y+v-&gt;z*v-&gt;z);
} }
// File : vector.i // File : vector.i
@ -2829,13 +2829,13 @@ double Vector_magnitude(Vector *v) {
%} %}
typedef struct Vector { typedef struct Vector {
double x,y,z; double x,y,z;
%extend { %extend {
Vector(int,int,int); // This calls new_Vector() Vector(int,int,int); // This calls new_Vector()
~Vector(); // This calls delete_Vector() ~Vector(); // This calls delete_Vector()
double magnitude(); // This will call Vector_magnitude() double magnitude(); // This will call Vector_magnitude()
... ...
} }
} Vector; } Vector;
</pre> </pre>
</div> </div>
@ -2847,13 +2847,13 @@ For example:
<div class="code"><pre> <div class="code"><pre>
typedef struct Integer { typedef struct Integer {
int value; int value;
} Int; } Int;
%extend Integer { ... } /* Correct name */ %extend Integer { ... } /* Correct name */
%extend Int { ... } /* Incorrect name */ %extend Int { ... } /* Incorrect name */
struct Float { struct Float {
float value; float value;
}; };
typedef struct Float FloatValue; typedef struct Float FloatValue;
%extend Float { ... } /* Correct name */ %extend Float { ... } /* Correct name */
@ -2866,7 +2866,7 @@ There is one exception to this rule and that is when the struct is anonymously n
<div class="code"><pre> <div class="code"><pre>
typedef struct { typedef struct {
double value; double value;
} Double; } Double;
%extend Double { ... } /* Okay */ %extend Double { ... } /* Okay */
</pre></div> </pre></div>
@ -2975,13 +2975,13 @@ Occasionally, a C program will involve structures like this :</p>
<div class="code"><pre> <div class="code"><pre>
typedef struct Object { typedef struct Object {
int objtype; int objtype;
union { union {
int ivalue; int ivalue;
double dvalue; double dvalue;
char *strvalue; char *strvalue;
void *ptrvalue; void *ptrvalue;
} intRep; } intRep;
} Object; } Object;
</pre></div> </pre></div>
@ -2993,15 +2993,15 @@ following:</p>
<div class="code"><pre> <div class="code"><pre>
typedef union { typedef union {
int ivalue; int ivalue;
double dvalue; double dvalue;
char *strvalue; char *strvalue;
void *ptrvalue; void *ptrvalue;
} Object_intRep; } Object_intRep;
typedef struct Object { typedef struct Object {
int objType; int objType;
Object_intRep intRep; Object_intRep intRep;
} Object; } Object;
</pre></div> </pre></div>
@ -3013,16 +3013,16 @@ structures. In this case, functions like this would be created :</p>
<div class="code"><pre> <div class="code"><pre>
Object_intRep *Object_intRep_get(Object *o) { Object_intRep *Object_intRep_get(Object *o) {
return (Object_intRep *) &amp;o-&gt;intRep; return (Object_intRep *) &amp;o-&gt;intRep;
} }
int Object_intRep_ivalue_get(Object_intRep *o) { int Object_intRep_ivalue_get(Object_intRep *o) {
return o-&gt;ivalue; return o-&gt;ivalue;
} }
int Object_intRep_ivalue_set(Object_intRep *o, int value) { int Object_intRep_ivalue_set(Object_intRep *o, int value) {
return (o-&gt;ivalue = value); return (o-&gt;ivalue = value);
} }
double Object_intRep_dvalue_get(Object_intRep *o) { double Object_intRep_dvalue_get(Object_intRep *o) {
return o-&gt;dvalue; return o-&gt;dvalue;
} }
... etc ... ... etc ...
@ -3229,7 +3229,7 @@ program. For example :</p>
%{ %{
/* Create a new vector */ /* Create a new vector */
static Vector *new_Vector() { static Vector *new_Vector() {
return (Vector *) malloc(sizeof(Vector)); return (Vector *) malloc(sizeof(Vector));
} }
%} %}
@ -3249,7 +3249,7 @@ there is a special inlined form of code block that is used as follows
%inline %{ %inline %{
/* Create a new vector */ /* Create a new vector */
Vector *new_Vector() { Vector *new_Vector() {
return (Vector *) malloc(sizeof(Vector)); return (Vector *) malloc(sizeof(Vector));
} }
%} %}
@ -3275,7 +3275,7 @@ initialization on module loading, you could write this:
<div class="code"><pre> <div class="code"><pre>
%init %{ %init %{
init_variables(); init_variables();
%} %}
</pre></div> </pre></div>

View file

@ -530,10 +530,10 @@ functions such as the following :</p>
<div class="code"><pre> <div class="code"><pre>
List * new_List(void) { List * new_List(void) {
return new List; return new List;
} }
void delete_List(List *l) { void delete_List(List *l) {
delete l; delete l;
} }
</pre></div> </pre></div>
@ -874,7 +874,7 @@ All member functions are roughly translated into accessor functions like this :<
<div class="code"><pre> <div class="code"><pre>
int List_search(List *obj, char *value) { int List_search(List *obj, char *value) {
return obj-&gt;search(value); return obj-&gt;search(value);
} }
</pre></div> </pre></div>
@ -912,11 +912,11 @@ structures. A pair of accessor functions are effectively created. For example
<div class="code"><pre> <div class="code"><pre>
int List_length_get(List *obj) { int List_length_get(List *obj) {
return obj-&gt;length; return obj-&gt;length;
} }
int List_length_set(List *obj, int value) { int List_length_set(List *obj, int value) {
obj-&gt;length = value; obj-&gt;length = value;
return value; return value;
} }
</pre></div> </pre></div>
@ -933,7 +933,7 @@ class List {
public: public:
... ...
%immutable; %immutable;
int length; int length;
%mutable; %mutable;
... ...
}; };
@ -1231,7 +1231,7 @@ into constants with the classname as a prefix. For example :</p>
<div class="code"><pre> <div class="code"><pre>
class Swig { class Swig {
public: public:
enum {ALE, LAGER, PORTER, STOUT}; enum {ALE, LAGER, PORTER, STOUT};
}; };
</pre></div> </pre></div>
@ -1321,7 +1321,7 @@ a declaration like this :</p>
<div class="code"><pre> <div class="code"><pre>
class Foo { class Foo {
public: public:
double bar(double &amp;a); double bar(double &amp;a);
} }
</pre></div> </pre></div>
@ -1331,7 +1331,7 @@ has a low-level accessor
<div class="code"><pre> <div class="code"><pre>
double Foo_bar(Foo *obj, double *a) { double Foo_bar(Foo *obj, double *a) {
obj-&gt;bar(*a); obj-&gt;bar(*a);
} }
</pre></div> </pre></div>
@ -1550,24 +1550,24 @@ the full C++ code has been omitted.</p>
class Shape { class Shape {
public: public:
double x,y; double x,y;
virtual double area() = 0; virtual double area() = 0;
virtual double perimeter() = 0; virtual double perimeter() = 0;
void set_location(double x, double y); void set_location(double x, double y);
}; };
class Circle : public Shape { class Circle : public Shape {
public: public:
Circle(double radius); Circle(double radius);
~Circle(); ~Circle();
double area(); double area();
double perimeter(); double perimeter();
}; };
class Square : public Shape { class Square : public Shape {
public: public:
Square(double size); Square(double size);
~Square(); ~Square();
double area(); double area();
double perimeter(); double perimeter();
} }
</pre></div> </pre></div>
@ -2615,7 +2615,7 @@ public:
} }
Complex operator*(const Complex &amp;c) const { Complex operator*(const Complex &amp;c) const {
return Complex(rpart*c.rpart - ipart*c.ipart, return Complex(rpart*c.rpart - ipart*c.ipart,
rpart*c.ipart + c.rpart*ipart); rpart*c.ipart + c.rpart*ipart);
} }
Complex operator-() const { Complex operator-() const {
return Complex(-rpart, -ipart); return Complex(-rpart, -ipart);
@ -2788,17 +2788,17 @@ example :
class Vector { class Vector {
public: public:
double x,y,z; double x,y,z;
Vector(); Vector();
~Vector(); ~Vector();
... bunch of C++ methods ... ... bunch of C++ methods ...
%extend { %extend {
char *__str__() { char *__str__() {
static char temp[256]; static char temp[256];
sprintf(temp,"[ %g, %g, %g ]", $self-&gt;x,$self-&gt;y,$self-&gt;z); sprintf(temp,"[ %g, %g, %g ]", $self-&gt;x,$self-&gt;y,$self-&gt;z);
return &amp;temp[0]; return &amp;temp[0];
} }
} }
}; };
</pre></div> </pre></div>
@ -4696,11 +4696,11 @@ public:
return add_ref(); return add_ref();
} }
int unref() const { int unref() const {
if (ref_count() == 0 || del_ref() == 0 ) { if (ref_count() == 0 || del_ref() == 0 ) {
delete this; delete this;
return 0; return 0;
} }
return ref_count(); return ref_count();
} }
}; };

View file

@ -102,8 +102,10 @@ Suppose you have an ordinary C function like this :</p>
<div class="code"><pre> <div class="code"><pre>
int fact(int n) { int fact(int n) {
if (n &lt;= 1) return 1; if (n &lt;= 1)
else return n*fact(n-1); return 1;
else
return n*fact(n-1);
} }
</pre></div> </pre></div>
@ -124,18 +126,17 @@ As an example, the Tcl wrapper function for the <tt>fact()</tt>
function above example might look like the following : </p> function above example might look like the following : </p>
<div class="code"><pre> <div class="code"><pre>
int wrap_fact(ClientData clientData, Tcl_Interp *interp, int wrap_fact(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) {
int argc, char *argv[]) { int result;
int result; int arg0;
int arg0; if (argc != 2) {
if (argc != 2) { interp-&gt;result = "wrong # args";
interp-&gt;result = "wrong # args"; return TCL_ERROR;
return TCL_ERROR; }
} arg0 = atoi(argv[1]);
arg0 = atoi(argv[1]); result = fact(arg0);
result = fact(arg0); sprintf(interp-&gt;result,"%d", result);
sprintf(interp-&gt;result,"%d", result); return TCL_OK;
return TCL_OK;
} }
</pre></div> </pre></div>
@ -149,9 +150,9 @@ requires code like the following :</p>
<div class="code"><pre> <div class="code"><pre>
int Wrap_Init(Tcl_Interp *interp) { int Wrap_Init(Tcl_Interp *interp) {
Tcl_CreateCommand(interp, "fact", wrap_fact, (ClientData) NULL, Tcl_CreateCommand(interp, "fact", wrap_fact, (ClientData) NULL,
(Tcl_CmdDeleteProc *) NULL); (Tcl_CmdDeleteProc *) NULL);
return TCL_OK; return TCL_OK;
} }
</pre></div> </pre></div>
@ -244,9 +245,9 @@ representation of a structure. For example,
<div class="code"><pre> <div class="code"><pre>
struct Vector { struct Vector {
Vector(); Vector();
~Vector(); ~Vector();
double x,y,z; double x,y,z;
}; };
</pre></div> </pre></div>
@ -299,9 +300,9 @@ have the following C++ definition :</p>
<div class="code"><pre> <div class="code"><pre>
class Vector { class Vector {
public: public:
Vector(); Vector();
~Vector(); ~Vector();
double x,y,z; double x,y,z;
}; };
</pre></div> </pre></div>

View file

@ -208,8 +208,8 @@ $ swig -tcl example.i
$ gcc example.c example_wrap.c \ $ gcc example.c example_wrap.c \
-Xlinker -export-dynamic \ -Xlinker -export-dynamic \
-DHAVE_CONFIG_H -I/usr/local/include/ \ -DHAVE_CONFIG_H -I/usr/local/include/ \
-L/usr/local/lib -ltcl -lm -ldl \ -L/usr/local/lib -ltcl -lm -ldl \
-o mytclsh -o mytclsh
</pre></div> </pre></div>
@ -626,11 +626,11 @@ CFLAGS = /Z7 /Od /c /nologo
TCL_INCLUDES = -Id:\tcl8.0a2\generic -Id:\tcl8.0a2\win TCL_INCLUDES = -Id:\tcl8.0a2\generic -Id:\tcl8.0a2\win
TCLLIB = d:\tcl8.0a2\win\tcl80.lib TCLLIB = d:\tcl8.0a2\win\tcl80.lib
tcl:: tcl:
..\..\swig -tcl -o $(WRAPFILE) $(INTERFACE) ..\..\swig -tcl -o $(WRAPFILE) $(INTERFACE)
$(CC) $(CFLAGS) $(TCL_INCLUDES) $(SRCS) $(WRAPFILE) $(CC) $(CFLAGS) $(TCL_INCLUDES) $(SRCS) $(WRAPFILE)
set LIB=$(TOOLS)\lib set LIB=$(TOOLS)\lib
$(LINK) $(LOPT) -out:example.dll $(LIBS) $(TCLLIB) example.obj example_wrap.obj $(LINK) $(LOPT) -out:example.dll $(LIBS) $(TCLLIB) example.obj example_wrap.obj
</pre></div> </pre></div>
@ -981,7 +981,7 @@ This provides a very natural interface. For example,
<div class="code"><pre> <div class="code"><pre>
struct Vector { struct Vector {
double x,y,z; double x,y,z;
}; };
</pre></div> </pre></div>
@ -2466,8 +2466,9 @@ you might define a typemap like this:
%module example %module example
%typemap(in) int { %typemap(in) int {
if (Tcl_GetIntFromObj(interp,$input,&amp;$1) == TCL_ERROR) return TCL_ERROR; if (Tcl_GetIntFromObj(interp,$input,&amp;$1) == TCL_ERROR)
printf("Received an integer : %d\n",$1); return TCL_ERROR;
printf("Received an integer : %d\n",$1);
} }
%inline %{ %inline %{
extern int fact(int n); extern int fact(int n);
@ -2504,8 +2505,9 @@ You can refine this by supplying an optional parameter name. For example:
%module example %module example
%typemap(in) int n { %typemap(in) int n {
if (Tcl_GetIntFromObj(interp,$input,&amp;$1) == TCL_ERROR) return TCL_ERROR; if (Tcl_GetIntFromObj(interp,$input,&amp;$1) == TCL_ERROR)
printf("n = %d\n",$1); return TCL_ERROR;
printf("n = %d\n",$1);
} }
%inline %{ %inline %{
extern int fact(int n); extern int fact(int n);
@ -2527,8 +2529,9 @@ the typemap system follows <tt>typedef</tt> declarations. For example:
<div class="code"> <div class="code">
<pre> <pre>
%typemap(in) int n { %typemap(in) int n {
if (Tcl_GetIntFromObj(interp,$input,&amp;$1) == TCL_ERROR) return TCL_ERROR; if (Tcl_GetIntFromObj(interp,$input,&amp;$1) == TCL_ERROR)
printf("n = %d\n",$1); return TCL_ERROR;
printf("n = %d\n",$1);
} }
%inline %{ %inline %{
typedef int Integer; typedef int Integer;
@ -2976,10 +2979,10 @@ work)
<div class="code"> <div class="code">
<pre> <pre>
%typemap(in) int, short, long { %typemap(in) int, short, long {
int temp; int temp;
if (Tcl_GetIntFromObj(interp, $input, &amp;temp) == TCL_ERROR) if (Tcl_GetIntFromObj(interp, $input, &amp;temp) == TCL_ERROR)
return TCL_ERROR; return TCL_ERROR;
$1 = ($1_ltype) temp; $1 = ($1_ltype) temp;
} }
</pre> </pre>
</div> </div>
@ -3154,8 +3157,8 @@ subdirectory which has the same name as the package. For example :
<div class="code"><pre> <div class="code"><pre>
./example/ ./example/
pkgIndex.tcl # The file created by pkg_mkIndex pkgIndex.tcl # The file created by pkg_mkIndex
example.so # The SWIG generated module example.so # The SWIG generated module
</pre></div> </pre></div>
<p> <p>
@ -3265,14 +3268,14 @@ Our script allows easy array access as follows :
<div class="code"><pre> <div class="code"><pre>
set a [Array double 100] ;# Create a double [100] set a [Array double 100] ;# Create a double [100]
for {set i 0} {$i &lt; 100} {incr i 1} { ;# Clear the array for {set i 0} {$i &lt; 100} {incr i 1} { ;# Clear the array
$a set $i 0.0 $a set $i 0.0
} }
$a set 3 3.1455 ;# Set an individual element $a set 3 3.1455 ;# Set an individual element
set b [$a get 10] ;# Retrieve an element set b [$a get 10] ;# Retrieve an element
set ia [Array int 50] ;# Create an int[50] set ia [Array int 50] ;# Create an int[50]
for {set i 0} {$i &lt; 50} {incr i 1} { ;# Clear it for {set i 0} {$i &lt; 50} {incr i 1} { ;# Clear it
$ia set $i 0 $ia set $i 0
} }
$ia set 3 7 ;# Set an individual element $ia set 3 7 ;# Set an individual element
set ib [$ia get 10] ;# Get an individual element set ib [$ia get 10] ;# Get an individual element

View file

@ -3051,8 +3051,8 @@ For example, suppose you had a structure like this:
<div class="code"><pre> <div class="code"><pre>
struct SomeObject { struct SomeObject {
float value[4]; float value[4];
... ...
}; };
</pre></div> </pre></div>
@ -3166,9 +3166,9 @@ checking the values of function arguments. For example:</p>
%module math %module math
%typemap(check) double posdouble { %typemap(check) double posdouble {
if ($1 &lt; 0) { if ($1 &lt; 0) {
croak("Expecting a positive number"); croak("Expecting a positive number");
} }
} }
... ...
@ -4511,22 +4511,22 @@ The following excerpt from the Python module illustrates this:
/* Note: %typecheck(X) is a macro for %typemap(typecheck,precedence=X) */ /* Note: %typecheck(X) is a macro for %typemap(typecheck,precedence=X) */
%typecheck(SWIG_TYPECHECK_INTEGER) %typecheck(SWIG_TYPECHECK_INTEGER)
int, short, long, int, short, long,
unsigned int, unsigned short, unsigned long, unsigned int, unsigned short, unsigned long,
signed char, unsigned char, signed char, unsigned char,
long long, unsigned long long, long long, unsigned long long,
const int &amp;, const short &amp;, const long &amp;, const int &amp;, const short &amp;, const long &amp;,
const unsigned int &amp;, const unsigned short &amp;, const unsigned long &amp;, const unsigned int &amp;, const unsigned short &amp;, const unsigned long &amp;,
const long long &amp;, const unsigned long long &amp;, const long long &amp;, const unsigned long long &amp;,
enum SWIGTYPE, enum SWIGTYPE,
bool, const bool &amp; bool, const bool &amp;
{ {
$1 = (PyInt_Check($input) || PyLong_Check($input)) ? 1 : 0; $1 = (PyInt_Check($input) || PyLong_Check($input)) ? 1 : 0;
} }
%typecheck(SWIG_TYPECHECK_DOUBLE) %typecheck(SWIG_TYPECHECK_DOUBLE)
float, double, float, double,
const float &amp;, const double &amp; const float &amp;, const double &amp;
{ {
$1 = (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input)) ? 1 : 0; $1 = (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input)) ? 1 : 0;
} }

View file

@ -636,7 +636,7 @@ example. For example:
PyObject *o = PyTuple_GetItem(varargs,i); PyObject *o = PyTuple_GetItem(varargs,i);
if (!PyString_Check(o)) { if (!PyString_Check(o)) {
PyErr_SetString(PyExc_ValueError,"Expected a string"); PyErr_SetString(PyExc_ValueError,"Expected a string");
free(argv); free(argv);
return NULL; return NULL;
} }
argv[i] = PyString_AsString(o); argv[i] = PyString_AsString(o);

View file

@ -164,7 +164,7 @@ PYTHON_LIB: D:\python21\libs\python21.lib<br>
<p> <p>
<b><tt>TCL_INCLUDE</tt></b> : Set this to the directory containing tcl.h<br> <b><tt>TCL_INCLUDE</tt></b> : Set this to the directory containing tcl.h<br>
<b><tt>TCL_LIB</tt></b> : Set this to the TCL library including path for linking<p> <b><tt>TCL_LIB</tt></b> : Set this to the TCL library including path for linking<p>
Example using ActiveTcl 8.3.3.3 <br> Example using ActiveTcl 8.3.3.3<br>
<tt> <tt>
TCL_INCLUDE: D:\tcl\include<br> TCL_INCLUDE: D:\tcl\include<br>
TCL_LIB: D:\tcl\lib\tcl83.lib<br> TCL_LIB: D:\tcl\lib\tcl83.lib<br>