Merge latest master into doxygen branch.

This commit is contained in:
Vadim Zeitlin 2014-12-15 02:54:57 +01:00
commit 9b857e6cf1
275 changed files with 6821 additions and 2094 deletions

5
.gitignore vendored
View file

@ -136,6 +136,7 @@ Examples/test-suite/uffi/*/
# Octave generated files
swigexample*.oct
Examples/test-suite/octave/*.oct
# Python generated files, based on:
# https://github.com/github/gitignore/blob/master/Python.gitignore
@ -143,6 +144,10 @@ swigexample*.oct
*/__pycache__/
/__pycache__/
# Go generated files
*.[5689]
*_gc.c
# Scratch directories
Examples/scratch

View file

@ -8,6 +8,8 @@ matrix:
include:
- compiler: gcc
env: SWIGLANG=csharp
- compiler: gcc
env: SWIGLANG=d
- compiler: gcc
env: SWIGLANG=go
- compiler: gcc
@ -23,7 +25,9 @@ matrix:
- compiler: gcc
env: SWIGLANG=lua
- compiler: gcc
env: SWIGLANG=octave SWIGJOBS=-j4
env: SWIGLANG=octave SWIGJOBS=-j3 # 3.2
- compiler: gcc
env: SWIGLANG=octave SWIGJOBS=-j3 VER=3.8
- compiler: gcc
env: SWIGLANG=perl5
- compiler: gcc
@ -42,6 +46,10 @@ matrix:
env: SWIGLANG=python PY3=3 VER=3.3
- compiler: gcc
env: SWIGLANG=python PY3=3 VER=3.4
- compiler: gcc
env: SWIGLANG=python SWIG_FEATURES=-builtin
- compiler: gcc
env: SWIGLANG=python SWIG_FEATURES=-builtin PY3=3
- compiler: gcc
env: SWIGLANG=ruby
- compiler: gcc
@ -56,13 +64,15 @@ before_install:
- time sudo apt-get -qq install libboost-dev
- if test -z "$SWIGLANG"; then sudo apt-get -qq install yodl; fi
- if test "$SWIGLANG" = "csharp"; then sudo apt-get -qq install mono-devel; fi
- if test "$SWIGLANG" = "d"; then wget http://downloads.dlang.org/releases/2014/dmd_2.066.0-0_amd64.deb; sudo dpkg -i dmd_2.066.0-0_amd64.deb; fi
- if test "$SWIGLANG" = "go"; then go env | sed -e 's/^/export /' > goenvsetup && source goenvsetup && rm -f goenvsetup; fi # Until configure.ac is fixed
- if test "$SWIGLANG" = "javascript" -a "$ENGINE" = "node"; then sudo apt-get install -qq rlwrap python-software-properties && echo 'yes' | sudo add-apt-repository ppa:chris-lea/node.js && sudo apt-get -qq update && sudo apt-get install -qq nodejs && sudo npm install -g node-gyp; fi
- if test "$SWIGLANG" = "javascript" -a "$ENGINE" = "jsc"; then sudo apt-get install -qq libwebkitgtk-dev; fi
- if test "$SWIGLANG" = "javascript" -a "$ENGINE" = "v8"; then sudo apt-get install -qq libv8-dev; fi
- if test "$SWIGLANG" = "guile"; then sudo apt-get -qq install guile-2.0-dev; fi
- if test "$SWIGLANG" = "lua"; then sudo apt-get -qq install lua5.1 liblua5.1-dev; fi
- if test "$SWIGLANG" = "octave"; then sudo apt-get -qq install octave3.2 octave3.2-headers; fi
- if test "$SWIGLANG" = "octave" -a -z "$VER"; then sudo apt-get -qq install octave3.2 octave3.2-headers; fi
- if test "$SWIGLANG" = "octave" -a "$VER"; then sudo add-apt-repository -y ppa:kwwette/octaves && sudo apt-get -qq update && sudo apt-get -qq install liboctave${VER}-dev; fi
- if test "$SWIGLANG" = "php"; then sudo apt-get install php5-cli php5-dev; fi
- if test "$SWIGLANG" = "python"; then git clone https://github.com/jcrocholl/pep8.git && pushd pep8 && git checkout tags/1.5.7 && python ./setup.py build && sudo python ./setup.py install && popd; fi
- if test "$SWIGLANG" = "python" -a "$PY3" -a -z "$VER"; then sudo apt-get install -qq python3-dev; fi
@ -71,6 +81,7 @@ before_install:
# Stricter compile flags for examples. Various headers and SWIG generated code prevents full use of -pedantic.
- declare -A CFLAGS_EXAMPLES && CFLAGS_EXAMPLES=(
["csharp"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
["d"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
["go"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
["guile"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
["java"]="-Werror -std=gnu89 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
@ -85,6 +96,7 @@ before_install:
)
- declare -A CXXFLAGS_EXAMPLES && CXXFLAGS_EXAMPLES=(
["csharp"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
["d"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
["go"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
["guile"]="-Werror -std=c++98 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
["java"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"

56
CHANGES
View file

@ -1021,13 +1021,13 @@ Version 2.0.9 (16 December 2012)
2012-10-11: wsfulton
Most of the special variables available for use in %exception are now also available for expansion in
%extend blocks. These are: $name $symname $overname $decl $fulldecl $parentname $parentsymname, see docs
%extend blocks. These are: $name $symname $overname $decl $fulldecl $parentclassname $parentclasssymname, see docs
on "Class extension" in SWIGPlus.html. Patch based on submission from Kris Thielemans.
2012-10-10: wsfulton
Additional new special variables in %exception are expanded as follows:
$parentname - The parent class name (if any) for a method.
$parentsymname - The target language parent class name (if any) for a method.
$parentclassname - The parent class name (if any) for a method.
$parentclasssymname - The target language parent class name (if any) for a method.
2012-10-08: iant
[Go] Generating Go code now requires using the -intgosize option to
@ -1622,7 +1622,7 @@ Version 2.0.5 (19 April 2012)
-tmsearch and -tmused.
2011-08-26: wsfulton
[C#, D] Fix %callback which was generating uncompileable code.
[C#, D] Fix %callback which was generating uncompilable code.
2011-08-25: wsfulton
Fix constructors in named typedef class declarations as reported by Gregory Bronner:
@ -1861,7 +1861,7 @@ Version 2.0.4 (21 May 2011)
PySlice_GetIndices, which changed signatures in python3.2.
2011-04-07: wsfulton
Fix wrapping of const array typedefs which were generating uncompileable code as
Fix wrapping of const array typedefs which were generating uncompilable code as
reported by Karl Wette.
2011-04-03: szager
@ -2088,8 +2088,8 @@ Version 2.0.2 (20 February 2011)
Fix handling of multiple regex-using %renames attached to the same
declaration. For example, now
%rename("%(regex/^Set(.*)/put\\1/)s") "";
%rename("%(regex/^Get(.*)/get\\1/)s") "";
%rename("%(regex:/^Set(.*)/put\\1/)s") "";
%rename("%(regex:/^Get(.*)/get\\1/)s") "";
works as expected whereas before only the last anonymous rename was
taken into account.
@ -2299,7 +2299,7 @@ Version 2.0.1 (4 October 2010)
in this case).
2010-06-03: wsfulton
Fix uncompileable code when %rename results in two enum items
Fix uncompilable code when %rename results in two enum items
with the same name. Reported by Vadim Zeitlin.
Version 2.0.0 (2 June 2010)
@ -2812,7 +2812,7 @@ Version 2.0.0 (2 June 2010)
Fix #2310483 - function pointer typedef within extern "C" block.
2009-11-13: wsfulton
Fix usage of nested template classes within templated classes so that compileable code
Fix usage of nested template classes within templated classes so that compilable code
is generated.
2009-11-13: olly
@ -2820,7 +2820,7 @@ Version 2.0.0 (2 June 2010)
wasn't being used. Patch from gverbruggen in SF#2892647.
2009-11-12: wsfulton
Fix usage of nested template classes so that compileable code is generated - the nested
Fix usage of nested template classes so that compilable code is generated - the nested
template class is now treated like a normal nested classes, that is, as an opaque type
unless the nestedworkaround feature is used.
@ -2846,7 +2846,7 @@ Version 2.0.0 (2 June 2010)
2009-11-11: wsfulton
There were a number of C++ cases where nested classes/structs/unions were being handled
as if C code was being parsed which would oftentimes lead to uncompileable code as an
as if C code was being parsed which would oftentimes lead to uncompilable code as an
attempt was made to wrap the nested structs like it is documented for C code. Now all
nested structs/classes/unions are ignored in C++ mode, as was always documented. However,
there is an improvement as usage of nested structs/classes/unions is now always treated
@ -2858,7 +2858,7 @@ Version 2.0.0 (2 June 2010)
Fix R for -fcompact and add std_map.i
2009-11-08: wsfulton
Fix inconsistency for nested structs/unions/classes. Uncompileable code was being
Fix inconsistency for nested structs/unions/classes. Uncompilable code was being
generated when inner struct and union declarations were used as types within the
inner struct. The inner struct/union is now treated as a forward declaration making the
behaviour the same as an inner class. (C++ code), eg:
@ -2872,7 +2872,7 @@ Version 2.0.0 (2 June 2010)
Ignored nested class/struct warnings now display the name of the ignored class/struct.
2009-11-07: wsfulton
Bug #1514681 - Fix nested template classes within a namespace generated uncompileable
Bug #1514681 - Fix nested template classes within a namespace generated uncompilable
code and introduced strange side effects to other wrapper code especially code
after the nested template class. Note that nested template classes are still ignored.
@ -2898,8 +2898,8 @@ Version 2.0.0 (2 June 2010)
and in template parameter specializations:
struct S {};
template <typename T> struct X { void a() {}; };
template <> struct X<S> { void b() {}; };
template <typename T> struct X { void a() {} };
template <> struct X<S> { void b() {} };
%template(MyTConcrete) X< ::S >;
plus probably some other corner case usage of ::.
@ -3727,7 +3727,7 @@ Version 1.3.36 (24 June 2008)
06/19/2008: wsfulton
[Java, C#] C# and Java keywords will be renamed instead of just issuing a warning
and then generating uncompileable code. Warning 314 gives the new name when a
and then generating uncompilable code. Warning 314 gives the new name when a
keyword is found.
06/19/2008: wsfulton
@ -4170,7 +4170,7 @@ Version 1.3.34 (27 February 2008)
11/30/2007: wsfulton
Fix using statements using a base class method where the methods were overloaded.
Depending on the order of the using statements and method declarations, these
were previously generating uncompileable wrappers, eg:
were previously generating uncompilable wrappers, eg:
struct Derived : Base {
virtual void funk();
@ -5258,7 +5258,7 @@ Version 1.3.30 (November 13, 2006)
10/03/2006: wsfulton
[Ruby] Fix #1527885 - Overloaded director virtual methods sometimes produced
uncompileable code when used with the director:except feature.
uncompilable code when used with the director:except feature.
10/03/2006: wsfulton
Directors: Directors are output in the order in which they are declared in
@ -9456,7 +9456,7 @@ Version 1.3.23 (November 11, 2004)
wrapper method only and not the extra overloaded methods that SWIG generates.
For example:
%feature("except") void hello(int i=0, double d=0.0);
%feature("except") hello(int i=0, double d=0.0);
void hello(int i=0, double d=0.0);
will apply the feature to all three wrapper methods, that is:
@ -9467,7 +9467,7 @@ Version 1.3.23 (November 11, 2004)
If the default arguments are not specified in the feature:
%feature("except") void hello(int i, double d);
%feature("except") hello(int i, double d);
void hello(int i=0, double d=0.0);
then the feature will only apply to this wrapper method:
@ -10842,7 +10842,7 @@ Version 1.3.22 (September 4, 2004)
...
}
Previously, none of BIG, LARGE or BAR would have produced compileable code
Previously, none of BIG, LARGE or BAR would have produced compilable code
when using %javaconst(1).
06/27/2004: wsfulton
@ -20234,13 +20234,13 @@ Version 1.3.6 (July 9, 2001)
class TestClass
{
public:
TestClass() {};
TestClass(int a) {};
~TestClass() {};
unsigned long xyz(short k) {};
unsigned long xyz(int n) {};
static void static_func() {};
static void static_func(int a) {};
TestClass() {}
TestClass(int a) {}
~TestClass() {}
unsigned long xyz(short k) {}
unsigned long xyz(int n) {}
static void static_func() {}
static void static_func(int a) {}
};
void delete_TestClass(int a);

View file

@ -5,3 +5,123 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.3 (in progress)
===========================
2014-12-09: wsfulton
Fix #245 - regression (since swig-3.0.0) in templated constructors.
Templated constructors could not be instantiated - they were incorrectly ignored with a warning 504:
"Function: xyz must have a return type. Ignored."
2014-12-07: wsfulton
Add support for C++11 strongly typed enumerations.
2014-11-21: wsfulton
[Java C#] Fix multiply defined error when using %rename of enum items when using the "simple enum" wrappers.
2014-10-28: vadz
[Python] Patch #201 The generated .py file no longer uses *args for all Python parameters.
Instead, the parameters are named using the C++ parameter names.
2014-10-24: timotheecour
[D] Patch #204 Use core.atomic.atomicOp to mutate shared variables
2014-10-21: wsfulton
Fix issue #242 - Use of the "kwargs" feature no longer automatically turns on the
"compactdefaultargs" feature if the target language does not support kwargs.
Only Java and Python support kwargs, so this affects all the other languages.
*** POTENTIAL INCOMPATIBILITY ***
2014-10-10: diorcety
[Python] Patch #232 Fix property access using directors
2014-10-06: wsfulton
[Python] Fixes when using -builtin and std::vector/std::list wrappers to allow deletion
of single elements, such as 'del vec[0]'.
2014-09-30: oliverb
[Javascript] Merge patch #216 by Richie765 - Added support for many versions of v8 javascript.
2014-09-30: oliverb
[Javascript] Merge patch #195 by zittix - Fixed JSClassRef declaration not using the static one.
2014-09-30: ianlancetaylor
[Go] In configure script, require Go 1.1 or later.
2014-09-30: wsfulton
[Python] Patch #207 - Fix No module error with -relativeimport when using single
header file import.
2014-09-27: wsfulton
Patch #208 - Initialise newly created array when using array_functions in the
carrays.i library (C++ usage).
2014-09-27: wsfulton
[Ruby] Patch #187 - Fix crash on shutdown of the Ruby interpreter if more than one
module was loaded at a time when data is being shared between modules.
2014-09-27: wsfulton
[Java] Patch #168 - Fix leak in Java director string handling after the Java
upcall when called from a native thread.
2014-09-25: ianlancetaylor
[Go] Adjust generated code to work with upcoming Go 1.4
release.
2014-09-23: wsfulton
[Python] Add patch from Thomas Maslach to fix crash in wrappers when using -threads in
the STL iterators (SwigPyIterator destructor).
2014-09-17: wsfulton
[C#] Merge patch #229 from contre - Add bool array types to arrays_csharp.i
2014-09-12: olly
[PHP] Add support for specifying any PHP interfaces a wrapped class
implements, e.g.: %typemap("phpinterfaces") MyIterator "Iterator";
2014-09-11: olly
[PHP] Fix throwing a PHP exception through C++ from a subclassed
director method - PHP NULL gets returned by the subclassed method
in this case, so the directorout typemap needs to allow that (at
least if an exception is active).
2014-09-09: ianlancetaylor
[Go] Add goargout typemap.
2014-09-09: olly
[PHP] Fix segmentation faults with directors in PHP >= 5.4, and
reenable runme tests for director_basic testcase. Fix from
pavel-charvat in issue#164.
2014-09-05: ianlancetaylor
[Go] Add imtype, goin, goout, godirectorin, and
godirectorout typemaps, to support writing Go code to
convert between types.
2014-09-02: olly
[Python] Fix regression in indentation of python code produced with
-modern, introduced by changes in #188. Reported by fabiencastan
in #218.
2014-09-01: olly
Issue an error for unknown SWIG preprocessor directives, rather
than quietly ignoring them. Reported by jrhelsey in issue#217.
2014-08-15: talby
[Perl] Include guard fix for nested modules from Anthony Heading (SF Patch #350).
2014-08-04: wsfulton
[C#] Merge patch #200 from gpetrou - Changed CSharp license header to include auto-generated
tag so that StyleCop ignores the files.
2014-08-04: wsfulton
[Java] Merge patch #198 from Yuval Kashtan - Support for java.nio.ByteBuffer mapping to
unsigned char * in various.i in NIOBUFFER typemaps.
2014-07-14: ianlancetaylor
[Go] Change struct definition to use void *, not uint8, so
that the type is recorded as possibly containing
pointers. This ensures that the 1.3 garbage collector
does not collect pointers passed to C++ code.
2014-07-01: wsfulton
Fix SF Bug #1375 - Expansion of the $parentclassname special variable incorrectly contains
brackets in the expanded name.

View file

@ -56,7 +56,7 @@ Add the SDK tools and NDK tools to your path and create a directory somewhere fo
<pre>
$ export PATH=$HOME/android/android-sdk-linux_x86/tools:$HOME/android/android-sdk-linux_x86/platform-tools:$HOME/android/android-ndk-r6b:$PATH
$ mkdir AndroidApps
$ cd AnrdoidApps
$ cd AndroidApps
</pre>
</div>

View file

@ -495,59 +495,59 @@ struct DerivedStruct : BaseStruct {
<H3><a name="CPlusPlus11_strongly_typed_enumerations"></a>7.2.13 Strongly typed enumerations</H3>
<p>SWIG parses the new <tt>enum class</tt> syntax and forward declarator for the enums:</p>
<p>SWIG supports strongly typed enumerations and parses the new <tt>enum class</tt> syntax and forward declarator for the enums, such as:</p>
<div class="code"><pre>
enum class MyEnum : unsigned int;
</pre></div>
<p>The strongly typed enumerations are treated the same as the ordinary and anonymous enums.
This is because the required nested class support in SWIG is new and has not yet been incorporated into the wrapping of these strongly typed enum classes.
This is usually not a problem, however,
there may be some name clashes. For example, the following code:</p>
<p>
Strongly typed enums are often used to avoid name clashes such as the following:
</p>
<div class="code"><pre>
class Color {
enum class PrintingColors : unsigned int {
Cyan, Magenta, Yellow, Black
struct Color {
enum class RainbowColors : unsigned int {
Red, Orange, Yellow, Green, Blue, Indigo, Violet
};
enum class BasicColors {
Red, Green, Blue
enum class WarmColors {
Yellow, Orange, Red
};
enum class AllColors {
// produces warnings because of duplicate names
Yellow, Orange, Red, Magenta, Blue, Cyan, Green, Pink, Black, White
};
};
</pre></div>
<p>A workaround is to write these as a series of separate classes containing anonymous enums:</p>
<div class="code"><pre>
class PrintingColors {
enum : unsigned int {
Cyan, Magenta, Yellow, Black
};
};
class BasicColors {
enum : unsigned int {
Red, Green, Blue
};
};
class AllColors {
enum : unsigned int {
Yellow, Orange, Red, Magenta, Blue, Cyan, Green, Pink, Black, White
// Note normal enum
enum PrimeColors {
Red=100, Green, Blue
};
};
</pre></div>
<p>
Expect to see this improved in a future version of SWIG.
There are various ways that the target languages handle enums, so it is not possible to precisely state how they are handled in this section.
However, generally, most scripting languages mangle in the strongly typed enumeration's class name,
but do not use any additional mangling for normal enumerations. For example, in Python, the following code
</p>
<div class="targetlang"><pre>
print Color.RainbowColors_Red, Color.WarmColors_Red, Color.Red
</pre></div>
<p>
results in
</p>
<div class="shell"><pre>
0 2 100
</pre></div>
<p>
The strongly typed languages often wrap normal enums into an enum class and so treat normal enums and strongly typed enums the same.
The equivalent in Java is:
</p>
<div class="targetlang"><pre>
System.out.println(Color.RainbowColors.Red.swigValue() + " " + Color.WarmColors.Red.swigValue() + " " + Color.PrimeColors.Red.swigValue());
</pre></div>
<H3><a name="CPlusPlus11_double_angle_brackets"></a>7.2.14 Double angle brackets</H3>
@ -611,6 +611,7 @@ The following is an example of an alias template:
<div class="code"><pre>
template&lt; typename T1, typename T2, int &gt;
class SomeType {
public:
T1 a;
T2 b;
int c;

View file

@ -1075,6 +1075,7 @@ try {
$action
} catch (std::out_of_range e) {
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, e.what());
return $null;
}
%}

View file

@ -854,6 +854,7 @@
<li><a href="Go.html#Go_enumerations">Go Enumerations</a>
<li><a href="Go.html#Go_classes">Go Classes</a>
<ul>
<li><a href="Go.html#Go_class_memory">Go Class Memory Management</a>
<li><a href="Go.html#Go_class_inheritance">Go Class Inheritance</a>
</ul>
<li><a href="Go.html#Go_templates">Go Templates</a>
@ -861,6 +862,7 @@
<li><a href="Go.html#Go_primitive_type_mappings">Default Go primitive type mappings</a>
<li><a href="Go.html#Go_output_arguments">Output arguments</a>
<li><a href="Go.html#Go_adding_additional_code">Adding additional go code</a>
<li><a href="Go.html#Go_typemaps">Go typemaps</a>
</ul>
</ul>
</div>
@ -1415,6 +1417,7 @@
<li><a href="Php.html#Php_nn2_6_2">Constructors and Destructors</a>
<li><a href="Php.html#Php_nn2_6_3">Static Member Variables</a>
<li><a href="Php.html#Php_nn2_6_4">Static Member Functions</a>
<li><a href="Php.html#Php_nn2_6_5">Specifying Implemented Interfaces</a>
</ul>
<li><a href="Php.html#Php_nn2_7">PHP Pragmas, Startup and Shutdown code</a>
</ul>

View file

@ -485,12 +485,12 @@ variables are replaced with.
</tr>
<tr>
<td>$parentname</td>
<td>$parentclassname</td>
<td>The parent class name (if any) for a method.</td>
</tr>
<tr>
<td>$parentsymname</td>
<td>$parentclasssymname</td>
<td>The target language parent class name (if any) for a method.</td>
</tr>
@ -547,7 +547,7 @@ Below shows the expansions for the 1st of the overloaded <tt>something</tt> wrap
The <tt>exception.i</tt> library file provides support for creating
language independent exceptions in your interfaces. To use it, simply
put an "<tt>%include exception.i</tt>" in your interface file. This
creates a function<tt> SWIG_exception()</tt> that can be used to raise
provides a function <tt>SWIG_exception()</tt> that can be used to raise
common scripting language exceptions in a portable manner. For example :</p>
<div class="code"><pre>
@ -1082,7 +1082,7 @@ For example:
<div class="code">
<pre>
%feature("except") void hello(int i=0, double d=0.0) { ... }
%feature("except") hello(int i=0, double d=0.0) { ... }
void hello(int i=0, double d=0.0);
</pre>
</div>
@ -1105,7 +1105,7 @@ If the default arguments are not specified in the feature:
<div class="code">
<pre>
%feature("except") void hello(int i, double d) { ... }
%feature("except") hello(int i, double d) { ... }
void hello(int i=0, double d=0.0);
</pre>
</div>

View file

@ -23,6 +23,7 @@
<li><a href="#Go_enumerations">Go Enumerations</a>
<li><a href="#Go_classes">Go Classes</a>
<ul>
<li><a href="#Go_class_memory">Go Class Memory Management</a>
<li><a href="#Go_class_inheritance">Go Class Inheritance</a>
</ul>
<li><a href="#Go_templates">Go Templates</a>
@ -30,6 +31,7 @@
<li><a href="#Go_primitive_type_mappings">Default Go primitive type mappings</a>
<li><a href="#Go_output_arguments">Output arguments</a>
<li><a href="#Go_adding_additional_code">Adding additional go code</a>
<li><a href="#Go_typemaps">Go typemaps</a>
</ul>
</ul>
</div>
@ -374,7 +376,40 @@ returns a go interface. If the returned pointer can be null, you can check
for this by calling the Swigcptr() method.
</p>
<H4><a name="Go_class_inheritance"></a>23.3.5.1 Go Class Inheritance</H4>
<H4><a name="Go_class_memory"></a>23.3.5.1 Go Class Memory Management</H4>
<p>
Calling <tt>NewClassName</tt> for some C++ class <tt>ClassName</tt>
will allocate memory using the C++ memory allocator. This memory will
not be automatically freed by Go's garbage collector. When you are
done with the C++ object you must free it using <tt>DeleteClassName</tt>.
</p>
<p>
A common technique is to store the C++ object into a Go object, and
use the Go function <tt>runtime.SetFinalizer</tt> to free the C++
object when the Go object is freed. For example, if the SWIG package
is imported as "wrap":
</p>
<div class="code">
<pre>
type GoClassName struct {
w wrap.ClassName
}
func NewGoClassName() *GoClassName {
r := &amp;GoClassName{wrap.NewClassName()}
runtime.SetFinalizer(r,
func(r *GoClassName) {
wrap.DeleteClassName(r.w)
})
return r
}
</pre>
</div>
<H4><a name="Go_class_inheritance"></a>23.3.5.2 Go Class Inheritance</H4>
<p>
@ -692,5 +727,144 @@ func bar() {
</pre>
</div>
<H3><a name="Go_typemaps"></a>23.3.11 Go typemaps</H3>
<p>
You can use the <tt>%typemap</tt> directive to modify SWIG's default
wrapping behavior for specific C/C++ types. You need to be familiar
with the material in the general
"<a href="Typemaps.html#Typemaps">Typemaps</a>" chapter. That chapter
explains how to define a typemap. This section describes some
specific typemaps used for Go.
</p>
<p>
In general type conversion code may be written either in C/C++ or in
Go. The choice to make normally depends on where memory should be
allocated. To allocate memory controlled by the Go garbage collector,
write Go code. To allocate memory in the C/C++ heap, write C code.
</p>
<table BORDER summary="Go Typemaps">
<tr>
<td><b>Typemap</b></td>
<td><b>Description</b></td>
</tr>
<tr>
<td>gotype</td>
<td>
The Go type to use for a C++ type. This type will appear in the
generated Go wrapper function. If this is not defined SWIG will use a
default as <a href="#Go_primitive_type_mappings">described above</a>.
</td>
</tr>
<tr>
<td>imtype</td>
<td>
An intermediate Go type used by the "goin", "goout", "godirectorin",
and "godirectorout" typemaps. If this typemap is not defined for a
C/C++ type, the gotype typemape will be used. This is useful when
gotype is best converted to C/C++ using Go code.
</td>
</tr>
<tr>
<td>goin</td>
<td>
Go code to convert from gotype to imtype when calling a C/C++
function. SWIG will then internally convert imtype to a C/C++ type
and pass it down. If this is not defined no conversion is done.
</td>
</tr>
<tr>
<td>in</td>
<td>
C/C++ code to convert the internally generated C/C++ type, based on
imtype, into the C/C++ type that a function call expects. If this is
not defined the value will simply be cast to the desired type.
</td>
</tr>
<tr>
<td>out</td>
<td>
C/C++ code to convert the C/C++ type that a function call returns into
the internally generated C/C++ type, based on imtype, that will be
returned to Go. If this is not defined the value will simply be cast
to the desired type.
</td>
</tr>
<tr>
<td>goout</td>
<td>
Go code to convert a value returned from a C/C++ function from imtype
to gotype. If this is not defined no conversion is done.
</td>
</tr>
<tr>
<td>argout</td>
<td>
C/C++ code to adjust an argument value when returning from a function.
This is called after the real C/C++ function has run. This uses the
internally generated C/C++ type, based on imtype. This is only useful
for a pointer type of some sort. If this is not defined nothing will
be done.
</td>
</tr>
<tr>
<td>goargout</td>
<td>
Go code to adjust an argument value when returning from a function.
This is called after the real C/C++ function has run. The value will
be in imtype. This is only useful for a pointer type of some sort.
If this is not defined nothing will be done.
</td>
</tr>
<tr>
<td>directorin</td>
<td>
C/C++ code to convert the C/C++ type used to call a director method
into the internally generated C/C++ type, based on imtype, that will
be passed to Go. If this is not defined the value will simply be cast
to the desired type.
</td>
</tr>
<tr>
<td>godirectorin</td>
<td>
Go code to convert a value used to call a director method from imtype
to gotype. If this is not defined no conversion is done.
</td>
</tr>
<tr>
<td>godirectorout</td>
<td>
Go code to convert a value returned from a director method from gotype
to imtype. If this is not defined no conversion is done.
</td>
</tr>
<tr>
<td>directorout</td>
<td>
C/C++ code to convert a value returned from a director method from the
internally generated C/C++ type, based on imtype, into the type that
the method should return If this is not defined the value will simply
be cast to the desired type.
</td>
</tr>
</table>
</body>
</html>

View file

@ -358,7 +358,7 @@ more aggressive from gcc-4.0 onwards and will result in code that fails with str
<p>
The name of the shared library output file is important.
If the name of your SWIG module is "<tt>example</tt>", the name of the corresponding shared library file should be "<tt>libexample.so</tt>" (or equivalent depending on your machine, see <a href="#Java_dynamic_linking_problems">Dynamic linking problems</a> for more information).
The name of the module is specified using the <tt>%module</tt> directive or<tt> -module</tt> command line option.</p>
The name of the module is specified using the <tt>%module</tt> directive or <tt>-module</tt> command line option.</p>
<H3><a name="Java_using_module"></a>25.2.5 Using your module</H3>
@ -2441,7 +2441,7 @@ It also contains all the methods in the C++ class it is proxying plus getters an
member variables. These functions call the native methods in the intermediary JNI class.
The advantage of having this extra layer is the type safety that the proxy class functions offer.
It adds static type checking which leads to fewer surprises at runtime.
For example, you can see that if you attempt to use the <tt> spam() </tt>
For example, you can see that if you attempt to use the <tt>spam()</tt>
function it will only compile when the parameters passed are an <tt>int</tt> and a <tt>Foo</tt>.
From a user's point of view, it makes the class work as if it were a Java class:
</p>
@ -4173,8 +4173,8 @@ void *malloc(size_t nbytes);
<p>
If no declaration name is given to <tt>%exception</tt>, it is applied to all wrapper functions.
The <tt> $action </tt> is a SWIG special variable and is replaced by the C/C++ function call being wrapped.
The <tt> return $null; </tt> handles all native method return types, namely those that have a void return and those that do not.
The <tt>$action</tt> is a SWIG special variable and is replaced by the C/C++ function call being wrapped.
The <tt>return $null;</tt> handles all native method return types, namely those that have a void return and those that do not.
This is useful for typemaps that will be used in native method returning all return types.
See the section on
<a href="#Java_special_variables">Java special variables</a> for further explanation.
@ -5490,6 +5490,15 @@ These are listed below:
<td>Use for mapping NULL terminated arrays of C strings to Java String arrays</td>
</tr>
<tr>
<td>unsigned char *</td>
<td>NIOBUFFER</td>
<td>various.i</td>
<td>input<br> output</td>
<td>java.nio.Buffer</td>
<td>Use for mapping directly allocated buffers to c/c++. useful with directors and long lived memory objects</td>
</tr>
</table>
<H3><a name="Java_typemap_attributes"></a>25.9.6 Java typemap attributes</H3>
@ -5570,7 +5579,7 @@ This special variable is usually used for making calls to a function in the inte
</p>
<p>
<b><tt>$null </tt></b><br>
<b><tt>$null</tt></b><br>
Used in input typemaps to return early from JNI functions that have either void or a non-void return type. Example:
</p>

View file

@ -88,6 +88,12 @@ $ swig -javascript -jsc example.i</pre>
<pre>
$ swig -c++ -javascript -jsc example.i</pre>
</div>
<p>The V8 code that SWIG generates should work with most versions from 3.11.10 up to 3.29.14 and later.</p>
<p>Specify the V8 version when running SWIG (e.g. 3.25.30)</p>
<div class="shell">
<pre>
$ swig -c++ -javascript -v8 -DV8_VERSION=0x032530 example.i</pre>
</div>
<p>This creates a C/C++ source file <code>example_wrap.c</code> or <code>example_wrap.cxx</code>. The generated C source file contains the low-level wrappers that need to be compiled and linked with the rest of your C/C++ application to create an extension module.</p>
<p>The name of the wrapper file is derived from the name of the input file. For example, if the input file is <code>example.i</code>, the name of the wrapper file is <code>example_wrap.c</code>. To change this, you can use the -o option. The wrapped module will export one function which must be called to register the module with the Javascript interpreter. For example, if your module is named <code>example</code> the corresponding initializer for JavascriptCore would be</p>
<div class="code">
@ -129,6 +135,11 @@ $ make check-javascript-examples ENGINE=jsc</pre>
<pre>
$ make check-javascript-test-suite ENGINE=jsc</pre>
</div>
<p>You can specify a specific <code>V8</code> version for running the examples and tests</p>
<div class="shell">
<pre>
$ make check-javascript-examples V8_VERSION=0x032530 ENGINE=v8</pre>
</div>
<H3><a name="Javascript_known_issues"></a>26.2.3 Known Issues</H3>
@ -184,7 +195,7 @@ $ sudo npm install -g node-gyp</pre>
<p>First create the wrapper using SWIG:</p>
<div class="shell">
<pre>
$ swig -javascript -node -c++ example.cxx</pre>
$ swig -javascript -node -c++ example.i</pre>
</div>
<p>Then run <code>node-gyp</code></p>
<div class="shell">
@ -342,8 +353,8 @@ It has some extras to configure <code>node-webkit</code>. See the <a href="https
<div class="code">
<pre>
{
"name": "example"
"main": "app.html"
"name": "example",
"main": "app.html",
"window": {
"show": true,
"width": 800,
@ -446,7 +457,7 @@ var x = 42;
var y = 105;
var g = example.gcd(x,y);
// Accessing the globak variable
// Accessing the global variable
var f = example.Foo;
example.Foo = 3.1415926;</pre>
</div>
@ -467,7 +478,7 @@ public:
}
virtual ~Shape() {
nshapes--;
};
}
double x, y;
void move(double dx, double dy);
virtual double area(void) = 0;
@ -479,7 +490,7 @@ class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { };
Circle(double r) : radius(r) { }
virtual double area(void);
virtual double perimeter(void);
};
@ -488,7 +499,7 @@ class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
Square(double w) : width(w) { }
virtual double area(void);
virtual double perimeter(void);
};</pre>
@ -765,7 +776,7 @@ class JSEmitter {
*/
virtual int exitClass(Node *) {
return SWIG_OK;
};
}
/**
* Invoked at the beginning of the variableHandler.
@ -777,7 +788,7 @@ class JSEmitter {
*/
virtual int exitVariable(Node *) {
return SWIG_OK;
};
}
/**
* Invoked at the beginning of the functionHandler.
@ -789,7 +800,7 @@ class JSEmitter {
*/
virtual int exitFunction(Node *) {
return SWIG_OK;
};
}
/**
* Invoked by functionWrapper callback after call to Language::functionWrapper.

View file

@ -59,8 +59,8 @@ Also, there are a dozen or so examples in the Examples/octave directory, and hun
<p>
As of SWIG 3.0.0, the Octave module has been tested with Octave versions 3.0.5, 3.2.4, 3.4.3, 3.6.4, and 3.8.0.
Use of Octave versions older than 3.x.x is not recommended, as these versions are no longer tested with SWIG.
As of SWIG 3.0.3, the Octave module has been tested with Octave versions 3.2.4, 3.4.3, 3.6.4, and 3.8.1.
Use of older Octave versions is not recommended, as these versions are no longer tested with SWIG.
</p>
<H2><a name="Octave_nn3"></a>32.2 Running SWIG</H2>

View file

@ -29,6 +29,7 @@
<li><a href="#Php_nn2_6_2">Constructors and Destructors</a>
<li><a href="#Php_nn2_6_3">Static Member Variables</a>
<li><a href="#Php_nn2_6_4">Static Member Functions</a>
<li><a href="#Php_nn2_6_5">Specifying Implemented Interfaces</a>
</ul>
<li><a href="#Php_nn2_7">PHP Pragmas, Startup and Shutdown code</a>
</ul>
@ -113,9 +114,7 @@ more detail in <a href="#Php_nn2_6">section 27.2.6</a>.
<p>
The usual (and recommended) way is to build the extension as a separate
dynamically loaded module (which is supported by all modern operating
systems). You can then specify that this be loaded
automatically in <tt>php.ini</tt> or load it explicitly for any script which
needs it.
systems).
</p>
<p>
@ -137,16 +136,15 @@ least work for Linux though):
</p>
<div class="code"><pre>
gcc `php-config --includes` -fpic -c example_wrap.c
gcc -shared example_wrap.o -o example.so
gcc `php-config --includes` -fpic -c example_wrap.c example.c
gcc -shared example_wrap.o example.o -o example.so
</pre></div>
<H3><a name="Php_nn1_3"></a>34.1.2 Using PHP Extensions</H3>
<p>
To test the extension from a PHP script, you need to load it first. You
can load it for every script by adding this line to the <tt>[PHP]</tt> section of
To test the extension from a PHP script, you first need to tell PHP to
load it. To do this, add a line like this to the <tt>[PHP]</tt> section of
<tt>php.ini</tt>:
</p>
@ -155,8 +153,14 @@ can load it for every script by adding this line to the <tt>[PHP]</tt> section o
</pre></div>
<p>
Alternatively, you can load it explicitly only for scripts which need it
by adding this line to the start of each such PHP script::
If the module is in PHP's default extension directory, you can omit the path.
</p>
<p>
For some SAPIs (for example, the CLI SAPI) you can instead use the
<a href="http://php.net/manual/en/function.dl.php">dl() function</a> to load
an extension at run time, by adding a like like this to the start of each
PHP script which uses your extension:
</p>
<div class="code"><pre>
@ -164,14 +168,25 @@ by adding this line to the start of each such PHP script::
</pre></div>
<p>
SWIG also generates a php module, which
attempts to do the <tt>dl()</tt> call for you:
But note that this doesn't work when running PHP through a webserver in PHP5.3
and later - you'll need to use <tt>extension</tt> in <tt>php.ini</tt> as
described above.
</p>
<p>
The PHP module which SWIG generates will also attempt to do the <tt>dl()</tt>
call for you if the extension isn't already loaded:
</p>
<div class="code"><pre>
include("example.php");
</pre></div>
<p>
This PHP module also defines the PHP classes for the wrapped API, so you'll
almost certainly want to include it anyway.
</p>
<H2><a name="Php_nn2"></a>34.2 Basic PHP interface</H2>
@ -220,9 +235,9 @@ echo "E = " . E . "\n";
<p>
There's one peculiarity of how constants work in PHP which it is useful
to note (this is not specific to SWIG though) - if you try to use an undeclared
constant, PHP will issue a warning and then expand the constant to a string
version of the constant's name. The warning will often be missed though as
if you're using PHP in a webserver, it will probably end up in error.log or
constant, PHP will emit a notice and then expand the constant to a string
version of the constant's name. Unfortunately it is easy to miss the notice
if you're using PHP in a webserver, as it will probably end up in error.log or
similar.
</p>
@ -756,6 +771,23 @@ Ko::threats();
</pre></div>
<H4><a name="Php_nn2_6_5"></a>34.2.6.5 Specifying Implemented Interfaces</H4>
<p>
PHP supports the concept of abstract interfaces which a class can implement.
Since SWIG 3.0.3, you can tell SWIG that a wrapped class (for example
<code>MyIterator</code>) implements the <code>Iterator</code> interface like
so:
</p>
<div class="code"><pre>
%typemap("phpinterfaces") MyIterator "Iterator";
</pre></div>
<p>
If there are multiple interfaces, just list them separated by commas.
</p>
<H3><a name="Php_nn2_7"></a>34.2.7 PHP Pragmas, Startup and Shutdown code</H3>

View file

@ -194,7 +194,7 @@ int fact(int n);
</div>
<p>
The <tt> #define SWIG_FILE_WITH_INIT </tt> line inserts a macro that specifies that the
The <tt>#define SWIG_FILE_WITH_INIT</tt> line inserts a macro that specifies that the
resulting C file should be built as a python extension, inserting the module
<tt>init</tt> code. This <tt>.i</tt> file wraps the following simple C file:
</p>
@ -395,7 +395,7 @@ of the module prefixed by an underscore</b>. If the name of your module is "<tt
name of the corresponding object file should be
"<tt>_example.so</tt>" or "<tt>_examplemodule.so</tt>".
The name of the module is specified using the <tt>%module</tt> directive or the
<tt> -module</tt> command line option.
<tt>-module</tt> command line option.
</p>
<p>
@ -783,8 +783,8 @@ Building a SWIG extension to Python under Windows is roughly similar to
the process used with Unix. Using the distutils, it is essentially
identical. If you have the same version of the MS compiler that Python
was built with (the python2.4 and python2.5 distributed by python.org
are built with Visual Studio 2003), the standard <tt> python setup.py
build </tt> should just work.
are built with Visual Studio 2003), the standard <tt>python setup.py
build</tt> should just work.
</p>
<p>

View file

@ -685,7 +685,7 @@ For example, this struct declaration: </p>
</div>
<p> gets wrapped as a <tt>Vector</tt> class, with
Ruby instance methods <tt>x</tt>, <tt> x=</tt>,
Ruby instance methods <tt>x</tt>, <tt>x=</tt>,
<tt>y</tt> and <tt>y=</tt>. These methods can
be used to access structure data from Ruby as follows: </p>
@ -1313,7 +1313,7 @@ chapter.</p>
<p>Some containers in the STL allow you to modify their default
behavior by using so called functors or function objects.
Functors are often just a very simple struct with<tt> operator()</tt>
Functors are often just a very simple struct with <tt>operator()</tt>
redefined or an actual C/C++ function. This allows you, for
example, to always keep the sort order of a STL container to your
liking.</p>
@ -1327,7 +1327,7 @@ this includes <tt>std::set</tt>,
<tt>std::multiset</tt>
and <tt>std::multimap</tt>.</p>
<p>The functors in swig are called<tt> swig::UnaryFunction</tt>
<p>The functors in swig are called <tt>swig::UnaryFunction</tt>
and <tt>swig::BinaryFunction</tt>.
For C++ predicates (ie. functors that must return bool as a result) <tt>swig::UnaryPredicate</tt>
@ -1380,8 +1380,8 @@ values they point at, while the non-const iterators can both read and
modify the values.</p>
<p>The Ruby STL wrappings support both type of iterators by using
a proxy class in-between. This proxy class is <tt>swig::Iterator or
swig::ConstIterator. </tt> Derived from them are template
a proxy class in-between. This proxy class is <tt>swig::Iterator</tt> or
<tt>swig::ConstIterator</tt>. Derived from them are template
classes that need to be initialized with the actual iterator for the
container you are wrapping and often times with the beginning and
ending points of the iteration range.</p>
@ -1450,7 +1450,7 @@ i
</pre>
</div>
<p>If you'd rather have STL classes without any iterators, you should define<tt> -DSWIG_NO_EXPORT_ITERATOR_METHODS </tt>when running swig.</p>
<p>If you'd rather have STL classes without any iterators, you should define <tt>-DSWIG_NO_EXPORT_ITERATOR_METHODS</tt> when running swig.</p>
<H3><a name="Ruby_nn24"></a>38.3.16 C++ Smart Pointers</H3>
@ -4997,7 +4997,7 @@ object from its underlying C++ object.</p>
<p>In general, you will only need to use the <tt>SWIG_RubyInstanceFor</tt>,
which is required for implementing mark functions as shown below.
However, if you implement your own free functions (see below) you may
also have to call the<tt> SWIG_RubyRemoveTracking</tt> and <tt>RubyUnlinkObjects</tt>
also have to call the <tt>SWIG_RubyRemoveTracking</tt> and <tt>RubyUnlinkObjects</tt>
methods.</p>
<H3><a name="Ruby_nn61"></a>38.10.4 Mark Functions</H3>

View file

@ -1046,7 +1046,7 @@ def filecopy(source,target):
</pre></div>
<p>
In this case <tt>f1</tt>,<tt> f2</tt>, and <tt>buffer</tt> are all
In this case <tt>f1</tt>, <tt>f2</tt>, and <tt>buffer</tt> are all
opaque objects containing C pointers. It doesn't matter what value
they contain--our program works just fine without this knowledge.</p>
@ -1711,7 +1711,7 @@ wrapping a header file like this:
</pre></div>
<p>
<tt>%rename </tt>applies a renaming operation to all future
<tt>%rename</tt> applies a renaming operation to all future
occurrences of a name. The renaming applies to functions, variables,
class and structure names, member functions, and member data. For
example, if you had two-dozen C++ classes, all with a member function
@ -3316,7 +3316,7 @@ Most importantly, define a type before it is used! A C compiler will tell you
if the full type information is not available if it is needed, whereas
SWIG will usually not warn or error out as it is designed to work without
full type information. However, if type information is not specified
correctly, the wrappers can be sub-optimal and even result in uncompileable C/C++ code.
correctly, the wrappers can be sub-optimal and even result in uncompilable C/C++ code.
<li>If your program has a main() function, you may need to rename it
(read on).

View file

@ -1184,15 +1184,17 @@ public:
</div>
<p>
This produces uncompileable wrapper code because default values in C++ are
This produces uncompilable wrapper code because default values in C++ are
evaluated in the same scope as the member function whereas SWIG
evaluates them in the scope of a wrapper function (meaning that the
values have to be public).
</p>
<p>
This feature is automatically turned on when wrapping <a href="SWIG.html#SWIG_default_args">C code with default arguments</a>
and whenever keyword arguments (kwargs) are specified for either C or C++ code.
The <tt>compactdefaultargs</tt> feature is automatically turned on when wrapping <a href="SWIG.html#SWIG_default_args">C code with default arguments</a>.
Some target languages will also automatically turn on this feature
if the keyword arguments feature (kwargs) is specified for either C or C++ functions, and the target language supports kwargs,
the <tt>compactdefaultargs</tt> feature is also automatically turned on.
Keyword arguments are a language feature of some scripting languages, for example Ruby and Python.
SWIG is unable to support kwargs when wrapping overloaded methods, so the default approach cannot be used.
</p>
@ -1203,7 +1205,7 @@ SWIG is unable to support kwargs when wrapping overloaded methods, so the defaul
<p>
SWIG wraps class members that are public following the C++
conventions, i.e., by explicit public declaration or by the use of
the <tt> using</tt> directive. In general, anything specified in a
the <tt>using</tt> directive. In general, anything specified in a
private or protected section will be ignored, although the internal
code generator sometimes looks at the contents of the private and
protected sections so that it can properly generate code for default
@ -2798,7 +2800,7 @@ public:
</pre></div>
<p>
This code adds a<tt> __str__</tt> method to our class for producing a
This code adds a <tt>__str__</tt> method to our class for producing a
string representation of the object. In Python, such a method would
allow us to print the value of an object using the <tt>print</tt>
command.
@ -2847,12 +2849,12 @@ struct Derived : Base {
<p>
The following special variables are expanded if used within a %extend block:
$name, $symname, $overname, $decl, $fulldecl, $parentname and $parentsymname.
$name, $symname, $overname, $decl, $fulldecl, $parentclassname and $parentclasssymname.
The <a href="Customization.html#Customization_exception_special_variables">Special variables</a> section provides more information each of these special variables.
</p>
<p>
The<tt> %extend</tt> directive follows all of the same conventions
The <tt>%extend</tt> directive follows all of the same conventions
as its use with C structures. Please refer to the <a href="SWIG.html#SWIG_adding_member_functions">Adding member functions to C structures</a>
section for further details.
</p>
@ -3565,7 +3567,7 @@ It is also possible to separate these declarations from the template class. For
template&lt;class T&gt; class List {
...
public:
List() { };
List() { }
T get(int index);
...
};

View file

@ -160,7 +160,7 @@ of the module. If the name of your SWIG module is "<tt>example</tt>", the
name of the corresponding object file should be
"<tt>example.so</tt>".
The name of the module is specified using the <tt>%module</tt> directive or the
<tt> -module</tt> command line option.
<tt>-module</tt> command line option.
</p>
<H3><a name="Tcl_nn5"></a>39.1.3 Static linking</H3>
@ -504,7 +504,7 @@ name, but you can override it using the <tt>-prefix</tt> option.
</p>
<p>
When the<tt> -namespace</tt> option is used, objects in the module
When the <tt>-namespace</tt> option is used, objects in the module
are always accessed with the namespace name such as <tt>Foo::bar</tt>.
</p>
@ -1283,7 +1283,7 @@ you can use it in Tcl like this:
% x insert Lager
% x get 1
Stout
% puts [l cget -length]
% puts [x cget -length]
3
%
</pre></div>
@ -2365,7 +2365,7 @@ Tcl extension by specifying the following in an interface file :
$action // Gets substituted by actual function call
}
catch (RangeError) {
Tcl_SetStringObj(tcl_result,"Array index out-of-bounds");
Tcl_SetResult(interp, (char *)"Array index out-of-bounds", TCL_STATIC);
return TCL_ERROR;
}
}
@ -2384,7 +2384,7 @@ exception handler to only apply to specific methods like this:
$action
}
catch (RangeError) {
Tcl_SetStringObj(tcl_result,"Array index out-of-bounds");
Tcl_SetResult(interp, (char *)"Array index out-of-bounds", TCL_STATIC);
return TCL_ERROR;
}
}
@ -2394,7 +2394,7 @@ exception handler to only apply to specific methods like this:
$action
}
catch (RangeError) {
Tcl_SetStringObj(tcl_result,"Array index out-of-bounds");
Tcl_SetResult(interp, (char *)"Array index out-of-bounds", TCL_STATIC);
return TCL_ERROR;
}
}
@ -2419,7 +2419,7 @@ For example:
$action
}
catch (RangeError) {
Tcl_SetStringObj(tcl_result,"Array index out-of-bounds");
Tcl_SetResult(interp, (char *)"Array index out-of-bounds", TCL_STATIC);
return TCL_ERROR;
}
}
@ -2921,7 +2921,6 @@ int Tcl_GetDoubleFromObj(Tcl_Interp *, Tcl_Obj *o, double *dp);
<div class="code">
<pre>
Tcl_Obj *Tcl_NewStringObj(char *str, int len);
void Tcl_SetStringObj(Tcl_Obj *obj, char *str, int len);
char *Tcl_GetStringFromObj(Tcl_Obj *obj, int *len);
void Tcl_AppendToObj(Tcl_Obj *obj, char *str, int len);
</pre>
@ -3037,9 +3036,10 @@ work)
<div class="code">
<pre>
%typemap(out) char * {
Tcl_SetStringObj($result,$1);
%typemap(out,noblock=1,fragment="SWIG_FromCharPtr") char *, const char * {
Tcl_SetObjResult(interp,SWIG_FromCharPtr((const char *)$1));
}
</pre>
</div>

View file

@ -2050,6 +2050,22 @@ wrap_foo() {
</pre>
</div>
<p>There is an exception: if the variable name starts with the <tt>_global_</tt> prefix,
the argument number is not appended. Such variables can be used throughout the generated
wrapper function. For example, the above typemap could be rewritten to use <tt>_global_temp</tt>
instead of <tt>temp</tt> and the generated code would then contain a single <tt>_global_temp</tt> variable
instead of <tt>temp1</tt>, <tt>temp2</tt> and <tt>temp3</tt>:
</p>
<div class="code">
<pre>
%typemap(in) std::string * <b>(std::string _global_temp)</b> {
... as above ...
}
</pre>
</div>
<p>
Some typemaps do not recognize local variables (or they may simply not
apply). At this time, only typemaps that apply to argument conversion support this (input typemaps such as the "in" typemap).
@ -3360,7 +3376,7 @@ list of strings like this:
</div>
<p>
To do this, you not only need to map a list of strings to <tt> char *argv[]</tt>, but the
To do this, you not only need to map a list of strings to <tt>char *argv[]</tt>, but the
value of <tt>int argc</tt> is implicitly determined by the length of the list. Using only simple
typemaps, this type of conversion is possible, but extremely painful.
Multi-argument typemaps help in this situation.

View file

@ -130,6 +130,7 @@ OBJS = $(SRCS:.c=.@OBJEXT@) $(CXXSRCS:.cxx=.@OBJEXT@)
distclean:
rm -f Makefile
rm -f d/example.mk
rm -f xml/Makefile
##################################################################
@ -738,10 +739,10 @@ javascript_clean:
##### ANDROID ######
##################################################################
ANDROID = android
ANDROID_NDK_BUILD = ndk-build
ANDROID_ADB = adb
ANT = ant
ANDROID = @ANDROID@
ANDROID_NDK_BUILD = @NDKBUILD@
ANDROID_ADB = @ADB@
ANT = @ANT@
TARGETID = 1
# ----------------------------------------------------------------
@ -784,7 +785,7 @@ android_version:
# -----------------------------------------------------------------
android_clean:
test -n "$(SRCDIR)" && cd $(SRCDIR) ; ant -q -logfile /dev/null clean
test -n "$(SRCDIR)" && cd $(SRCDIR) ; $(ANT) -q -logfile /dev/null clean
rm -f $(INTERFACEDIR)$(TARGET)_wrap.*
rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java`
rm -rf obj
@ -1396,6 +1397,7 @@ csharp_run:
# Version check below also works with MS csc.exe which does not understand --version
csharp_version:
$(CSHARPCOMPILER) --version | head -n 1
if test -n "$(CSHARPCILINTERPRETER)" ; then "$(CSHARPCILINTERPRETER)" --version ; fi
# -----------------------------------------------------------------
# Cleaning the CSharp examples
@ -1874,7 +1876,7 @@ d_compile: $(SRCDIR_SRCS)
# -----------------------------------------------------------------
d_run:
$(RUNTOOL) $(D_RUNME) $(RUNPIPE)
env LD_LIBRARY_PATH=$$PWD $(RUNTOOL) $(D_RUNME) $(RUNPIPE)
# -----------------------------------------------------------------
# Version display

View file

@ -7,7 +7,7 @@ public:
}
virtual ~Shape() {
nshapes--;
};
}
double x, y;
void move(double dx, double dy);
virtual double area(void) = 0;
@ -19,7 +19,7 @@ class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { };
Circle(double r) : radius(r) { }
virtual double area(void);
virtual double perimeter(void);
};
@ -28,7 +28,7 @@ class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
Square(double w) : width(w) { }
virtual double area(void);
virtual double perimeter(void);
};

View file

@ -4,8 +4,8 @@ class Vector {
private:
double x,y,z;
public:
Vector() : x(0), y(0), z(0) { };
Vector(double x, double y, double z) : x(x), y(y), z(z) { };
Vector() : x(0), y(0), z(0) { }
Vector(double x, double y, double z) : x(x), y(y), z(z) { }
friend Vector operator+(const Vector &a, const Vector &b);
char *print();
};
@ -20,7 +20,3 @@ public:
Vector &operator[](int);
int size();
};

View file

@ -29,7 +29,7 @@ public:
VectorArray(int maxsize);
~VectorArray();
int size();
/* This wrapper provides an alternative to the [] operator */
%extend {
Vector &get(int index) {
@ -40,7 +40,3 @@ public:
}
}
};

View file

@ -1,27 +1 @@
ifeq (2,$(D_VERSION))
WORKING_DIR = d2/
else
WORKING_DIR = d1/
endif
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx
EXTRA_LDFLAGS = example.o example_wrap.o
TARGET = example_wrap
SWIGOPT =
DSRCS = *.d
DFLAGS = -ofrunme
check: build
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run
build:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
clean:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean
include ../example.mk

View file

@ -1,27 +1 @@
ifeq (2,$(D_VERSION))
WORKING_DIR = d2/
else
WORKING_DIR = d1/
endif
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx
EXTRA_LDFLAGS = example.o example_wrap.o
TARGET = example_wrap
SWIGOPT =
DSRCS = *.d
DFLAGS = -ofrunme
check: build
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run
build:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
clean:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean
include ../example.mk

View file

@ -1,27 +1 @@
ifeq (2,$(D_VERSION))
WORKING_DIR = d2/
else
WORKING_DIR = d1/
endif
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
EXTRA_CFLAGS = -I../ example_wrap.c
EXTRA_LDFLAGS = example_wrap.o
TARGET = example_wrap
SWIGOPT =
DSRCS = *.d
DFLAGS = -ofrunme
check: build
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run
build:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
clean:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean
include ../example.mk

View file

@ -1,23 +0,0 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 1.3.41
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
module example;
static import example_wrap;
static import tango.stdc.stringz;
public const int ICONST = 42;
public const double FCONST = 2.1828;
public const char CCONST = 'x';
public const char CCONST2 = '\n';
public const char[] SCONST = "Hello World";
public const char[] SCONST2 = "\"Hello World\"";
public const double EXPR = 42+3*(2.1828);
public const int iconst = 37;
public const double fconst = 3.14;

View file

@ -1,27 +1 @@
ifeq (2,$(D_VERSION))
WORKING_DIR = d2/
else
WORKING_DIR = d1/
endif
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx
EXTRA_LDFLAGS = example.o example_wrap.o
TARGET = example_wrap
SWIGOPT =
DSRCS = *.d
DFLAGS = -ofrunme
check: build
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run
build:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
clean:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean
include ../example.mk

50
Examples/d/example.mk.in Normal file
View file

@ -0,0 +1,50 @@
#
# Common Makefile code for building D examples.
#
# We actually need to configure this to gain access to the default D version to
# use when D_VERSION is not set. Using Examples/Makefile.in is not enough, as
# the location of the source files (d1/ or d2/) depends on it. The alternative
# would be to add the functionality specific to Examples/d (as opposed to the
# test suite) directly to Examples/Makefile.in.
#
# This file is supposed to be included from a Makefile in the subdirectory
# corresponding to a specific example.
#
ifeq (,$(D_VERSION))
D_VERSION = @DDEFAULTVERSION@
endif
ifeq (1,$(D_VERSION))
VERSION_DIR = d1/
else
VERSION_DIR = d2/
endif
EXAMPLES_TOP = ../../..
SWIG_TOP = ../../../..
SWIG = $(SWIG_TOP)/preinst-swig
EXTRA_CFLAGS =
EXTRA_CXXFLAGS =
EXTRA_LDFLAGS =
TARGET = example_wrap
SWIGOPT = -outcurrentdir
DSRCS = *.d
DFLAGS = -ofrunme
check: build
$(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' d_run
build:
mkdir -p $(VERSION_DIR)
if [ -f $(SRCDIR)example.cxx ]; then \
$(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' EXTRA_CXXFLAGS='$(EXTRA_CXXFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' CXXSRCS='example.cxx' d_cpp; \
elif [ -f $(SRCDIR)example.c ]; then \
$(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' SRCS='example.c' d; \
else \
$(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' SRCS='' d; \
fi
$(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' DSRCS='../$(SRCDIR)$(VERSION_DIR)runme.d $(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
clean:
$(MAKE) -C $(VERSION_DIR) -f $(EXAMPLES_TOP)/Makefile SRCDIR='../$(SRCDIR)' d_clean

View file

@ -1,27 +1 @@
ifeq (2,$(D_VERSION))
WORKING_DIR = d2/
else
WORKING_DIR = d1/
endif
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx
EXTRA_LDFLAGS = example.o example_wrap.o
TARGET = example_wrap
SWIGOPT =
DSRCS = *.d
DFLAGS = -ofrunme
check: build
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run
build:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
clean:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean
include ../example.mk

View file

@ -1,27 +1 @@
ifeq (2,$(D_VERSION))
WORKING_DIR = d2/
else
WORKING_DIR = d1/
endif
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
EXTRA_CFLAGS = -I../ ../example.c example_wrap.c
EXTRA_LDFLAGS = example.o example_wrap.o
TARGET = example_wrap
SWIGOPT =
DSRCS = *.d
DFLAGS = -ofrunme
check: build
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run
build:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
clean:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean
include ../example.mk

View file

@ -1,27 +1 @@
ifeq (2,$(D_VERSION))
WORKING_DIR = d2/
else
WORKING_DIR = d1/
endif
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
EXTRA_CFLAGS = -I../ ../example.c example_wrap.c
EXTRA_LDFLAGS = example.o example_wrap.o
TARGET = example_wrap
SWIGOPT =
DSRCS = *.d
DFLAGS = -ofrunme
check: build
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run
build:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
clean:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean
include ../example.mk

View file

@ -1,27 +1 @@
ifeq (2,$(D_VERSION))
WORKING_DIR = d2/
else
WORKING_DIR = d1/
endif
TOP = ../../..
SWIG = $(TOP)/../preinst-swig
EXTRA_CFLAGS = -I../ ../example.c example_wrap.c
EXTRA_LDFLAGS = example.o example_wrap.o
TARGET = example_wrap
SWIGOPT =
DSRCS = *.d
DFLAGS = -ofrunme
check: build
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_run
build:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
clean:
cd $(WORKING_DIR); \
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' d_clean
include ../example.mk

View file

@ -4,8 +4,8 @@ class Vector {
private:
double x,y,z;
public:
Vector() : x(0), y(0), z(0) { };
Vector(double x, double y, double z) : x(x), y(y), z(z) { };
Vector() : x(0), y(0), z(0) { }
Vector(double x, double y, double z) : x(x), y(y), z(z) { }
friend Vector operator+(const Vector &a, const Vector &b);
char *print();
};
@ -20,7 +20,3 @@ public:
Vector &operator[](int);
int size();
};

View file

@ -29,7 +29,7 @@ public:
VectorArray(int maxsize);
~VectorArray();
int size();
/* This wrapper provides an alternative to the [] operator */
%extend {
Vector &get(int index) {

View file

@ -4,8 +4,8 @@ class Vector {
private:
double x,y,z;
public:
Vector() : x(0), y(0), z(0) { };
Vector(double x, double y, double z) : x(x), y(y), z(z) { };
Vector() : x(0), y(0), z(0) { }
Vector(double x, double y, double z) : x(x), y(y), z(z) { }
friend Vector operator+(const Vector &a, const Vector &b);
char *print();
};
@ -20,7 +20,3 @@ public:
Vector &operator[](int);
int size();
};

View file

@ -29,7 +29,7 @@ public:
VectorArray(int maxsize);
~VectorArray();
int size();
/* This wrapper provides an alternative to the [] operator */
%extend {
Vector &get(int index) {
@ -40,4 +40,3 @@ public:
}
}
};

View file

@ -7,12 +7,18 @@ else
JSENGINE=node
endif
ifneq (, $(V8_VERSION))
JSV8_VERSION=$(V8_VERSION)
else
JSV8_VERSION=0x031110
endif
EXAMPLES_TOP=../..
SWIG_TOP=../../..
SWIG = $(SWIG_TOP)/preinst-swig
TARGET = example
INTERFACE = example.i
SWIGOPT=-$(JSENGINE)
SWIGOPT=-$(JSENGINE) -DV8_VERSION=$(JSV8_VERSION)
check: build
$(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' JSENGINE='$(JSENGINE)' TARGET='$(TARGET)' javascript_run

View file

@ -4,8 +4,8 @@ class Vector {
private:
double x,y,z;
public:
Vector() : x(0), y(0), z(0) { };
Vector(double x, double y, double z) : x(x), y(y), z(z) { };
Vector() : x(0), y(0), z(0) { }
Vector(double x, double y, double z) : x(x), y(y), z(z) { }
friend Vector operator+(const Vector &a, const Vector &b);
char *print();
};
@ -20,7 +20,3 @@ public:
Vector &operator[](int);
int size();
};

View file

@ -29,7 +29,7 @@ public:
VectorArray(int maxsize);
~VectorArray();
int size();
/* This wrapper provides an alternative to the [] operator */
%extend {
Vector &get(int index) {

View file

@ -9,20 +9,20 @@ console.log(example.maxdouble(3.14,2.18));
iv = new example.vecint(100);
dv = new example.vecdouble(1000);
for(i=0;i<=100;i++)
for(i=0;i<100;i++)
iv.setitem(i,2*i);
for(i=0;i<=1000;i++)
for(i=0;i<1000;i++)
dv.setitem(i, 1.0/(i+1));
sum = 0;
for(i=0;i<=100;i++)
for(i=0;i<100;i++)
sum = sum + iv.getitem(i);
console.log(sum);
sum = 0.0;
for(i=0;i<=1000;i++)
for(i=0;i<1000;i++)
sum = sum + dv.getitem(i);
console.log(sum);

View file

@ -3,25 +3,25 @@ print "[lua] This is runme.lua"
-- we do not need to load the library, as it was already in the interpreter
-- but let's check anyway
assert(type(example)=='table',"Don't appear to have loaded the example module")
-- note: we will copy the functions from example table into global
-- this will help us later
for k,v in pairs(example) do _G[k]=v end
-- our add function
-- note: we will copy the functions from example table into global
-- this will help us later
for k,v in pairs(example) do _G[k]=v end
-- our add function
-- we will be calling this from C
function add(a,b)
print("[lua] this is function add(",a,b,")")
c=a+b
print("[lua] returning",c)
return c
function add(a,b)
print("[lua] this is function add(",a,b,")")
c=a+b
print("[lua] returning",c)
return c
end
function append(a,b)
print("[lua] this is function append(",a,b,")")
c=a..b
print("[lua] returning",c)
return c
function append(a,b)
print("[lua] this is function append(",a,b,")")
c=a..b
print("[lua] returning",c)
return c
end

View file

@ -1,7 +1,7 @@
class Base {
public:
Base() { };
virtual ~Base() { };
Base() { }
virtual ~Base() { }
virtual const char * A() const {
return "Base::A";
}

View file

@ -8,7 +8,7 @@ public:
}
virtual ~Shape() {
nshapes--;
};
}
double x, y;
void move(double dx, double dy);
virtual double area(void) = 0;
@ -20,7 +20,7 @@ class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { };
Circle(double r) : radius(r) { }
virtual double area(void);
virtual double perimeter(void);
};
@ -29,7 +29,7 @@ class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
Square(double w) : width(w) { }
virtual double area(void);
virtual double perimeter(void);
};

View file

@ -4,8 +4,8 @@ struct Vector {
private:
double x,y,z;
public:
Vector() : x(0), y(0), z(0) { };
Vector(double x, double y, double z) : x(x), y(y), z(z) { };
Vector() : x(0), y(0), z(0) { }
Vector(double x, double y, double z) : x(x), y(y), z(z) { }
Vector operator+(const Vector &b) const;
char *print();
};

View file

@ -1,5 +1,8 @@
/* File : example.i */
%module(directors="1") swigexample
%feature("autodoc", 1);
%{
#include "example.h"
%}

View file

@ -1,6 +1,8 @@
/* File : example.i */
%module swigexample
%feature("autodoc", 1);
%{
#include "example.h"
%}

View file

@ -1,6 +1,8 @@
/* File : example.i */
%module swigexample
%feature("autodoc", 1);
/* A few preprocessor macros */
#define ICONST 42

View file

@ -1,6 +1,8 @@
/* File : example.i */
%module swigexample
%feature("autodoc", 1);
%contract gcd(int x, int y) {
require:
x >= 0;

View file

@ -1,6 +1,8 @@
/* File : example.i */
%module swigexample
%feature("autodoc", 1);
%{
#include "example.h"
%}

View file

@ -1,5 +1,8 @@
/* File : example.i */
%module(directors="1") swigexample
%feature("autodoc", 1);
%{
#include "example.h"
%}

View file

@ -1,5 +1,8 @@
/* File : example.i */
%module swigexample
%feature("autodoc", 1);
%{
#include "example.h"
%}

View file

@ -1,5 +1,8 @@
/* File : example.i */
%module swigexample
%feature("autodoc", 1);
%{
#include "example.h"
%}

View file

@ -1,6 +1,7 @@
/* File : example.i */
%module swigexample
%feature("autodoc", 1);
%inline %{
// From B. Strousjoup, "The C++ Programming Language, Third Edition", p. 514

View file

@ -1,5 +1,8 @@
/* File : example.i */
/* module name given on cmdline */
%feature("autodoc", 1);
%{
#include "example.h"
%}

View file

@ -1,6 +1,10 @@
/* File : example.i */
%module swigexample
%feature("autodoc", 1);
#pragma SWIG nowarn=SWIGWARN_IGNORE_OPERATOR_EQ
%{
#include "example.h"
%}

View file

@ -1,6 +1,8 @@
/* File : example.i */
%module swigexample
%feature("autodoc", 1);
%{
extern void add(int *, int *, int *);
extern void sub(int *, int *, int *);

View file

@ -4,8 +4,8 @@ class Vector {
private:
double x,y,z;
public:
Vector() : x(0), y(0), z(0) { };
Vector(double x, double y, double z) : x(x), y(y), z(z) { };
Vector() : x(0), y(0), z(0) { }
Vector(double x, double y, double z) : x(x), y(y), z(z) { }
friend Vector operator+(const Vector &a, const Vector &b);
char *print();
};

View file

@ -4,6 +4,8 @@
%module swigexample
%feature("autodoc", 1);
%{
#include "example.h"
%}

View file

@ -1,6 +1,8 @@
/* File : example.i */
%module swigexample
%feature("autodoc", 1);
%inline %{
extern int gcd(int x, int y);
extern double Foo;

View file

@ -1,6 +1,8 @@
/* File : example.i */
%module swigexample
%feature("autodoc", 1);
%{
#include "example.h"
%}

View file

@ -1,5 +1,8 @@
/* File : example.i */
%module swigexample
%feature("autodoc", 1);
%{
#include "example.h"
%}

View file

@ -2,8 +2,8 @@
class Base {
public:
Base() { };
virtual ~Base() { };
Base() { }
virtual ~Base() { }
virtual void A() {
printf("I'm Base::A\n");
}

View file

@ -4,8 +4,8 @@ class Vector {
private:
double x,y,z;
public:
Vector() : x(0), y(0), z(0) { };
Vector(double x, double y, double z) : x(x), y(y), z(z) { };
Vector() : x(0), y(0), z(0) { }
Vector(double x, double y, double z) : x(x), y(y), z(z) { }
friend Vector operator+(const Vector &a, const Vector &b);
char *print();
};
@ -20,7 +20,3 @@ public:
Vector &operator[](int);
int size();
};

View file

@ -29,7 +29,7 @@ public:
VectorArray(int maxsize);
~VectorArray();
int size();
/* This wrapper provides an alternative to the [] operator */
%extend {
Vector &get(int index) {
@ -40,7 +40,3 @@ public:
}
}
};

View file

@ -9,7 +9,7 @@ public:
}
virtual ~Shape() {
nshapes--;
};
}
double x, y;
void move(double dx, double dy);
virtual double area(void) = 0;
@ -22,8 +22,8 @@ class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { };
~Circle() { };
Circle(double r) : radius(r) { }
~Circle() { }
void set_radius( double r );
virtual double area(void);
virtual double perimeter(void);
@ -33,7 +33,7 @@ class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
Square(double w) : width(w) { }
~Square() { }
virtual double area(void);
virtual double perimeter(void);
@ -44,7 +44,7 @@ private:
typedef std::vector<Shape*>::iterator iterator;
std::vector<Shape*> shapes;
public:
ShapeContainer() : shapes() {};
ShapeContainer() : shapes() {}
~ShapeContainer();
void addShape( Shape *s );
};

View file

@ -9,7 +9,7 @@ public:
}
virtual ~Shape() {
nshapes--;
};
}
double x, y;
void move(double dx, double dy);
virtual double area(void) = 0;
@ -22,8 +22,8 @@ class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { };
~Circle() { };
Circle(double r) : radius(r) { }
~Circle() { }
void set_radius( double r );
virtual double area(void);
virtual double perimeter(void);
@ -33,7 +33,7 @@ class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
Square(double w) : width(w) { }
~Square() { }
virtual double area(void);
virtual double perimeter(void);

View file

@ -4,8 +4,8 @@ class Vector {
private:
double x,y,z;
public:
Vector() : x(0), y(0), z(0) { };
Vector(double x, double y, double z) : x(x), y(y), z(z) { };
Vector() : x(0), y(0), z(0) { }
Vector(double x, double y, double z) : x(x), y(y), z(z) { }
friend Vector operator+(const Vector &a, const Vector &b);
char *as_string();
};
@ -20,7 +20,3 @@ public:
Vector &operator[](int);
int size();
};

View file

@ -1,10 +1,6 @@
/* File : example.i */
/* This example has nothing to do with references but the name is used by all
* the other languages so it's hard to rename to something more meaningful.
*
* Mostly it shows how to use %extend.
*/
/* This file has a few "typical" uses of C++ references. */
%module example
@ -33,8 +29,8 @@ public:
VectorArray(int maxsize);
~VectorArray();
int size();
/* This wrapper provides an alternative to the [] operator */
/* This wrapper provides an alternative to the [] operator */
%extend {
Vector &get(int index) {
printf("VectorArray extended get: %p %d\n", (void *)$self, index);

View file

@ -24,7 +24,6 @@ simple
smartptr
std_vector
std_map
swigrun
template
varargs
variables

View file

@ -10,3 +10,12 @@
/* Let's just grab the original header file here */
%include "example.h"
%inline %{
// The -builtin SWIG option results in SWIGPYTHON_BUILTIN being defined
#ifdef SWIGPYTHON_BUILTIN
bool is_python_builtin() { return true; }
#else
bool is_python_builtin() { return false; }
#endif
%}

View file

@ -20,10 +20,17 @@ try:
except RuntimeError,e:
print e.args[0]
try:
t.hosed()
except example.Exc,e:
print e.code, e.msg
if not example.is_python_builtin():
try:
t.hosed()
except example.Exc,e:
print e.code, e.msg
else:
try:
t.hosed()
except BaseException,e:
# Throwing builtin classes as exceptions not supported (-builtin option)
print e
for i in range(1,4):
try:

View file

@ -109,6 +109,12 @@
%template(doubleQueue) Queue<double>;
%inline %{
// The -builtin SWIG option results in SWIGPYTHON_BUILTIN being defined
#ifdef SWIGPYTHON_BUILTIN
bool is_python_builtin() { return true; }
#else
bool is_python_builtin() { return false; }
#endif
%}

View file

@ -1,10 +1,16 @@
# file: runme.py
import example
if example.is_python_builtin():
print "Skipping example: -builtin option does not support %exceptionclass"
exit(0)
q = example.intQueue(10)
print "Inserting items into intQueue"
print type(example.FullError)
try:
for i in range(0,100):
q.enqueue(i)

View file

@ -2,8 +2,8 @@
class Base {
public:
Base() { };
virtual ~Base() { };
Base() { }
virtual ~Base() { }
virtual void A() {
printf("I'm Base::A\n");
}

View file

@ -11,7 +11,8 @@ import_packages_subdirs = \
from_init2 \
from_init3 \
relativeimport1 \
relativeimport1
relativeimport2 \
relativeimport3
check: build
if test "x$(SRCDIR)" != x; then \

View file

@ -1,6 +1,10 @@
# Test import of modules content from within __init__.py
print "Testing %module(package=...) + python 'import' in __init__.py"
import sys
import os.path
# Test import of modules content from within __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
if sys.version_info < (3,0):
import py2.pkg2
print " Finished importing py2.pkg2"

View file

@ -1,6 +1,10 @@
# Test import of modules content from within __init__.py
print "Testing %module(package=...) + python 'import' in __init__.py"
import sys
import os.path
# Test import of modules content from within __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
if sys.version_info < (3,0):
import py2.pkg2
print " Finished importing py2.pkg2"

View file

@ -1,6 +1,10 @@
# Test import of modules content from within __init__.py
print "Testing %module(package=...) + python 'import' in __init__.py"
import sys
import os.path
# Test import of modules content from within __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
if sys.version_info < (3,0):
import py2.pkg2
print " Finished importing py2.pkg2"

View file

@ -1,6 +1,10 @@
# Test import of modules content from within __init__.py
print "Testing %module(package=...) with -relativeimport"
import sys
import os.path
# Test import of modules content from within __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) with -relativeimport"
if sys.version_info < (3,0):
import py2.pkg2.bar
print " Finished importing py2.pkg2.bar"

View file

@ -1,6 +1,10 @@
# Test import of modules content from within __init__.py
print "Testing %module(package=...) + python 'import' in __init__.py"
import sys
import os.path
# Test import of modules content from within __init__.py
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
if sys.version_info < (3,0):
import py2.pkg2.bar
print " Finished importing py2.pkg2.bar"

View file

@ -1,9 +0,0 @@
# Test import of modules content from within __init__.py
print("Testing %module(package=...) + python 'import' in __init__.py")
import sys
if sys.version_info < (3, 0):
import py2.pkg2.bar
print(" Finished importing py2.pkg2.bar")
else:
import py3.pkg2.bar
print(" Finished importing py3.pkg2.bar")

View file

@ -0,0 +1,25 @@
TOP = ../../..
SWIG = $(realpath $(TOP)/../preinst-swig)
SWIGOPT =
LIBS =
PY3 =
ifeq (,$(PY3))
PKG1DIR = "py2"
else
PKG1DIR = "py3"
endif
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
build:
cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build
static:
cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd py2 && $(MAKE) clean
cd py3 && $(MAKE) clean

View file

@ -0,0 +1,22 @@
This example tests the %import directive and -relativeimport swig option.
Use 'python runme.py' to run a test.
Overview:
---------
The example defines 2 different extension modules--each wrapping a separate C++
class.
pyX/pkg2/pkg3/foo.i - Pkg3_Foo class
pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg3_Foo
The code is processed by swig with -relativeimport flag. The runtime test
imports pyX.pkg2.bar module.
If everything works well, the module pyX.pkg2.bar shall load properly.
Unix:
-----
- Run make
- Run the test as described above

View file

@ -0,0 +1,14 @@
TOP = ../../../..
SWIG = $(realpath $(TOP)/../preinst-swig)
SWIGOPT =
LIBS =
build:
cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd pkg2 && $(MAKE) clean

View file

@ -0,0 +1,18 @@
TOP = ../../../../..
SWIG = $(realpath $(TOP)/../preinst-swig)
SWIGOPT =
LIBS =
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean
cd pkg3 && $(MAKE) clean

View file

@ -0,0 +1,5 @@
#ifndef PY2_PKG2_BAR_HPP
#define PY2_PKG2_BAR_HPP
#include "../../py2/pkg2/pkg3/foo.hpp"
struct Pkg2_Bar : Pkg3_Foo {};
#endif /* PY2_PKG2_BAR_HPP */

View file

@ -0,0 +1,6 @@
%module(package="py2.pkg2") bar
%{
#include "../../py2/pkg2/bar.hpp"
%}
%import (module="foo", package="py2.pkg2.pkg3") "../../py2/pkg2/pkg3/foo.hpp"
%include "../../py2/pkg2/bar.hpp"

View file

@ -0,0 +1,15 @@
TOP = ../../../../../..
SWIG = $(realpath $(TOP)/../preinst-swig)
SWIGOPT =
LIBS =
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp
static:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean

View file

@ -0,0 +1,4 @@
#ifndef PY2_PKG2_PKG3_FOO_HPP
#define PY2_PKG2_PKG3_FOO_HPP
struct Pkg3_Foo {};
#endif /* PY2_PKG2_PKG3_FOO_HPP */

View file

@ -0,0 +1,5 @@
%module(package="py2.pkg2.pkg3") foo
%{
#include "../../../py2/pkg2/pkg3/foo.hpp"
%}
%include "../../../py2/pkg2/pkg3/foo.hpp"

View file

@ -0,0 +1,14 @@
TOP = ../../../..
SWIG = $(realpath $(TOP)/../preinst-swig)
SWIGOPT =
LIBS =
build:
cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean
cd pkg2 && $(MAKE) clean

View file

@ -0,0 +1,18 @@
TOP = ../../../../..
SWIG = $(realpath $(TOP)/../preinst-swig)
SWIGOPT =
LIBS =
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build
static:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean
cd pkg3 && $(MAKE) clean

View file

@ -0,0 +1,5 @@
#ifndef PY3_PKG2_BAR_HPP
#define PY3_PKG2_BAR_HPP
#include "../../py3/pkg2/pkg3/foo.hpp"
struct Pkg2_Bar : Pkg3_Foo {};
#endif /* PY3_PKG2_BAR_HPP */

Some files were not shown because too many files have changed in this diff Show more