Some HTML error fixes
Long blockquote lines shortened git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6063 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
881e85e1cd
commit
687cfbb625
17 changed files with 233 additions and 179 deletions
|
|
@ -42,6 +42,7 @@
|
||||||
Scheme-to-C compiler supporting most of the language features as
|
Scheme-to-C compiler supporting most of the language features as
|
||||||
defined in the <i>Revised^5 Report on Scheme</i>. Its main
|
defined in the <i>Revised^5 Report on Scheme</i>. Its main
|
||||||
attributes are that it
|
attributes are that it
|
||||||
|
</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>
|
||||||
|
|
@ -49,6 +50,7 @@
|
||||||
<li>supports full tail-recursion and first-class continuations</li>
|
<li>supports full tail-recursion and first-class continuations</li>
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
|
<p>
|
||||||
When confronted with a large C library, CHICKEN users can use
|
When confronted with a large C library, CHICKEN users can use
|
||||||
SWIG to generate CHICKEN wrappers for the C library. However,
|
SWIG to generate CHICKEN wrappers for the C library. However,
|
||||||
the real advantages of using SWIG with CHICKEN are its
|
the real advantages of using SWIG with CHICKEN are its
|
||||||
|
|
@ -68,7 +70,7 @@
|
||||||
present in releases of CHICKEN with version number
|
present in releases of CHICKEN with version number
|
||||||
<strong>greater than or equal to <tt>1.40</tt></strong>.
|
<strong>greater than or equal to <tt>1.40</tt></strong>.
|
||||||
|
|
||||||
<br></br> CHICKEN can be downloaded from <a
|
<br> CHICKEN can be downloaded from <a
|
||||||
href="http://www.call-with-current-continuation.org/">http://www.call-with-current-continuation.org/</a>
|
href="http://www.call-with-current-continuation.org/">http://www.call-with-current-continuation.org/</a>
|
||||||
|
|
||||||
You may want to look at any of the examples in Examples/chicken/
|
You may want to look at any of the examples in Examples/chicken/
|
||||||
|
|
@ -137,7 +139,7 @@
|
||||||
<tt>Foo-Bar->Foo-Baz</tt>. That is, an underscore is converted
|
<tt>Foo-Bar->Foo-Baz</tt>. That is, an underscore is converted
|
||||||
to a dash and '_to_' is converted to an arrow.
|
to a dash and '_to_' is converted to an arrow.
|
||||||
|
|
||||||
<br></br>
|
<br>
|
||||||
|
|
||||||
Additionally, there is a <em>mixed</em> mode that can be
|
Additionally, there is a <em>mixed</em> mode that can be
|
||||||
specified with the <tt>-mixed</tt> option on the SWIG command
|
specified with the <tt>-mixed</tt> option on the SWIG command
|
||||||
|
|
@ -148,7 +150,7 @@
|
||||||
named <tt>someDeclaration_xyz</tt> will be available as the
|
named <tt>someDeclaration_xyz</tt> will be available as the
|
||||||
CHICKEN identifier ending with <tt>some-declaration-xyz</tt>.
|
CHICKEN identifier ending with <tt>some-declaration-xyz</tt>.
|
||||||
|
|
||||||
<br></br>
|
<br>
|
||||||
|
|
||||||
You may control what the CHICKEN identifier will be by using the
|
You may control what the CHICKEN identifier will be by using the
|
||||||
<tt>%rename</tt> SWIG directive in the SWIG interface file.
|
<tt>%rename</tt> SWIG directive in the SWIG interface file.
|
||||||
|
|
@ -162,6 +164,7 @@
|
||||||
(which has been deprecated); instead, it uses a prefix system.
|
(which has been deprecated); instead, it uses a prefix system.
|
||||||
Specifying the module name as 'example' in SWIG CHICKEN can be
|
Specifying the module name as 'example' in SWIG CHICKEN can be
|
||||||
done using either of:
|
done using either of:
|
||||||
|
</p>
|
||||||
<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>
|
||||||
|
|
@ -169,10 +172,11 @@
|
||||||
line.</li>
|
line.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<p>
|
||||||
CHICKEN will be able to access the module using the <tt>(declare
|
CHICKEN will be able to access the module using the <tt>(declare
|
||||||
(uses <i>modulename</i>))</tt> CHICKEN Scheme form.
|
(uses <i>modulename</i>))</tt> CHICKEN Scheme form.
|
||||||
|
|
||||||
<br></br>
|
<br>
|
||||||
|
|
||||||
Normally, for a C declaration <tt>Foo_Bar</tt> with a module
|
Normally, for a C declaration <tt>Foo_Bar</tt> with a module
|
||||||
name of 'example', the corresponding CHICKEN identifier will be
|
name of 'example', the corresponding CHICKEN identifier will be
|
||||||
|
|
@ -180,7 +184,7 @@
|
||||||
prefixed to the CHICKEN identifier</strong> (following normal
|
prefixed to the CHICKEN identifier</strong> (following normal
|
||||||
naming conventions).
|
naming conventions).
|
||||||
|
|
||||||
<br></br>
|
<br>
|
||||||
|
|
||||||
You may explicitly override the prefix with the SWIG command
|
You may explicitly override the prefix with the SWIG command
|
||||||
line option <tt>-prefix <i>whateverprefix</i></tt>, or you may
|
line option <tt>-prefix <i>whateverprefix</i></tt>, or you may
|
||||||
|
|
@ -194,6 +198,7 @@
|
||||||
<p>
|
<p>
|
||||||
Constants may be created using any of the four constructs in
|
Constants may be created using any of the four constructs in
|
||||||
the interface file:
|
the interface file:
|
||||||
|
</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>
|
||||||
|
|
@ -201,6 +206,7 @@
|
||||||
<li><code>enum { MYCONSTANT4 = ... };</code></li>
|
<li><code>enum { MYCONSTANT4 = ... };</code></li>
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
|
<p>
|
||||||
In all cases, the constants may be accessed from with CHICKEN
|
In all cases, the constants may be accessed from with CHICKEN
|
||||||
using the form <tt>(MYCONSTANT1)</tt>; that is, the constants
|
using the form <tt>(MYCONSTANT1)</tt>; that is, the constants
|
||||||
may be accessed using the read-only parameter form.
|
may be accessed using the read-only parameter form.
|
||||||
|
|
@ -249,7 +255,7 @@
|
||||||
system. Please consult a Scheme book if you are unfamiliar
|
system. Please consult a Scheme book if you are unfamiliar
|
||||||
with the concept.
|
with the concept.
|
||||||
|
|
||||||
<br></br>
|
<br>
|
||||||
|
|
||||||
CHICKEN has a modified version of TinyCLOS, which SWIG CHICKEN
|
CHICKEN has a modified version of TinyCLOS, which SWIG CHICKEN
|
||||||
uses in C++ mode. SWIG CHICKEN generates a
|
uses in C++ mode. SWIG CHICKEN generates a
|
||||||
|
|
@ -260,7 +266,7 @@
|
||||||
"xxx-clos")</tt> all the metaobject (class) macros your program
|
"xxx-clos")</tt> all the metaobject (class) macros your program
|
||||||
needs.
|
needs.
|
||||||
|
|
||||||
<br></br>
|
<br>
|
||||||
|
|
||||||
SWIG CHICKEN will call the destructor for all TinyCLOS objects
|
SWIG CHICKEN will call the destructor for all TinyCLOS objects
|
||||||
that are garbage-collected by CHICKEN. It also allows access to
|
that are garbage-collected by CHICKEN. It also allows access to
|
||||||
|
|
@ -337,7 +343,7 @@
|
||||||
read from <code>Lib/chicken/typemaps.i</code> and
|
read from <code>Lib/chicken/typemaps.i</code> and
|
||||||
<code>Lib/chicken/chicken.swg</code>.
|
<code>Lib/chicken/chicken.swg</code>.
|
||||||
|
|
||||||
<br></br>
|
<br>
|
||||||
|
|
||||||
Two Chicken-specific typemaps are supported:
|
Two Chicken-specific typemaps are supported:
|
||||||
<code>clos_in</code> and <code>clos_out</code>. They are for
|
<code>clos_in</code> and <code>clos_out</code>. They are for
|
||||||
|
|
@ -373,7 +379,7 @@
|
||||||
are exposed in the SWIG interface file; it "fully knows" only
|
are exposed in the SWIG interface file; it "fully knows" only
|
||||||
those classes that are not forward declarations.
|
those classes that are not forward declarations.
|
||||||
|
|
||||||
<br></br>
|
<br>
|
||||||
|
|
||||||
A real-world example of the "fully knows" problem is found in
|
A real-world example of the "fully knows" problem is found in
|
||||||
the VTK visualization library. All VTK classes are derived from
|
the VTK visualization library. All VTK classes are derived from
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ All Rights Reserved<br>
|
||||||
David M. Beazley<br>
|
David M. Beazley<br>
|
||||||
Department of Computer Science <br>
|
Department of Computer Science <br>
|
||||||
University of Utah <br>
|
University of Utah <br>
|
||||||
Salt Lake City, Utah 84112 </br>
|
Salt Lake City, Utah 84112 <br>
|
||||||
<tt>beazley@cs.utah.edu</tt>
|
<tt>beazley@cs.utah.edu</tt>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
||||||
|
|
@ -361,8 +361,6 @@ $ <b>swig -c++ -python -dump_tags example.i</b>
|
||||||
. top . include . insert (/r0/beazley/Projects/lib/swig1.3/python/python.swg:7)
|
. top . include . insert (/r0/beazley/Projects/lib/swig1.3/python/python.swg:7)
|
||||||
. top . include . insert (/r0/beazley/Projects/lib/swig1.3/python/python.swg:8)
|
. top . include . insert (/r0/beazley/Projects/lib/swig1.3/python/python.swg:8)
|
||||||
. top . include . typemap (/r0/beazley/Projects/lib/swig1.3/python/python.swg:19)
|
. top . include . typemap (/r0/beazley/Projects/lib/swig1.3/python/python.swg:19)
|
||||||
. top . include . typemap . typemapitem (/r0/beazley/Projects/lib/swig1.3/python/python.swg:19)
|
|
||||||
. top . include . typemap . typemapitem (/r0/beazley/Projects/lib/swig1.3/python/python.swg:19)
|
|
||||||
...
|
...
|
||||||
. top . include (example.i:6)
|
. top . include (example.i:6)
|
||||||
. top . include . module (example.i:2)
|
. top . include . module (example.i:2)
|
||||||
|
|
@ -1312,7 +1310,7 @@ common to see small code fragments of code generated using code like this:
|
||||||
/* Print into a string */
|
/* Print into a string */
|
||||||
String *s = NewString("");
|
String *s = NewString("");
|
||||||
Printf(s,"Hello\n");
|
Printf(s,"Hello\n");
|
||||||
for (i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++) {
|
||||||
Printf(s,"%d\n", i);
|
Printf(s,"%d\n", i);
|
||||||
}
|
}
|
||||||
...
|
...
|
||||||
|
|
@ -2155,7 +2153,7 @@ command line options, simply use code similar to this:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
void Language::main(int argc, char *argv[]) {
|
void Language::main(int argc, char *argv[]) {
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if (argv[i]) {
|
if (argv[i]) {
|
||||||
if(strcmp(argv[i],"-interface") == 0) {
|
if(strcmp(argv[i],"-interface") == 0) {
|
||||||
if (argv[i+1]) {
|
if (argv[i+1]) {
|
||||||
|
|
@ -2293,8 +2291,8 @@ int Python::top(Node *n) {
|
||||||
|
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
}
|
}
|
||||||
</blockquote>
|
|
||||||
</pre>
|
</pre>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
<a name="n37"></a><H3>26.10.6 Module I/O and wrapper skeleton</H3>
|
<a name="n37"></a><H3>26.10.6 Module I/O and wrapper skeleton</H3>
|
||||||
|
|
||||||
|
|
@ -2380,7 +2378,7 @@ might rely on it.<p>
|
||||||
Here is where you may also define an alias (but then you'll need to
|
Here is where you may also define an alias (but then you'll need to
|
||||||
kludge --- don't do this):<p>
|
kludge --- don't do this):<p>
|
||||||
|
|
||||||
<blockquote<tt>
|
<blockquote><tt>
|
||||||
skip-qux = $(skip-qux99)
|
skip-qux = $(skip-qux99)
|
||||||
</tt></blockquote><p>
|
</tt></blockquote><p>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,6 @@ This section details guile-specific support in SWIG.
|
||||||
<a name="n2"></a><H2>16.1 Meaning of "Module"</H2>
|
<a name="n2"></a><H2>16.1 Meaning of "Module"</H2>
|
||||||
|
|
||||||
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
There are three different concepts of "module" involved, defined
|
There are three different concepts of "module" involved, defined
|
||||||
separately for SWIG, Guile, and Libtool. To avoid horrible confusion,
|
separately for SWIG, Guile, and Libtool. To avoid horrible confusion,
|
||||||
|
|
@ -106,8 +104,6 @@ If that happens, there is A LOT less code duplication in the standard typemaps.<
|
||||||
<a name="n4"></a><H2>16.3 Linkage</H2>
|
<a name="n4"></a><H2>16.3 Linkage</H2>
|
||||||
|
|
||||||
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Guile support is complicated by a lack of user community cohesiveness,
|
Guile support is complicated by a lack of user community cohesiveness,
|
||||||
which manifests in multiple shared-library usage conventions. A set of
|
which manifests in multiple shared-library usage conventions. A set of
|
||||||
|
|
@ -307,8 +303,6 @@ module with code that is being wrapped. See the
|
||||||
<a name="n11"></a><H2>16.4 Underscore Folding</H2>
|
<a name="n11"></a><H2>16.4 Underscore Folding</H2>
|
||||||
|
|
||||||
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Underscores are converted to dashes in identifiers. Guile support may
|
Underscores are converted to dashes in identifiers. Guile support may
|
||||||
grow an option to inhibit this folding in the future, but no one has
|
grow an option to inhibit this folding in the future, but no one has
|
||||||
|
|
@ -321,8 +315,6 @@ functions and variables (see CHANGES).
|
||||||
<a name="n12"></a><H2>16.5 Typemaps</H2>
|
<a name="n12"></a><H2>16.5 Typemaps</H2>
|
||||||
|
|
||||||
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The Guile module handles all types via typemaps. This
|
The Guile module handles all types via typemaps. This
|
||||||
information is read from <code>Lib/guile/typemaps.i</code>.
|
information is read from <code>Lib/guile/typemaps.i</code>.
|
||||||
|
|
@ -455,8 +447,6 @@ the guile module replaces $owner with 0 or 1 depending on feature:new.</p>
|
||||||
<a name="n17"></a><H2>16.7 Exception Handling</H2>
|
<a name="n17"></a><H2>16.7 Exception Handling</H2>
|
||||||
|
|
||||||
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
SWIG code calls <code>scm_error</code> on exception, using the following
|
SWIG code calls <code>scm_error</code> on exception, using the following
|
||||||
mapping:
|
mapping:
|
||||||
|
|
@ -481,8 +471,6 @@ See Lib/exception.i for details.
|
||||||
<a name="n18"></a><H2>16.8 Procedure documentation</H2>
|
<a name="n18"></a><H2>16.8 Procedure documentation</H2>
|
||||||
|
|
||||||
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<p>If invoked with the command-line option <code>-procdoc
|
<p>If invoked with the command-line option <code>-procdoc
|
||||||
<var>file</var></code>, SWIG creates documentation strings for the
|
<var>file</var></code>, SWIG creates documentation strings for the
|
||||||
generated wrapper functions, describing the procedure signature and
|
generated wrapper functions, describing the procedure signature and
|
||||||
|
|
@ -516,8 +504,6 @@ details.
|
||||||
<a name="n19"></a><H2>16.9 Procedures with setters</H2>
|
<a name="n19"></a><H2>16.9 Procedures with setters</H2>
|
||||||
|
|
||||||
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<p>For global variables, SWIG creates a single wrapper procedure
|
<p>For global variables, SWIG creates a single wrapper procedure
|
||||||
<code>(<var>variable</var> :optional value)</code>, which is used for
|
<code>(<var>variable</var> :optional value)</code>, which is used for
|
||||||
both getting and setting the value. For struct members, SWIG creates
|
both getting and setting the value. For struct members, SWIG creates
|
||||||
|
|
@ -746,7 +732,8 @@ into the GOOPS guile-module. So if <i>Module-primitive.scm</i> is on the autolo
|
||||||
<code>%goops</code> directive can be empty. Otherwise, the <code>%goops</code> directive should contain
|
<code>%goops</code> directive can be empty. Otherwise, the <code>%goops</code> directive should contain
|
||||||
whatever code is needed to load the <i>Module-primitive.scm</i> file into guile.</li>
|
whatever code is needed to load the <i>Module-primitive.scm</i> file into guile.</li>
|
||||||
<blockquote><pre>%scheme %{ (load-extension "./foo.so" "scm_init_my_modules_foo_module") %}
|
<blockquote><pre>%scheme %{ (load-extension "./foo.so" "scm_init_my_modules_foo_module") %}
|
||||||
// only include the following definition if (my modules foo) can not be loaded automatically
|
// only include the following definition if (my modules foo) cannot
|
||||||
|
// be loaded automatically
|
||||||
%goops %{
|
%goops %{
|
||||||
(primitive-load "/path/to/foo-primitive.scm")
|
(primitive-load "/path/to/foo-primitive.scm")
|
||||||
(primitive-load "/path/to/Swig/common.scm")
|
(primitive-load "/path/to/Swig/common.scm")
|
||||||
|
|
@ -760,7 +747,8 @@ Produces the following code at the top of the generated GOOPS guile-module
|
||||||
(primitive-load "/path/to/Swig/common.scm")
|
(primitive-load "/path/to/Swig/common.scm")
|
||||||
|
|
||||||
(use-modules (oop goops) (Swig common))
|
(use-modules (oop goops) (Swig common))
|
||||||
(use-modules ((my modules foo-primitive) :renamer (symbol-prefix-proc 'primitive:)))
|
(use-modules ((my modules foo-primitive) :renamer (symbol-prefix-proc
|
||||||
|
'primitive:)))
|
||||||
|
|
||||||
</pre></blockquote>
|
</pre></blockquote>
|
||||||
|
|
||||||
|
|
@ -777,7 +765,8 @@ Produces the following code at the top of the generated GOOPS guile-module
|
||||||
(load-extension "./foo.so" "scm_init_my_modules_foo_module")
|
(load-extension "./foo.so" "scm_init_my_modules_foo_module")
|
||||||
|
|
||||||
(use-modules (oop goops) (Swig common))
|
(use-modules (oop goops) (Swig common))
|
||||||
(use-modules ((my modules foo-primitive) :renamer (symbol-prefix-proc 'primitive:)))
|
(use-modules ((my modules foo-primitive) :renamer (symbol-prefix-proc
|
||||||
|
'primitive:)))
|
||||||
|
|
||||||
</pre></blockquote>
|
</pre></blockquote>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
||||||
|
|
@ -364,7 +364,8 @@ The following exception is indicative of this:
|
||||||
|
|
||||||
<blockquote><pre>
|
<blockquote><pre>
|
||||||
$ java main
|
$ java main
|
||||||
Exception in thread "main" java.lang.UnsatisfiedLinkError: libexample.so: undefined symbol: fact
|
Exception in thread "main" java.lang.UnsatisfiedLinkError: libexample.so: undefined
|
||||||
|
symbol: fact
|
||||||
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
|
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
|
||||||
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java, Compiled Code)
|
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java, Compiled Code)
|
||||||
at java.lang.ClassLoader.loadLibrary(ClassLoader.java, Compiled Code)
|
at java.lang.ClassLoader.loadLibrary(ClassLoader.java, Compiled Code)
|
||||||
|
|
@ -398,7 +399,8 @@ compiler. For example:
|
||||||
<p>
|
<p>
|
||||||
<blockquote><pre>% swig -c++ -java example.i
|
<blockquote><pre>% swig -c++ -java example.i
|
||||||
% g++ -c -fpic example.cxx
|
% g++ -c -fpic example.cxx
|
||||||
% g++ -c -fpic example_wrap.cxx -I/usr/java/j2sdk1.4.1/include -I/usr/java/j2sdk1.4.1/include/linux
|
% g++ -c -fpic example_wrap.cxx -I/usr/java/j2sdk1.4.1/include -I/usr/java/
|
||||||
|
j2sdk1.4.1/include/linux
|
||||||
% g++ -shared example.o example_wrap.o -o libexample.so
|
% g++ -shared example.o example_wrap.o -o libexample.so
|
||||||
</pre></blockquote>
|
</pre></blockquote>
|
||||||
|
|
||||||
|
|
@ -560,7 +562,7 @@ Details of all these generated classes will unfold as you read this section.
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
The JNI (C/C++) code is generated into a file which also contains the module name, for example <tt>example_wrap.cxx</tt>
|
The JNI (C/C++) code is generated into a file which also contains the module name, for example <tt>example_wrap.cxx</tt>
|
||||||
or </tt>example_wrap.c</tt>. These C or C++ files complete the contents of the module.
|
or <tt>example_wrap.c</tt>. These C or C++ files complete the contents of the module.
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
The generated Java classes can be placed into a Java package by using the <tt>-package</tt> commandline option.
|
The generated Java classes can be placed into a Java package by using the <tt>-package</tt> commandline option.
|
||||||
|
|
@ -1514,7 +1516,8 @@ If declarations such as these appear, you will get a warning message like this:
|
||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
example.i:12: Warning(515): Overloaded method spam(unsigned short) ignored. Method spam(int) at example.i:11 used.
|
example.i:12: Warning(515): Overloaded method spam(unsigned short) ignored.
|
||||||
|
Method spam(int) at example.i:11 used.
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
|
@ -1774,10 +1777,14 @@ JNI functions. The JNI functions have to follow a particular naming convention s
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
JNIEXPORT jlong JNICALL Java_exampleJNI_new_1Foo(JNIEnv *jenv, jclass jcls);
|
JNIEXPORT jlong JNICALL Java_exampleJNI_new_1Foo(JNIEnv *jenv, jclass jcls);
|
||||||
JNIEXPORT void JNICALL Java_exampleJNI_delete_1Foo(JNIEnv *jenv, jclass jcls, jlong jarg1);
|
JNIEXPORT void JNICALL Java_exampleJNI_delete_1Foo(JNIEnv *jenv, jclass jcls,
|
||||||
JNIEXPORT void JNICALL Java_exampleJNI_set_1Foo_1x(JNIEnv *jenv, jclass jcls, jlong jarg1, jint jarg2);
|
jlong jarg1);
|
||||||
JNIEXPORT jint JNICALL Java_exampleJNI_get_1Foo_1x(JNIEnv *jenv, jclass jcls, jlong jarg1);
|
JNIEXPORT void JNICALL Java_exampleJNI_set_1Foo_1x(JNIEnv *jenv, jclass jcls,
|
||||||
JNIEXPORT jint JNICALL Java_exampleJNI_Foo_1spam(JNIEnv *jenv, jclass jcls, jlong jarg1, jint jarg2, jlong jarg3);
|
jlong jarg1, jint jarg2);
|
||||||
|
JNIEXPORT jint JNICALL Java_exampleJNI_get_1Foo_1x(JNIEnv *jenv, jclass jcls,
|
||||||
|
jlong jarg1);
|
||||||
|
JNIEXPORT jint JNICALL Java_exampleJNI_Foo_1spam(JNIEnv *jenv, jclass jcls,
|
||||||
|
jlong jarg1, jint jarg2, jlong jarg3);
|
||||||
JNIEXPORT void JNICALL Java_exampleJNI_egg(JNIEnv *jenv, jclass jcls, jlong jarg1);
|
JNIEXPORT void JNICALL Java_exampleJNI_egg(JNIEnv *jenv, jclass jcls, jlong jarg1);
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
@ -1857,7 +1864,8 @@ The pragma code appears in the generated intermediary JNI class where you would
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
[ jniclassimports pragma ]
|
[ jniclassimports pragma ]
|
||||||
[ jniclassmodifiers pragma ] jniclassname extends [ jniclassbase pragma ] implements [ jniclassinterfaces pragma ] {
|
[ jniclassmodifiers pragma ] jniclassname extends [ jniclassbase pragma ]
|
||||||
|
implements [ jniclassinterfaces pragma ] {
|
||||||
[ jniclasscode pragma ]
|
[ jniclasscode pragma ]
|
||||||
... SWIG generated native methods ...
|
... SWIG generated native methods ...
|
||||||
}
|
}
|
||||||
|
|
@ -1955,7 +1963,8 @@ The pragma code appears in the generated module class like this:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
[ moduleimports pragma ]
|
[ moduleimports pragma ]
|
||||||
[ modulemodifiers pragma ] modulename extends [ modulebase pragma ] implements [ moduleinterfaces pragma ] {
|
[ modulemodifiers pragma ] modulename extends [ modulebase pragma ]
|
||||||
|
implements [ moduleinterfaces pragma ] {
|
||||||
[ modulecode pragma ]
|
[ modulecode pragma ]
|
||||||
... SWIG generated wrapper functions ...
|
... SWIG generated wrapper functions ...
|
||||||
}
|
}
|
||||||
|
|
@ -1992,7 +2001,7 @@ public class Foo {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
if(swigCPtr != 0 && swigCMemOwn) {
|
if(swigCPtr != 0 && swigCMemOwn) {
|
||||||
exampleJNI.delete_Foo(swigCPtr);
|
exampleJNI.delete_Foo(swigCPtr);
|
||||||
swigCMemOwn = false;
|
swigCMemOwn = false;
|
||||||
}
|
}
|
||||||
|
|
@ -2173,7 +2182,7 @@ Obj obj = Factory.createObj(); // obj.swigCMemOwn = true;
|
||||||
<a name="n42"></a><H4>17.4.3.2 Inheritance</H4>
|
<a name="n42"></a><H4>17.4.3.2 Inheritance</H4>
|
||||||
|
|
||||||
|
|
||||||
Java proxy classes will mirror C++ inheritance chains. For example, given the base class <tt>Base</tt> and its derived class </tt>Derived</tt>:
|
Java proxy classes will mirror C++ inheritance chains. For example, given the base class <tt>Base</tt> and its derived class <tt>Derived</tt>:
|
||||||
|
|
||||||
<blockquote><pre>
|
<blockquote><pre>
|
||||||
class Base {
|
class Base {
|
||||||
|
|
@ -2208,7 +2217,7 @@ public class Base {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
if(swigCPtr != 0 && swigCMemOwn) {
|
if(swigCPtr != 0 && swigCMemOwn) {
|
||||||
exampleJNI.delete_Base(swigCPtr);
|
exampleJNI.delete_Base(swigCPtr);
|
||||||
swigCMemOwn = false;
|
swigCMemOwn = false;
|
||||||
}
|
}
|
||||||
|
|
@ -2245,7 +2254,7 @@ public class Derived extends Base {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
if(swigCPtr != 0 && swigCMemOwn) {
|
if(swigCPtr != 0 && swigCMemOwn) {
|
||||||
exampleJNI.delete_Derived(swigCPtr);
|
exampleJNI.delete_Derived(swigCPtr);
|
||||||
swigCMemOwn = false;
|
swigCMemOwn = false;
|
||||||
}
|
}
|
||||||
|
|
@ -2399,7 +2408,9 @@ The Java function generated is:
|
||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
public static void spam(SWIGTYPE_p_Snazzy x, SWIGTYPE_p_Snazzy y, SWIGTYPE_p_Snazzy z) { ... }
|
public static void spam(SWIGTYPE_p_Snazzy x, SWIGTYPE_p_Snazzy y, SWIGTYPE_p_Snazzy z) {
|
||||||
|
...
|
||||||
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
|
@ -2463,12 +2474,13 @@ public final class Beverage {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Beverage swigToEnum(int swigValue) {
|
public static Beverage swigToEnum(int swigValue) {
|
||||||
if (swigValue < swigValues.length && swigValues[swigValue].swigValue == swigValue)
|
if (swigValue < swigValues.length && swigValues[swigValue].swigValue == swigValue)
|
||||||
return swigValues[swigValue];
|
return swigValues[swigValue];
|
||||||
for (int i = 0; i < swigValues.length; i++)
|
for (int i = 0; i < swigValues.length; i++)
|
||||||
if (swigValues[i].swigValue == swigValue)
|
if (swigValues[i].swigValue == swigValue)
|
||||||
return swigValues[i];
|
return swigValues[i];
|
||||||
throw new IllegalArgumentException("No enum " + Beverage.class + " with value " + swigValue);
|
throw new IllegalArgumentException("No enum " + Beverage.class + " with value " +
|
||||||
|
swigValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Beverage(String swigName) {
|
private Beverage(String swigName) {
|
||||||
|
|
@ -2528,12 +2540,13 @@ public enum Beverage {
|
||||||
|
|
||||||
public static Beverage swigToEnum(int swigValue) {
|
public static Beverage swigToEnum(int swigValue) {
|
||||||
Beverage[] swigValues = Beverage.class.getEnumConstants();
|
Beverage[] swigValues = Beverage.class.getEnumConstants();
|
||||||
if (swigValue < swigValues.length && swigValues[swigValue].swigValue == swigValue)
|
if (swigValue < swigValues.length && swigValues[swigValue].swigValue == swigValue)
|
||||||
return swigValues[swigValue];
|
return swigValues[swigValue];
|
||||||
for (Beverage swigEnum : swigValues)
|
for (Beverage swigEnum : swigValues)
|
||||||
if (swigEnum.swigValue == swigValue)
|
if (swigEnum.swigValue == swigValue)
|
||||||
return swigEnum;
|
return swigEnum;
|
||||||
throw new IllegalArgumentException("No enum " + Beverage.class + " with value " + swigValue);
|
throw new IllegalArgumentException("No enum " + Beverage.class +
|
||||||
|
" with value " + swigValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Beverage() {
|
private Beverage() {
|
||||||
|
|
@ -2741,7 +2754,6 @@ void callup(DirectorBase *director) {
|
||||||
The following <code>directorDerived</code> Java class is derived from the Java proxy class <code>DirectorBase</code> and overrides <code>upcall_method()</code>.
|
The following <code>directorDerived</code> Java class is derived from the Java proxy class <code>DirectorBase</code> and overrides <code>upcall_method()</code>.
|
||||||
When C++ code invokes <code>upcall_method()</code>, the SWIG-generated C++ code redirects the call via JNI to the Java <code>directorDerived</code> subclass.
|
When C++ code invokes <code>upcall_method()</code>, the SWIG-generated C++ code redirects the call via JNI to the Java <code>directorDerived</code> subclass.
|
||||||
Naturally, the SWIG generated C++ code and the generated Java intermediate class marshall and convert arguments between C++ and Java when needed.
|
Naturally, the SWIG generated C++ code and the generated Java intermediate class marshall and convert arguments between C++ and Java when needed.
|
||||||
</p>
|
|
||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
|
|
@ -3484,7 +3496,7 @@ The following table lists the default type mapping from Java to C/C++.<p>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>bool<br> const bool & </td>
|
<td>bool<br> const bool & </td>
|
||||||
<td>boolean</td>
|
<td>boolean</td>
|
||||||
<td>jboolean</td>
|
<td>jboolean</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -3583,19 +3595,21 @@ Also note that all const references to primitive types are treated as if they ar
|
||||||
Given the following C function:
|
Given the following C function:
|
||||||
<blockquote> <pre>
|
<blockquote> <pre>
|
||||||
void func(unsigned short a, char *b, const long &c, unsigned long long d);
|
void func(unsigned short a, char *b, const long &c, unsigned long long d);
|
||||||
</blockquote> </pre>
|
</pre> </blockquote>
|
||||||
The module class method would be:
|
The module class method would be:
|
||||||
<blockquote> <pre>
|
<blockquote> <pre>
|
||||||
public static void func(int a, String b, int c, java.math.BigInteger d) {...}
|
public static void func(int a, String b, int c, java.math.BigInteger d) {...}
|
||||||
</blockquote> </pre>
|
</pre> </blockquote>
|
||||||
The intermediary JNI class would use the same types:
|
The intermediary JNI class would use the same types:
|
||||||
<blockquote> <pre>
|
<blockquote> <pre>
|
||||||
public final static native void func(int jarg1, String jarg2, int jarg3, java.math.BigInteger jarg4);
|
public final static native void func(int jarg1, String jarg2, int jarg3,
|
||||||
</blockquote> </pre>
|
java.math.BigInteger jarg4);
|
||||||
|
</pre> </blockquote>
|
||||||
and the JNI function would look like this:
|
and the JNI function would look like this:
|
||||||
<blockquote> <pre>
|
<blockquote> <pre>
|
||||||
JNIEXPORT void JNICALL Java_exampleJNI_func(JNIEnv *jenv, jclass jcls, jint jarg1, jstring jarg2, jint jarg3, jobject jarg4) {...}
|
JNIEXPORT void JNICALL Java_exampleJNI_func(JNIEnv *jenv, jclass jcls,
|
||||||
</blockquote> </pre>
|
jint jarg1, jstring jarg2, jint jarg3, jobject jarg4) {...}
|
||||||
|
</pre> </blockquote>
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
The mappings for C <tt>int</tt> and C <tt>long</tt> are appropriate for 32 bit applications which are used in the 32 bit JVMs.
|
The mappings for C <tt>int</tt> and C <tt>long</tt> are appropriate for 32 bit applications which are used in the 32 bit JVMs.
|
||||||
|
|
@ -3793,7 +3807,7 @@ The most important of these implement the mapping of C/C++ types to Java types:
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
If you are writing your own typemaps to handle a particular type, you will normally have to write a collection of them.
|
If you are writing your own typemaps to handle a particular type, you will normally have to write a collection of them.
|
||||||
The default typemaps are in "<tt>java.swg</tt>" and so might be a good place for finding typemaps to base any new ones on.</li>
|
The default typemaps are in "<tt>java.swg</tt>" and so might be a good place for finding typemaps to base any new ones on.
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The "jni", "jtype" and "jstype" typemaps are usually defined together to handle the Java to C/C++ type mapping.
|
The "jni", "jtype" and "jstype" typemaps are usually defined together to handle the Java to C/C++ type mapping.
|
||||||
|
|
@ -4158,7 +4172,8 @@ In summary the contents of the typemaps make up a proxy class like this:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
[ javaimports typemap ]
|
[ javaimports typemap ]
|
||||||
[ javaclassmodifiers typemap ] javaclassname extends [ javabase typemap ] implements [ javainterfaces typemap ] {
|
[ javaclassmodifiers typemap ] javaclassname extends [ javabase typemap ]
|
||||||
|
implements [ javainterfaces typemap ] {
|
||||||
[ javabody or javabody_derived typemap ]
|
[ javabody or javabody_derived typemap ]
|
||||||
[ javafinalize typemap ]
|
[ javafinalize typemap ]
|
||||||
public void <i>delete</i>() [ javadestruct OR javadestruct_derived typemap ]
|
public void <i>delete</i>() [ javadestruct OR javadestruct_derived typemap ]
|
||||||
|
|
@ -4176,7 +4191,8 @@ The type wrapper class is similar in construction:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
[ javaimports typemap ]
|
[ javaimports typemap ]
|
||||||
[ javaclassmodifiers typemap ] javaclassname extends [ javabase typemap ] implements [ javainterfaces typemap ] {
|
[ javaclassmodifiers typemap ] javaclassname extends [ javabase typemap ]
|
||||||
|
implements [ javainterfaces typemap ] {
|
||||||
[ javabody typemap ]
|
[ javabody typemap ]
|
||||||
[ javacode typemap ]
|
[ javacode typemap ]
|
||||||
}
|
}
|
||||||
|
|
@ -4187,7 +4203,8 @@ The enum class is also similar in construction:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
[ javaimports typemap ]
|
[ javaimports typemap ]
|
||||||
[ javaclassmodifiers typemap ] javaclassname extends [ javabase typemap ] implements [ javainterfaces typemap ] {
|
[ javaclassmodifiers typemap ] javaclassname extends [ javabase typemap ]
|
||||||
|
implements [ javainterfaces typemap ] {
|
||||||
... Enum values ...
|
... Enum values ...
|
||||||
[ javabody typemap ]
|
[ javabody typemap ]
|
||||||
[ javacode typemap ]
|
[ javacode typemap ]
|
||||||
|
|
@ -4391,7 +4408,8 @@ Practically speaking, you should create a separate SWIG interface file, which is
|
||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
%typemap("javapackage") SWIGTYPE, SWIGTYPE *, SWIGTYPE & "package.for.most.classes";
|
%typemap("javapackage") SWIGTYPE, SWIGTYPE *, SWIGTYPE &
|
||||||
|
"package.for.most.classes";
|
||||||
|
|
||||||
%typemap("javapackage") Package_2_class_one "package.for.other.classes";
|
%typemap("javapackage") Package_2_class_one "package.for.other.classes";
|
||||||
%typemap("javapackage") Package_3_class_two "package.for.another.set";
|
%typemap("javapackage") Package_3_class_two "package.for.another.set";
|
||||||
|
|
@ -4400,7 +4418,6 @@ Practically speaking, you should create a separate SWIG interface file, which is
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
The basic strategy here is to provide a default package typemap for the majority of the classes, only providing "javapackage" typemaps for the exceptions.
|
The basic strategy here is to provide a default package typemap for the majority of the classes, only providing "javapackage" typemaps for the exceptions.
|
||||||
</p>
|
|
||||||
|
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
|
@ -4498,7 +4515,7 @@ Let's consider a simple file class <tt>SimpleFile</tt> and an exception class <t
|
||||||
class FileException {
|
class FileException {
|
||||||
std::string message;
|
std::string message;
|
||||||
public:
|
public:
|
||||||
FileException(const std::string& msg) : message(msg) {}
|
FileException(const std::string& msg) : message(msg) {}
|
||||||
std::string what() {
|
std::string what() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
@ -4507,7 +4524,7 @@ public:
|
||||||
class SimpleFile {
|
class SimpleFile {
|
||||||
std::string filename;
|
std::string filename;
|
||||||
public:
|
public:
|
||||||
SimpleFile(const std::string& filename) : filename(filename) {}
|
SimpleFile(const std::string& filename) : filename(filename) {}
|
||||||
void open() throw(FileException) {
|
void open() throw(FileException) {
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
|
@ -4522,7 +4539,8 @@ The default generic "throws" typemap looks like this:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [ANY] %{
|
%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [ANY] %{
|
||||||
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "C++ $1_type exception thrown");
|
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException,
|
||||||
|
"C++ $1_type exception thrown");
|
||||||
return $null;
|
return $null;
|
||||||
%}
|
%}
|
||||||
</pre>
|
</pre>
|
||||||
|
|
@ -4616,7 +4634,8 @@ To validate every <tt>float</tt> being passed to C++, we could preceed the code
|
||||||
%module example
|
%module example
|
||||||
%typemap(javain) float "$module.CheckForNaN($javainput)"
|
%typemap(javain) float "$module.CheckForNaN($javainput)"
|
||||||
%pragma(java) modulecode=%{
|
%pragma(java) modulecode=%{
|
||||||
/** Simply returns the input value unless it is not a number, whereupon an exception is thrown. */
|
/** Simply returns the input value unless it is not a number,
|
||||||
|
whereupon an exception is thrown. */
|
||||||
static protected float CheckForNaN(float num) {
|
static protected float CheckForNaN(float num) {
|
||||||
if (Float.isNaN(num))
|
if (Float.isNaN(num))
|
||||||
throw new RuntimeException("Not a number");
|
throw new RuntimeException("Not a number");
|
||||||
|
|
@ -4634,7 +4653,8 @@ The following shows the generated code of interest:
|
||||||
public class example {
|
public class example {
|
||||||
...
|
...
|
||||||
|
|
||||||
/** Simply returns the input value unless it is not a number, whereupon an exception is thrown. */
|
/** Simply returns the input value unless it is not a number,
|
||||||
|
whereupon an exception is thrown. */
|
||||||
static protected float CheckForNaN(float num) {
|
static protected float CheckForNaN(float num) {
|
||||||
if (Float.isNaN(num))
|
if (Float.isNaN(num))
|
||||||
throw new RuntimeException("Not a number");
|
throw new RuntimeException("Not a number");
|
||||||
|
|
@ -4659,7 +4679,8 @@ Thus we can modify the pragma and the typemap for the throws clause:
|
||||||
<pre>
|
<pre>
|
||||||
%typemap(javain, throws="java.lang.Exception") float "$module.CheckForNaN($javainput)"
|
%typemap(javain, throws="java.lang.Exception") float "$module.CheckForNaN($javainput)"
|
||||||
%pragma(java) modulecode=%{
|
%pragma(java) modulecode=%{
|
||||||
/** Simply returns the input value unless it is not a number, whereupon an exception is thrown. */
|
/** Simply returns the input value unless it is not a number,
|
||||||
|
whereupon an exception is thrown. */
|
||||||
static protected float CheckForNaN(float num) throws java.lang.Exception {
|
static protected float CheckForNaN(float num) throws java.lang.Exception {
|
||||||
if (Float.isNaN(num))
|
if (Float.isNaN(num))
|
||||||
throw new RuntimeException("Not a number");
|
throw new RuntimeException("Not a number");
|
||||||
|
|
@ -4677,7 +4698,8 @@ the throws clause contains a single instance of <tt>java.lang.Exception</tt>:
|
||||||
public class example {
|
public class example {
|
||||||
...
|
...
|
||||||
|
|
||||||
/** Simply returns the input value unless it is not a number, whereupon an exception is thrown. */
|
/** Simply returns the input value unless it is not a number,
|
||||||
|
whereupon an exception is thrown. */
|
||||||
static protected float CheckForNaN(float num) throws java.lang.Exception {
|
static protected float CheckForNaN(float num) throws java.lang.Exception {
|
||||||
if (Float.isNaN(num))
|
if (Float.isNaN(num))
|
||||||
throw new RuntimeException("Not a number");
|
throw new RuntimeException("Not a number");
|
||||||
|
|
@ -4704,7 +4726,8 @@ The following SWIG interface file allows a Java String array to be used as a <tt
|
||||||
<blockquote><pre>
|
<blockquote><pre>
|
||||||
%module example
|
%module example
|
||||||
|
|
||||||
/* This tells SWIG to treat char ** as a special case when used as a parameter in a function call */
|
/* This tells SWIG to treat char ** as a special case when used as a parameter
|
||||||
|
in a function call */
|
||||||
%typemap(in) char ** (jint size) {
|
%typemap(in) char ** (jint size) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
size = (*jenv)->GetArrayLength(jenv, $input);
|
size = (*jenv)->GetArrayLength(jenv, $input);
|
||||||
|
|
@ -4752,7 +4775,8 @@ The following SWIG interface file allows a Java String array to be used as a <tt
|
||||||
%typemap(jtype) char ** "String[]"
|
%typemap(jtype) char ** "String[]"
|
||||||
%typemap(jstype) char ** "String[]"
|
%typemap(jstype) char ** "String[]"
|
||||||
|
|
||||||
/* These 2 typemaps handle the conversion of the jtype to jstype typemap type and visa versa */
|
/* These 2 typemaps handle the conversion of the jtype to jstype typemap type
|
||||||
|
and visa versa */
|
||||||
%typemap(javain) char ** "$javainput"
|
%typemap(javain) char ** "$javainput"
|
||||||
%typemap(javaout) char ** {
|
%typemap(javaout) char ** {
|
||||||
return $jnicall;
|
return $jnicall;
|
||||||
|
|
@ -5025,10 +5049,10 @@ class Ambulance : public Vehicle {
|
||||||
public:
|
public:
|
||||||
Ambulance(string volume) : vol(volume) {}
|
Ambulance(string volume) : vol(volume) {}
|
||||||
virtual void start() {
|
virtual void start() {
|
||||||
cout << "Ambulance started" << endl;
|
cout << "Ambulance started" << endl;
|
||||||
}
|
}
|
||||||
void sound_siren() {
|
void sound_siren() {
|
||||||
cout << vol << " siren sounded!" << endl;
|
cout << vol << " siren sounded!" << endl;
|
||||||
}
|
}
|
||||||
...
|
...
|
||||||
};
|
};
|
||||||
|
|
@ -5111,10 +5135,10 @@ class FireEngine : public Vehicle {
|
||||||
public:
|
public:
|
||||||
FireEngine() {}
|
FireEngine() {}
|
||||||
virtual void start() {
|
virtual void start() {
|
||||||
cout << "FireEngine started" << endl;
|
cout << "FireEngine started" << endl;
|
||||||
}
|
}
|
||||||
void roll_out_hose() {
|
void roll_out_hose() {
|
||||||
cout << "Hose rolled out" << endl;
|
cout << "Hose rolled out" << endl;
|
||||||
}
|
}
|
||||||
...
|
...
|
||||||
};
|
};
|
||||||
|
|
@ -5173,11 +5197,11 @@ Note that in this case, the Java class is constructed using JNI code rather than
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cout << "Unexpected type " << endl;
|
cout << "Unexpected type " << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$result)
|
if (!$result)
|
||||||
cout << "Failed to create new java object" << endl;
|
cout << "Failed to create new java object" << endl;
|
||||||
}
|
}
|
||||||
</pre></blockquote>
|
</pre></blockquote>
|
||||||
|
|
||||||
|
|
@ -5304,7 +5328,6 @@ This example contains some useful functionality which you may want in your code.
|
||||||
%template(VectorOfInt) std::vector<int>;
|
%template(VectorOfInt) std::vector<int>;
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
</p>
|
|
||||||
|
|
||||||
<li><i>When I pass class pointers or references through a C++ upcall and I
|
<li><i>When I pass class pointers or references through a C++ upcall and I
|
||||||
try to type cast them, Java complains with a ClassCastException. What am I
|
try to type cast them, Java complains with a ClassCastException. What am I
|
||||||
|
|
@ -5328,7 +5351,8 @@ public static void MyClass_method_upcall(MyClass self, long jarg1)
|
||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
public static void MyClass_method_upcall(MyClass self, long jarg1, Foo jarg1_object)
|
public static void MyClass_method_upcall(MyClass self, long jarg1,
|
||||||
|
Foo jarg1_object)
|
||||||
{
|
{
|
||||||
Foo darg1 = (jarg1_object != null ? jarg1_object : new Foo(jarg1, false));
|
Foo darg1 = (jarg1_object != null ? jarg1_object : new Foo(jarg1, false));
|
||||||
|
|
||||||
|
|
@ -5337,6 +5361,7 @@ public static void MyClass_method_upcall(MyClass self, long jarg1, Foo jarg1_obj
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
<p>
|
||||||
When you import a SWIG interface file containing class definitions, the classes you want to be director-enabled must be have the <code>feature("director")</code> enabled for type symmetry to work.
|
When you import a SWIG interface file containing class definitions, the classes you want to be director-enabled must be have the <code>feature("director")</code> enabled for type symmetry to work.
|
||||||
This applies even when the class being wrapped isn't a director-enabled class but takes parameters that are director-enabled classes.
|
This applies even when the class being wrapped isn't a director-enabled class but takes parameters that are director-enabled classes.
|
||||||
</p>
|
</p>
|
||||||
|
|
@ -5362,7 +5387,8 @@ public static void MyClass_method_upcall(MyClass self, long jarg1, Foo jarg1_obj
|
||||||
public class MyClassDerived {
|
public class MyClassDerived {
|
||||||
public void method_upcall(Foo foo_object)
|
public void method_upcall(Foo foo_object)
|
||||||
{
|
{
|
||||||
FooDerived derived = (foo_object != null ? (FooDerived) Foo.downcastFoo(foo_object) : null);
|
FooDerived derived = (foo_object != null ?
|
||||||
|
(FooDerived) Foo.downcastFoo(foo_object) : null);
|
||||||
/* rest of your code here */
|
/* rest of your code here */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5437,7 +5463,6 @@ public abstract class UserVisibleFoo extends Foo {
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
This doesn't prevent the user from creating subclasses derived from Foo, however, UserVisibleFoo provides the safety net that reminds the user to override the <code>method_upcall()</code> method.
|
This doesn't prevent the user from creating subclasses derived from Foo, however, UserVisibleFoo provides the safety net that reminds the user to override the <code>method_upcall()</code> method.
|
||||||
</p>
|
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<a name="odds_ends"></a>
|
<a name="odds_ends"></a>
|
||||||
|
|
@ -5562,7 +5587,8 @@ For example:
|
||||||
<blockquote><pre>
|
<blockquote><pre>
|
||||||
%native (HandRolled) void HandRolled(int, char *);
|
%native (HandRolled) void HandRolled(int, char *);
|
||||||
%{
|
%{
|
||||||
JNIEXPORT void JNICALL Java_packageName_moduleName_HandRolled(JNIEnv *, jclass, jlong, jstring);
|
JNIEXPORT void JNICALL Java_packageName_moduleName_HandRolled(JNIEnv *, jclass,
|
||||||
|
jlong, jstring);
|
||||||
%}
|
%}
|
||||||
</pre></blockquote>
|
</pre></blockquote>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -174,8 +174,9 @@ struct name {
|
||||||
~name(); // Delete pointer object
|
~name(); // Delete pointer object
|
||||||
void assign(type value); // Assign value
|
void assign(type value); // Assign value
|
||||||
type value(); // Get value
|
type value(); // Get value
|
||||||
type *cast(); // Cast the pointer to original type.
|
type *cast(); // Cast the pointer to original type
|
||||||
static name *frompointer(type *); // Create class wrapper from existing pointer
|
static name *frompointer(type *); // Create class wrapper from existing
|
||||||
|
// pointer
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
@ -300,7 +301,7 @@ function like this:
|
||||||
<pre>
|
<pre>
|
||||||
void print_array(double x[10]) {
|
void print_array(double x[10]) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++) {
|
||||||
printf("[%d] = %g\n", i, x[i]);
|
printf("[%d] = %g\n", i, x[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -347,7 +348,8 @@ struct name {
|
||||||
type getitem(int index); // Return item
|
type getitem(int index); // Return item
|
||||||
void setitem(index, type value); // Set item
|
void setitem(index, type value); // Set item
|
||||||
type *cast(); // Cast to original type
|
type *cast(); // Cast to original type
|
||||||
static name *frompointer(type *); // Create class wrapper from existing pointer
|
static name *frompointer(type *); // Create class wrapper from
|
||||||
|
// existing pointer
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
@ -554,7 +556,8 @@ Python example:
|
||||||
... a[i] = i
|
... a[i] = i
|
||||||
>>> b = cdata(a,40)
|
>>> b = cdata(a,40)
|
||||||
>>> b
|
>>> b
|
||||||
'\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\t'
|
'\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04
|
||||||
|
\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\t'
|
||||||
>>> c = intArray(10)
|
>>> c = intArray(10)
|
||||||
>>> memmove(c,b)
|
>>> memmove(c,b)
|
||||||
>>> print c[4]
|
>>> print c[4]
|
||||||
|
|
@ -1184,14 +1187,14 @@ double average(std::vector<int> v) {
|
||||||
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
|
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<double> half(const std::vector<double>& v) {
|
std::vector<double> half(const std::vector<double>& v) {
|
||||||
std::vector<double> w(v);
|
std::vector<double> w(v);
|
||||||
for (unsigned int i=0; i<w.size(); i++)
|
for (unsigned int i=0; i<w.size(); i++)
|
||||||
w[i] /= 2.0;
|
w[i] /= 2.0;
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
void halve_in_place(std::vector<double>& v) {
|
void halve_in_place(std::vector<double>& v) {
|
||||||
std::transform(v.begin(),v.end(),v.begin(),
|
std::transform(v.begin(),v.end(),v.begin(),
|
||||||
std::bind2nd(std::divides<double>(),2.0));
|
std::bind2nd(std::divides<double>(),2.0));
|
||||||
}
|
}
|
||||||
|
|
@ -1332,7 +1335,7 @@ For example:
|
||||||
%exception std::vector::getitem {
|
%exception std::vector::getitem {
|
||||||
try {
|
try {
|
||||||
$action
|
$action
|
||||||
} catch (std::out_of_range& e) {
|
} catch (std::out_of_range& e) {
|
||||||
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -438,7 +438,6 @@ There's also no support for
|
||||||
<tt>%exception</tt></a>, yet.
|
<tt>%exception</tt></a>, yet.
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Be warned:
|
Be warned:
|
||||||
|
|
@ -602,6 +601,7 @@ i.e. functions that convert values between C and Modula-3
|
||||||
and call the corresponding C function.
|
and call the corresponding C function.
|
||||||
Modula-3 wrapper functions generated by SWIG
|
Modula-3 wrapper functions generated by SWIG
|
||||||
consist of the following parts:
|
consist of the following parts:
|
||||||
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Generate <tt>PROCEDURE</tt> signature.</li>
|
<li>Generate <tt>PROCEDURE</tt> signature.</li>
|
||||||
<li>Declare local variables.</li>
|
<li>Declare local variables.</li>
|
||||||
|
|
@ -613,7 +613,6 @@ consist of the following parts:
|
||||||
<li>Free temporary storage.</li>
|
<li>Free temporary storage.</li>
|
||||||
<li>Return values.</li>
|
<li>Return values.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</p>
|
|
||||||
|
|
||||||
<table border>
|
<table border>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
@ -799,12 +798,12 @@ for the typemap library
|
||||||
.
|
.
|
||||||
For a monolithic module you might be better off
|
For a monolithic module you might be better off
|
||||||
if you add the imports directly:
|
if you add the imports directly:
|
||||||
|
</p>
|
||||||
<pre>
|
<pre>
|
||||||
%insert(m3rawintf) %{
|
%insert(m3rawintf) %{
|
||||||
IMPORT M3toC;
|
IMPORT M3toC;
|
||||||
%}
|
%}
|
||||||
</pre>
|
</pre>
|
||||||
</p>
|
|
||||||
|
|
||||||
|
|
||||||
<a name="exceptions"></a>
|
<a name="exceptions"></a>
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ a '+= b</td>
|
||||||
<tr><th colspan=2>Note that because camlp4 always recognizes <<
|
<tr><th colspan=2>Note that because camlp4 always recognizes <<
|
||||||
and >>, they are replaced by lsl and lsr in operator names.
|
and >>, they are replaced by lsl and lsr in operator names.
|
||||||
<tr><td>
|
<tr><td>
|
||||||
<i>'unop</i> object as in</br>
|
<i>'unop</i> object as in<br>
|
||||||
'! a
|
'! a
|
||||||
</td><td>
|
</td><td>
|
||||||
(invoke a) "!" C_void</td></tr>
|
(invoke a) "!" C_void</td></tr>
|
||||||
|
|
@ -474,7 +474,7 @@ into this type of function convenient.
|
||||||
void printfloats( float *tab, int len ) {
|
void printfloats( float *tab, int len ) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i = 0; i < len; i++ ) {
|
for( i = 0; i < len; i++ ) {
|
||||||
printf( "%f ", tab[i] );
|
printf( "%f ", tab[i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -487,7 +487,7 @@ void printfloats( float *tab, int len ) {
|
||||||
/* $*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 < $2; i++ ) {
|
for( i = 0; i < $2; i++ ) {
|
||||||
$1[i] = caml_double_val(caml_array_nth($input,i));
|
$1[i] = caml_double_val(caml_array_nth($input,i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -285,7 +285,9 @@ A common error received by first-time users is the following:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
use example;
|
use example;
|
||||||
Can't locate example.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005 .) at - line 1.
|
Can't locate example.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-lin
|
||||||
|
ux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/pe
|
||||||
|
rl5/site_perl/5.005 .) at - line 1.
|
||||||
BEGIN failed--compilation aborted at - line 1.
|
BEGIN failed--compilation aborted at - line 1.
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
@ -446,7 +448,8 @@ it needs to be. So you should compile the wrapper like:
|
||||||
</pre></blockquote>
|
</pre></blockquote>
|
||||||
So you could also compile the wrapper like
|
So you could also compile the wrapper like
|
||||||
<blockquote><pre>
|
<blockquote><pre>
|
||||||
% g++ -c example_wrap.cxx -I/usr/lib/perl/5.8.0/CORE `perl -e 'use Config; print $Config{ccflags}'`
|
% g++ -c example_wrap.cxx -I/usr/lib/perl/5.8.0/CORE \
|
||||||
|
`perl -e 'use Config; print $Config{ccflags}'`
|
||||||
</pre></blockquote>
|
</pre></blockquote>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
@ -1975,7 +1978,7 @@ To make the member writable, a "memberin" typemap can be used.
|
||||||
<p>
|
<p>
|
||||||
<blockquote><pre>%typemap(memberin) int [SIZE] {
|
<blockquote><pre>%typemap(memberin) int [SIZE] {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < SIZE; i++) {
|
for (i = 0; i < SIZE; i++) {
|
||||||
$1[i] = $input[i];
|
$1[i] = $input[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1992,7 +1995,7 @@ For example:
|
||||||
|
|
||||||
<blockquote><pre>%typemap(memberin) int [ANY] {
|
<blockquote><pre>%typemap(memberin) int [ANY] {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < $1_dim0; i++) {
|
for (i = 0; i < $1_dim0; i++) {
|
||||||
$1[i] = $input[i];
|
$1[i] = $input[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2091,7 +2094,7 @@ void *SWIG_MakePtr(SV *obj, void *ptr, swig_type_info *ty, int flags)</tt>
|
||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
Creates a new Perl pointer object. <tt>obj</tt> is a Perl SV that has been initialized to hold the result,
|
Creates a new Perl pointer object. <tt>obj</tt> is a Perl SV that has been initialized to hold the result,
|
||||||
<tt>ptr</tt is the pointer to convert, <tt>ty</tt> is the SWIG type descriptor structure that
|
<tt>ptr</tt> is the pointer to convert, <tt>ty</tt> is the SWIG type descriptor structure that
|
||||||
describes the type, and <tt>flags</tt> is a flag that controls properties of the conversion. <tt>flags</tt> is currently undefined
|
describes the type, and <tt>flags</tt> is a flag that controls properties of the conversion. <tt>flags</tt> is currently undefined
|
||||||
and reserved.
|
and reserved.
|
||||||
|
|
||||||
|
|
@ -2167,7 +2170,7 @@ you provided with the <tt>%module</tt> directive. Then, in place of the origina
|
||||||
SWIG creates a collection of high-level Perl wrappers. In your scripts, you will use these
|
SWIG creates a collection of high-level Perl wrappers. In your scripts, you will use these
|
||||||
high level wrappers. The wrappers, in turn, interact with the low-level procedural module.
|
high level wrappers. The wrappers, in turn, interact with the low-level procedural module.
|
||||||
|
|
||||||
<h3>Structure and class wrappers</h2>
|
<h3>Structure and class wrappers</h3>
|
||||||
|
|
||||||
Suppose you have the following SWIG interface file :<p>
|
Suppose you have the following SWIG interface file :<p>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,7 @@ dl("example.so");
|
||||||
print $seki;
|
print $seki;
|
||||||
$seki = $seki * 2; # Does not affect C variable, still equal to 2
|
$seki = $seki * 2; # Does not affect C variable, still equal to 2
|
||||||
example_func(); # Syncs C variable to PHP Variable, now both 4
|
example_func(); # Syncs C variable to PHP Variable, now both 4
|
||||||
<pre></blockquote>
|
</pre></blockquote>
|
||||||
SWIG supports global variables of all C datatypes including pointers and complex
|
SWIG supports global variables of all C datatypes including pointers and complex
|
||||||
objects.<p>
|
objects.<p>
|
||||||
|
|
||||||
|
|
@ -334,8 +334,6 @@ So, in the example above, the TEST constant was declared first, and will be stor
|
||||||
they were declared non-case sensitive, the output would be 'Hello Hello', as
|
they were declared non-case sensitive, the output would be 'Hello Hello', as
|
||||||
both point to the same value, without the case test taking place.
|
both point to the same value, without the case test taking place.
|
||||||
( Apologies, this paragraph needs rewritting to make some sense. )
|
( Apologies, this paragraph needs rewritting to make some sense. )
|
||||||
</pre>
|
|
||||||
</blockquote>
|
|
||||||
|
|
||||||
<a name="n11"></a><H3>21.2.8 Shadow classes</H3>
|
<a name="n11"></a><H3>21.2.8 Shadow classes</H3>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1180,8 +1180,6 @@ they are accessed through <tt>cvar</tt> like this:
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
</pre></blockquote>
|
|
||||||
|
|
||||||
<a name="n21"></a><H3>22.3.8 C++ inheritance</H3>
|
<a name="n21"></a><H3>22.3.8 C++ inheritance</H3>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1342,7 +1340,8 @@ If declarations such as these appear, you will get a warning message like this:
|
||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
example.i:12: Warning(509): Overloaded spam(short) is shadowed by spam(int) at example.i:11.
|
example.i:12: Warning(509): Overloaded spam(short) is shadowed by spam(int)
|
||||||
|
at example.i:11.
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
|
@ -2811,7 +2810,7 @@ Sometimes a C function expects an array to be passed as a pointer. For example,
|
||||||
<pre>
|
<pre>
|
||||||
int sumitems(int *first, int nitems) {
|
int sumitems(int *first, int nitems) {
|
||||||
int i, sum = 0;
|
int i, sum = 0;
|
||||||
for (i = 0; i < nitems; i++) {
|
for (i = 0; i < nitems; i++) {
|
||||||
sum += first[i];
|
sum += first[i];
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
|
|
@ -2977,7 +2976,7 @@ You can refine this by supplying an optional parameter name. For example:
|
||||||
|
|
||||||
%typemap(in) int nonnegative {
|
%typemap(in) int nonnegative {
|
||||||
$1 = (int) PyLong_AsLong($input);
|
$1 = (int) PyLong_AsLong($input);
|
||||||
if ($1 < 0) {
|
if ($1 < 0) {
|
||||||
PyErr_SetString(PyExc_ValueError,"Expected a nonnegative value.");
|
PyErr_SetString(PyExc_ValueError,"Expected a nonnegative value.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -3501,7 +3500,7 @@ arrays of different sizes. To do this, you might write a typemap as follows:
|
||||||
PyErr_SetString(PyExc_ValueError,"Expecting a sequence with $1_dim0 elements");
|
PyErr_SetString(PyExc_ValueError,"Expecting a sequence with $1_dim0 elements");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (i =0; i < $1_dim0; i++) {
|
for (i =0; i < $1_dim0; i++) {
|
||||||
PyObject *o = PySequence_GetItem($input,i);
|
PyObject *o = PySequence_GetItem($input,i);
|
||||||
if (!PyFloat_Check(o)) {
|
if (!PyFloat_Check(o)) {
|
||||||
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of floats");
|
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of floats");
|
||||||
|
|
@ -3541,7 +3540,7 @@ static int convert_darray(PyObject *input, double *ptr, int size) {
|
||||||
PyErr_SetString(PyExc_ValueError,"Sequence size mismatch");
|
PyErr_SetString(PyExc_ValueError,"Sequence size mismatch");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (i =0; i < size; i++) {
|
for (i =0; i < size; i++) {
|
||||||
PyObject *o = PySequence_GetItem(input,i);
|
PyObject *o = PySequence_GetItem(input,i);
|
||||||
if (!PyFloat_Check(o)) {
|
if (!PyFloat_Check(o)) {
|
||||||
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of floats");
|
PyErr_SetString(PyExc_ValueError,"Expecting a sequence of floats");
|
||||||
|
|
@ -3604,7 +3603,8 @@ is usually accessed as follows:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
Foo *f;
|
Foo *f;
|
||||||
if (SWIG_ConvertPtr($input, (void **) &f, SWIGTYPE_p_Foo, SWIG_POINTER_EXCEPTION) == -1) return NULL;
|
if (SWIG_ConvertPtr($input, (void **) &f, SWIGTYPE_p_Foo, SWIG_POINTER_EXCEPTION) == -1)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
PyObject *obj;
|
PyObject *obj;
|
||||||
obj = SWIG_NewPointerObj(f, SWIGTYPE_p_Foo, 0);
|
obj = SWIG_NewPointerObj(f, SWIGTYPE_p_Foo, 0);
|
||||||
|
|
@ -3617,7 +3617,8 @@ variable <tt>$1_descriptor</tt>. For example:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
%typemap(in) Foo * {
|
%typemap(in) Foo * {
|
||||||
if ((SWIG_ConvertPtr($input,(void **) &$1, $1_descriptor,SWIG_POINTER_EXCEPTION)) == -1) return NULL;
|
if ((SWIG_ConvertPtr($input,(void **) &$1, $1_descriptor,SWIG_POINTER_EXCEPTION)) == -1)
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
@ -3629,7 +3630,8 @@ For example:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
%typemap(in) Foo * {
|
%typemap(in) Foo * {
|
||||||
if ((SWIG_ConvertPtr($input,(void **) &$1, $descriptor(Foo *), SWIG_POINTER_EXCEPTION)) == -1) return NULL;
|
if ((SWIG_ConvertPtr($input,(void **) &$1, $descriptor(Foo *), SWIG_POINTER_EXCEPTION)) == -1)
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
|
||||||
|
|
@ -767,7 +767,10 @@ the <em>is_a?</em> relationship would fail). When SWIG processes this
|
||||||
interface file,
|
interface file,
|
||||||
you'll see a warning message like:
|
you'll see a warning message like:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>example.i:5: Warning(802): Warning for Derived: Base Base2 ignored. Multiple inheritance is not supported in Ruby.<br></pre>
|
<pre>
|
||||||
|
example.i:5: Warning(802): Warning for Derived: Base Base2 ignored.
|
||||||
|
Multiple inheritance is not supported in Ruby.
|
||||||
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
Starting with SWIG 1.3.20, the Ruby module for SWIG provides limited
|
Starting with SWIG 1.3.20, the Ruby module for SWIG provides limited
|
||||||
support
|
support
|
||||||
|
|
@ -854,7 +857,10 @@ or
|
||||||
If declarations such as these appear, you will get a warning message
|
If declarations such as these appear, you will get a warning message
|
||||||
like this:
|
like this:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>example.i:12: Warning(509): Overloaded spam(short) is shadowed by spam(int) at example.i:11.<br></pre>
|
<pre>
|
||||||
|
example.i:12: Warning(509): Overloaded spam(short) is shadowed by spam(int)
|
||||||
|
at example.i:11.
|
||||||
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
To fix this, you either need to ignore or rename one of the methods.
|
To fix this, you either need to ignore or rename one of the methods.
|
||||||
For example:
|
For example:
|
||||||
|
|
@ -1603,7 +1609,10 @@ somehow extracts the last three arguments (<i>nattributes</i>, <i>names</i>
|
||||||
and
|
and
|
||||||
<i>values</i>) needed by your C function. Let's start with the basics:
|
<i>values</i>) needed by your C function. Let's start with the basics:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br>}<br></pre>
|
<pre>
|
||||||
|
%typemap(in) (int nattributes, const char **names, const int *values)
|
||||||
|
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br>}
|
||||||
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
This <tt>%typemap</tt> directive tells SWIG that we want to match any
|
This <tt>%typemap</tt> directive tells SWIG that we want to match any
|
||||||
function declaration that
|
function declaration that
|
||||||
|
|
@ -1622,7 +1631,9 @@ and <i>val</i>) define local variables that our typemap will need.
|
||||||
next add a check for that:
|
next add a check for that:
|
||||||
</p>
|
</p>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br> <b>Check_Type($input, T_HASH);</b>
|
<pre>
|
||||||
|
%typemap(in) (int nattributes, const char **names, const int *values)
|
||||||
|
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br> <b>Check_Type($input, T_HASH);</b>
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
@ -1640,7 +1651,9 @@ get around that by calling the hash's <i>size</i> method directly and
|
||||||
converting its result
|
converting its result
|
||||||
to a C <tt>int</tt> value: </p>
|
to a C <tt>int</tt> value: </p>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> <b>$1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));</b>
|
<pre>
|
||||||
|
%typemap(in) (int nattributes, const char **names, const int *values)
|
||||||
|
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> <b>$1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));</b>
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
@ -1650,7 +1663,9 @@ third typemap arguments (i.e. the two C arrays) to <tt>NULL</tt> and
|
||||||
set the stage
|
set the stage
|
||||||
for extracting the keys and values from the hash:
|
for extracting the keys and values from the hash:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> <b>$2 = NULL;<br> $3 = NULL;<br> if ($1 > 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> }</b>
|
<pre>
|
||||||
|
%typemap(in) (int nattributes, const char **names, const int *values)
|
||||||
|
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> <b>$2 = NULL;<br> $3 = NULL;<br> if ($1 > 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> }</b>
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
@ -1662,7 +1677,9 @@ method
|
||||||
the elements
|
the elements
|
||||||
in that array:
|
in that array:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 > 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> <b>keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i < $1; i++) {<br> }</b>
|
<pre>
|
||||||
|
%typemap(in) (int nattributes, const char **names, const int *values)
|
||||||
|
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 > 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> <b>keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i < $1; i++) {<br> }</b>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
|
|
@ -1672,7 +1689,9 @@ typemap. For each element in the <i>keys_arr</i>
|
||||||
array, we want to get the key itself, as well as the value
|
array, we want to get the key itself, as well as the value
|
||||||
corresponding to that key in the hash:
|
corresponding to that key in the hash:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 > 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i < $1; i++) {<br> <b>key = rb_ary_entry(keys_arr, i);<br> val = rb_hash_aref($input, key);</b>
|
<pre>
|
||||||
|
%typemap(in) (int nattributes, const char **names, const int *values)
|
||||||
|
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 > 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i < $1; i++) {<br> <b>key = rb_ary_entry(keys_arr, i);<br> val = rb_hash_aref($input, key);</b>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1682,7 +1701,9 @@ To be safe, we should again use the <tt>Check_Type()</tt> macro to
|
||||||
confirm that the
|
confirm that the
|
||||||
key is a <tt>String</tt> and the value is a <tt>Fixnum</tt>:
|
key is a <tt>String</tt> and the value is a <tt>Fixnum</tt>:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 > 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i < $1; i++) {<br> key = rb_ary_entry(keys_arr, i);<br> val = rb_hash_aref($input, key);<br> <b>Check_Type(key, T_STRING);<br> Check_Type(val, T_FIXNUM);</b>
|
<pre>
|
||||||
|
%typemap(in) (int nattributes, const char **names, const int *values)
|
||||||
|
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 > 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i < $1; i++) {<br> key = rb_ary_entry(keys_arr, i);<br> val = rb_hash_aref($input, key);<br> <b>Check_Type(key, T_STRING);<br> Check_Type(val, T_FIXNUM);</b>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1692,7 +1713,9 @@ Finally, we can convert these Ruby objects into their C equivalents and
|
||||||
store them
|
store them
|
||||||
in our local C arrays:
|
in our local C arrays:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>%typemap(in) (int nattributes, const char **names, const int *values) (VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 > 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i < $1; i++) {<br> key = rb_ary_entry(keys_arr, i);<br> val = rb_hash_aref($input, key);<br> Check_Type(key, T_STRING);<br> Check_Type(val, T_FIXNUM);<br> <b>$2[i] = STR2CSTR(key);<br> $3[i] = NUM2INT(val);</b>
|
<pre>
|
||||||
|
%typemap(in) (int nattributes, const char **names, const int *values)
|
||||||
|
(VALUE keys_arr, int i, VALUE key, VALUE val) {<br> Check_Type($input, T_HASH);<br> $1 = NUM2INT(rb_funcall($input, rb_intern("size"), 0, NULL));<br> $2 = NULL;<br> $3 = NULL;<br> if ($1 > 0) {<br> $2 = (char **) malloc($1*sizeof(char *));<br> $3 = (int *) malloc($1*sizeof(int));<br> keys_arr = rb_funcall($input, rb_intern("keys"), 0, NULL);<br> for (i = 0; i < $1; i++) {<br> key = rb_ary_entry(keys_arr, i);<br> val = rb_hash_aref($input, key);<br> Check_Type(key, T_STRING);<br> Check_Type(val, T_FIXNUM);<br> <b>$2[i] = STR2CSTR(key);<br> $3[i] = NUM2INT(val);</b>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2310,7 +2310,7 @@ _wrap_Vector_x_get(ClientData clientData, Tcl_Interp *interp,
|
||||||
struct Vector *arg1 ;
|
struct Vector *arg1 ;
|
||||||
double result ;
|
double result ;
|
||||||
|
|
||||||
if (SWIG_GetArgs(interp, objc, objv,"p:Vector_x_get self ",&arg0,
|
if (SWIG_GetArgs(interp, objc, objv,"p:Vector_x_get self ",&arg0,
|
||||||
SWIGTYPE_p_Vector) == TCL_ERROR)
|
SWIGTYPE_p_Vector) == TCL_ERROR)
|
||||||
return TCL_ERROR;
|
return TCL_ERROR;
|
||||||
result = (double ) (arg1->x);
|
result = (double ) (arg1->x);
|
||||||
|
|
|
||||||
|
|
@ -1378,7 +1378,8 @@ or for statically typed languages like Java:
|
||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
example.i:4: Warning(516): Overloaded method foo(long) ignored. Method foo(int) at example.i:3 used.
|
example.i:4: Warning(516): Overloaded method foo(long) ignored. Method foo(int)
|
||||||
|
at example.i:3 used.
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
|
@ -1396,7 +1397,7 @@ Ambiguity problems are known to arise in the following situations:
|
||||||
<li>Floating point conversion. <tt>float</tt> and <tt>double</tt> can not be disambiguated in some languages.
|
<li>Floating point conversion. <tt>float</tt> and <tt>double</tt> can not be disambiguated in some languages.
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<li>Pointers and references. For example, <tt>Foo *</tt> and <tt>Foo &</tt>.
|
<li>Pointers and references. For example, <tt>Foo *</tt> and <tt>Foo &</tt>.
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<li>Pointers and arrays. For example, <tt>Foo *</tt> and <tt>Foo [4]</tt>.
|
<li>Pointers and arrays. For example, <tt>Foo *</tt> and <tt>Foo [4]</tt>.
|
||||||
|
|
@ -1420,7 +1421,8 @@ When wrapping an overloaded function, there is a chance that you will get an err
|
||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
example.i:3: Warning(467): Overloaded foo(int) not supported (no type checking rule for 'int').
|
example.i:3: Warning(467): Overloaded foo(int) not supported (no type checking
|
||||||
|
rule for 'int').
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
|
@ -2225,7 +2227,7 @@ template<class T> class Bar : public Foo<T> {
|
||||||
The order is important since SWIG uses the instantiation names to
|
The order is important since SWIG uses the instantiation names to
|
||||||
properly set up the inheritance hierarchy in the resulting wrapper
|
properly set up the inheritance hierarchy in the resulting wrapper
|
||||||
code (and base classes need to be wrapped before derived classes).
|
code (and base classes need to be wrapped before derived classes).
|
||||||
Don't worry--if you get the order wrong, SWIG should generate an warning message.
|
Don't worry--if you get the order wrong, SWIG should generate a warning message.
|
||||||
|
|
||||||
<P>
|
<P>
|
||||||
Occassionally, you may need to tell SWIG about base classes that are defined by templates,
|
Occassionally, you may need to tell SWIG about base classes that are defined by templates,
|
||||||
|
|
@ -2408,8 +2410,9 @@ template<class T1, class T2> struct pair {
|
||||||
T1 first;
|
T1 first;
|
||||||
T2 second;
|
T2 second;
|
||||||
pair() : first(T1()), second(T2()) { }
|
pair() : first(T1()), second(T2()) { }
|
||||||
pair(const T1 &x, const T2 &y) : first(x), second(y) { }
|
pair(const T1 &x, const T2 &y) : first(x), second(y) { }
|
||||||
template<class U1, class U2> pair(const pair<U1,U2> &x) : first(x.first),second(x.second) { }
|
template<class U1, class U2> pair(const pair<U1,U2> &x)
|
||||||
|
: first(x.first),second(x.second) { }
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
|
||||||
|
|
@ -1284,7 +1284,8 @@ If declarations such as these appear, you will get a warning message like this:
|
||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
example.i:12: Warning(509): Overloaded spam(short) is shadowed by spam(int) at example.i:11.
|
example.i:12: Warning(509): Overloaded spam(short) is shadowed by spam(int)
|
||||||
|
at example.i:11.
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
|
@ -2376,7 +2377,7 @@ used as a <tt>char **</tt> object.<p>
|
||||||
return TCL_ERROR;
|
return TCL_ERROR;
|
||||||
}
|
}
|
||||||
$1 = (char **) malloc((nitems+1)*sizeof(char *));
|
$1 = (char **) malloc((nitems+1)*sizeof(char *));
|
||||||
for (i = 0; i < nitems; i++) {
|
for (i = 0; i < nitems; i++) {
|
||||||
$1[i] = Tcl_GetStringFromObj(listobjv[i],0);
|
$1[i] = Tcl_GetStringFromObj(listobjv[i],0);
|
||||||
}
|
}
|
||||||
$1[i] = 0;
|
$1[i] = 0;
|
||||||
|
|
@ -2496,10 +2497,13 @@ void Tcl_AppendToObj(Tcl_Obj *obj, char *str, int len);
|
||||||
Tcl_Obj *Tcl_NewListObj(int objc, Tcl_Obj *objv);
|
Tcl_Obj *Tcl_NewListObj(int objc, Tcl_Obj *objv);
|
||||||
int Tcl_ListObjAppendList(Tcl_Interp *, Tcl_Obj *listPtr, Tcl_Obj *elemListPtr);
|
int Tcl_ListObjAppendList(Tcl_Interp *, Tcl_Obj *listPtr, Tcl_Obj *elemListPtr);
|
||||||
int Tcl_ListObjAppendElement(Tcl_Interp *, Tcl_Obj *listPtr, Tcl_Obj *element);
|
int Tcl_ListObjAppendElement(Tcl_Interp *, Tcl_Obj *listPtr, Tcl_Obj *element);
|
||||||
int Tcl_ListObjGetElements(Tcl_Interp *, Tcl_Obj *listPtr, int *objcPtr, Tcl_Obj ***objvPtr);
|
int Tcl_ListObjGetElements(Tcl_Interp *, Tcl_Obj *listPtr, int *objcPtr,
|
||||||
|
Tcl_Obj ***objvPtr);
|
||||||
int Tcl_ListObjLength(Tcl_Interp *, Tcl_Obj *listPtr, int *intPtr);
|
int Tcl_ListObjLength(Tcl_Interp *, Tcl_Obj *listPtr, int *intPtr);
|
||||||
int Tcl_ListObjIndex(Tcl_Interp *, Tcl_Obj *listPtr, int index, Tcl_Obj_Obj **objptr);
|
int Tcl_ListObjIndex(Tcl_Interp *, Tcl_Obj *listPtr, int index,
|
||||||
int Tcl_ListObjReplace(Tcl_Interp *, Tcl_Obj *listPtr, int first, int count, int objc, Tcl_Obj *objv);
|
Tcl_Obj_Obj **objptr);
|
||||||
|
int Tcl_ListObjReplace(Tcl_Interp *, Tcl_Obj *listPtr, int first, int count,
|
||||||
|
int objc, Tcl_Obj *objv);
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ PyObject *wrap_factorial(PyObject *self, PyObject *args) {
|
||||||
PyObject *obj1;
|
PyObject *obj1;
|
||||||
PyObject *resultobj;
|
PyObject *resultobj;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple("O:factorial", &obj1)) return NULL;
|
if (!PyArg_ParseTuple("O:factorial", &obj1)) return NULL;
|
||||||
<b><font color="#0000ff">arg1 = PyInt_AsLong(obj1);</font></b>
|
<b><font color="#0000ff">arg1 = PyInt_AsLong(obj1);</font></b>
|
||||||
result = factorial(arg1);
|
result = factorial(arg1);
|
||||||
<b><font color="#0000ff">resultobj = PyInt_FromLong(result);</font></b>
|
<b><font color="#0000ff">resultobj = PyInt_FromLong(result);</font></b>
|
||||||
|
|
@ -226,7 +226,7 @@ PyObject *wrap_gcd(PyObject *self, PyObject *args) {
|
||||||
PyObject *obj2;
|
PyObject *obj2;
|
||||||
PyObject *resultobj;
|
PyObject *resultobj;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple("OO:gcd", &obj1, &obj2)) return NULL;
|
if (!PyArg_ParseTuple("OO:gcd", &obj1, &obj2)) return NULL;
|
||||||
|
|
||||||
/* "in" typemap, argument 1 */<b><font color="#0000ff">
|
/* "in" typemap, argument 1 */<b><font color="#0000ff">
|
||||||
{
|
{
|
||||||
|
|
@ -314,7 +314,7 @@ example, you could write a typemap like this:
|
||||||
<pre>
|
<pre>
|
||||||
%typemap(in) <b><font color="#ff0000">double nonnegative</font></b> {
|
%typemap(in) <b><font color="#ff0000">double nonnegative</font></b> {
|
||||||
$1 = PyFloat_AsDouble($input);
|
$1 = PyFloat_AsDouble($input);
|
||||||
if ($1 < 0) {
|
if ($1 < 0) {
|
||||||
PyErr_SetString(PyExc_ValueError,"argument must be nonnegative.");
|
PyErr_SetString(PyExc_ValueError,"argument must be nonnegative.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -667,7 +667,7 @@ Here are some examples of valid typemap specifications:
|
||||||
%typemap(in, numinputs=0) int *output (int temp),
|
%typemap(in, numinputs=0) int *output (int temp),
|
||||||
long *output (long temp)
|
long *output (long temp)
|
||||||
{
|
{
|
||||||
$1 = &temp;
|
$1 = &temp;
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
@ -817,7 +817,7 @@ namespace std {
|
||||||
|
|
||||||
class Bar {
|
class Bar {
|
||||||
public:
|
public:
|
||||||
typedef const int & const_reference;
|
typedef const int & const_reference;
|
||||||
%typemap(out) const_reference {
|
%typemap(out) const_reference {
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
|
@ -1034,13 +1034,13 @@ Row4 [10]
|
||||||
Row4 rows[ANY]
|
Row4 rows[ANY]
|
||||||
Row4 [ANY]
|
Row4 [ANY]
|
||||||
|
|
||||||
# Reduce Row4 --> Integer[4]
|
# Reduce Row4 --> Integer[4]
|
||||||
Integer rows[10][4]
|
Integer rows[10][4]
|
||||||
Integer [10][4]
|
Integer [10][4]
|
||||||
Integer rows[ANY][ANY]
|
Integer rows[ANY][ANY]
|
||||||
Integer [ANY][ANY]
|
Integer [ANY][ANY]
|
||||||
|
|
||||||
# Reduce Integer --> int
|
# Reduce Integer --> int
|
||||||
int rows[10][4]
|
int rows[10][4]
|
||||||
int [10][4]
|
int [10][4]
|
||||||
int rows[ANY][ANY]
|
int rows[ANY][ANY]
|
||||||
|
|
@ -1066,7 +1066,7 @@ In this case, the following typemap patterns are searched for the argument <tt>f
|
||||||
fooii *x
|
fooii *x
|
||||||
fooii *
|
fooii *
|
||||||
|
|
||||||
# Reduce fooii --> foo<Integer,Integer>
|
# Reduce fooii --> foo<Integer,Integer>
|
||||||
foo<Integer,Integer> *x
|
foo<Integer,Integer> *x
|
||||||
foo<Integer,Integer> *
|
foo<Integer,Integer> *
|
||||||
|
|
||||||
|
|
@ -1111,7 +1111,7 @@ specifying rules for variations of the reserved <tt>SWIGTYPE</tt> type. For ex
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
%typemap(in) SWIGTYPE * { ... default pointer handling ... }
|
%typemap(in) SWIGTYPE * { ... default pointer handling ... }
|
||||||
%typemap(in) SWIGTYPE & { ... default reference handling ... }
|
%typemap(in) SWIGTYPE & { ... default reference handling ... }
|
||||||
%typemap(in) SWIGTYPE [] { ... default array handling ... }
|
%typemap(in) SWIGTYPE [] { ... default array handling ... }
|
||||||
%typemap(in) enum SWIGTYPE { ... default handling for enum values ... }
|
%typemap(in) enum SWIGTYPE { ... default handling for enum values ... }
|
||||||
%typemap(in) SWIGTYPE (CLASS::*) { ... default pointer member handling ... }
|
%typemap(in) SWIGTYPE (CLASS::*) { ... default pointer member handling ... }
|
||||||
|
|
@ -1180,8 +1180,8 @@ any typemaps specified for a single type. For example:
|
||||||
|
|
||||||
void foo(char *buffer, int len, int count); // (char *buffer, int len)
|
void foo(char *buffer, int len, int count); // (char *buffer, int len)
|
||||||
void bar(char *buffer, int blah); // char *buffer
|
void bar(char *buffer, int blah); // char *buffer
|
||||||
</blockquote>
|
|
||||||
</pre>
|
</pre>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
Multi-argument typemaps are also more restrictive in the way that they are matched.
|
Multi-argument typemaps are also more restrictive in the way that they are matched.
|
||||||
Currently, the first argument follows the matching rules described in the previous section,
|
Currently, the first argument follows the matching rules described in the previous section,
|
||||||
|
|
@ -1748,7 +1748,7 @@ converted. For example:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
%typemap(check) int positive {
|
%typemap(check) int positive {
|
||||||
if ($1 <= 0) {
|
if ($1 <= 0) {
|
||||||
SWIG_exception(SWIG_ValueError,"Expected positive value.");
|
SWIG_exception(SWIG_ValueError,"Expected positive value.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2243,7 +2243,7 @@ maps perform the conversion described for the above example:
|
||||||
}
|
}
|
||||||
$1 = PyList_Size($input);
|
$1 = PyList_Size($input);
|
||||||
$2 = (char **) malloc(($1+1)*sizeof(char *));
|
$2 = (char **) malloc(($1+1)*sizeof(char *));
|
||||||
for (i = 0; i < $1; i++) {
|
for (i = 0; i < $1; i++) {
|
||||||
PyObject *s = PyList_GetItem($input,i);
|
PyObject *s = PyList_GetItem($input,i);
|
||||||
if (!PyString_Check(s)) {
|
if (!PyString_Check(s)) {
|
||||||
free($2);
|
free($2);
|
||||||
|
|
@ -2258,8 +2258,8 @@ maps perform the conversion described for the above example:
|
||||||
%typemap(freearg) (int argc, char *argv[]) {
|
%typemap(freearg) (int argc, char *argv[]) {
|
||||||
if ($2) free($2);
|
if ($2) free($2);
|
||||||
}
|
}
|
||||||
</blockquote>
|
|
||||||
</pre>
|
</pre>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
A multi-argument map is always specified by surrounding the arguments with parentheses as shown.
|
A multi-argument map is always specified by surrounding the arguments with parentheses as shown.
|
||||||
For example:
|
For example:
|
||||||
|
|
@ -2354,7 +2354,7 @@ might write typemaps like this:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
$2 = PyInt_AsLong($input);
|
$2 = PyInt_AsLong($input);
|
||||||
if ($2 < 0) {
|
if ($2 < 0) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Positive integer expected");
|
PyErr_SetString(PyExc_ValueError, "Positive integer expected");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -2364,7 +2364,7 @@ might write typemaps like this:
|
||||||
// Return the buffer. Discarding any previous return result
|
// Return the buffer. Discarding any previous return result
|
||||||
%typemap(argout) (void *rbuffer, size_t len) {
|
%typemap(argout) (void *rbuffer, size_t len) {
|
||||||
Py_XDECREF($result); /* Blow away any previous result */
|
Py_XDECREF($result); /* Blow away any previous result */
|
||||||
if (result < 0) { /* Check for I/O error */
|
if (result < 0) { /* Check for I/O error */
|
||||||
free($1);
|
free($1);
|
||||||
PyErr_SetFromErrno(PyExc_IOError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -2483,9 +2483,9 @@ of the classes <tt>Foo</tt> and <tt>Bar</tt> as well as its own data members. F
|
||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
FooBar --> | -----------| <-- Foo
|
FooBar --> | -----------| <-- Foo
|
||||||
| int x |
|
| int x |
|
||||||
|------------| <-- Bar
|
|------------| <-- Bar
|
||||||
| int y |
|
| int y |
|
||||||
|------------|
|
|------------|
|
||||||
| int z |
|
| int z |
|
||||||
|
|
@ -2507,7 +2507,7 @@ if you look at the wrapper code for Python, you will see code like this:
|
||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_Foo,1)) == -1) return NULL;
|
if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_Foo,1)) == -1) return NULL;
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
|
@ -2529,7 +2529,7 @@ similar to this:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
%typemap(in) Foo * {
|
%typemap(in) Foo * {
|
||||||
if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor)) == -1) return NULL;
|
if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor)) == -1) return NULL;
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
@ -2558,9 +2558,9 @@ descriptor name for any C datatype. For example:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
%typemap(in) Foo * {
|
%typemap(in) Foo * {
|
||||||
if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor)) == -1) {
|
if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor)) == -1) {
|
||||||
Bar *temp;
|
Bar *temp;
|
||||||
if ((SWIG_ConvertPtr($input), (void **) &temp, <b>$descriptor(Bar *)</b>) == -1) {
|
if ((SWIG_ConvertPtr($input), (void **) &temp, <b>$descriptor(Bar *)</b>) == -1) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
$1 = (Foo *) temp;
|
$1 = (Foo *) temp;
|
||||||
|
|
@ -2618,7 +2618,7 @@ void foo(PyObject *o) {
|
||||||
descr = SWIG_TypeQuery("Foo *"); /* Get the type descriptor structure for Foo */
|
descr = SWIG_TypeQuery("Foo *"); /* Get the type descriptor structure for Foo */
|
||||||
assert(descr);
|
assert(descr);
|
||||||
}
|
}
|
||||||
if ((SWIG_ConvertPtr(o,(void **) &f, descr) == -1)) {
|
if ((SWIG_ConvertPtr(o,(void **) &f, descr) == -1)) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
...
|
...
|
||||||
|
|
@ -2715,7 +2715,7 @@ _wrap_foo(argc, args[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
if (IsString(args[0]) && IsInteger(args[1])) {
|
if (IsString(args[0]) && IsInteger(args[1])) {
|
||||||
return _wrap_foo_2(argc,args);
|
return _wrap_foo_2(argc,args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2796,33 +2796,33 @@ The follow excerpt from the Python module illustrates this:
|
||||||
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 &, const short &, const long &,
|
const int &, const short &, const long &,
|
||||||
const unsigned int &, const unsigned short &, const unsigned long &,
|
const unsigned int &, const unsigned short &, const unsigned long &,
|
||||||
const long long &, const unsigned long long &,
|
const long long &, const unsigned long long &,
|
||||||
enum SWIGTYPE,
|
enum SWIGTYPE,
|
||||||
bool, const bool &
|
bool, const bool &
|
||||||
{
|
{
|
||||||
$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 &, const double &
|
const float &, const double &
|
||||||
{
|
{
|
||||||
$1 = (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input)) ? 1 : 0;
|
$1 = (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input)) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
%typecheck(SWIG_TYPECHECK_CHAR) char {
|
%typecheck(SWIG_TYPECHECK_CHAR) char {
|
||||||
$1 = (PyString_Check($input) && (PyString_Size($input) == 1)) ? 1 : 0;
|
$1 = (PyString_Check($input) && (PyString_Size($input) == 1)) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
%typecheck(SWIG_TYPECHECK_STRING) char * {
|
%typecheck(SWIG_TYPECHECK_STRING) char * {
|
||||||
$1 = PyString_Check($input) ? 1 : 0;
|
$1 = PyString_Check($input) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
|
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
|
||||||
void *ptr;
|
void *ptr;
|
||||||
if (SWIG_ConvertPtr($input, (void **) &ptr, $1_descriptor, 0) == -1) {
|
if (SWIG_ConvertPtr($input, (void **) &ptr, $1_descriptor, 0) == -1) {
|
||||||
$1 = 0;
|
$1 = 0;
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -2832,7 +2832,7 @@ The follow excerpt from the Python module illustrates this:
|
||||||
|
|
||||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
|
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
|
||||||
void *ptr;
|
void *ptr;
|
||||||
if (SWIG_ConvertPtr($input, (void **) &ptr, $&1_descriptor, 0) == -1) {
|
if (SWIG_ConvertPtr($input, (void **) &ptr, $&1_descriptor, 0) == -1) {
|
||||||
$1 = 0;
|
$1 = 0;
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -2842,7 +2842,7 @@ The follow excerpt from the Python module illustrates this:
|
||||||
|
|
||||||
%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
|
%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
|
||||||
void *ptr;
|
void *ptr;
|
||||||
if (SWIG_ConvertPtr($input, (void **) &ptr, 0, 0) == -1) {
|
if (SWIG_ConvertPtr($input, (void **) &ptr, 0, 0) == -1) {
|
||||||
$1 = 0;
|
$1 = 0;
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -2927,7 +2927,7 @@ a set of typemaps like this:
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre>
|
<pre>
|
||||||
%typemap(in,numinputs=0) int *OUTPUT (int temp) {
|
%typemap(in,numinputs=0) int *OUTPUT (int temp) {
|
||||||
$1 = &temp;
|
$1 = &temp;
|
||||||
}
|
}
|
||||||
%typemap(argout) int *OUTPUT {
|
%typemap(argout) int *OUTPUT {
|
||||||
// return value somehow
|
// return value somehow
|
||||||
|
|
@ -2964,11 +2964,11 @@ For example:
|
||||||
<pre>
|
<pre>
|
||||||
%typemap(in) int *INPUT (int temp) {
|
%typemap(in) int *INPUT (int temp) {
|
||||||
temp = ... get value from $input ...;
|
temp = ... get value from $input ...;
|
||||||
$1 = &temp;
|
$1 = &temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(check) int *POSITIVE {
|
%typemap(check) int *POSITIVE {
|
||||||
if (*$1 <= 0) {
|
if (*$1 <= 0) {
|
||||||
SWIG_exception(SWIG_ValueError,"Expected a positive number!\n");
|
SWIG_exception(SWIG_ValueError,"Expected a positive number!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -170,8 +170,8 @@ int wrap_printf(const char *fmt, ...) {
|
||||||
...
|
...
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
};
|
};
|
||||||
</blockquote>
|
|
||||||
</pre>
|
</pre>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
Athough this code might compile, it won't do what you expect. This is
|
Athough this code might compile, it won't do what you expect. This is
|
||||||
because the call to <tt>printf()</tt> is compiled as a procedure call
|
because the call to <tt>printf()</tt> is compiled as a procedure call
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue