Merge branch 'master' into doxygen

Merge with ~3.0.1 sources from master.
This commit is contained in:
Vadim Zeitlin 2014-04-30 18:37:57 +02:00
commit 1ebd2334b8
1593 changed files with 51732 additions and 28076 deletions

2
.gitattributes vendored Normal file
View file

@ -0,0 +1,2 @@
.gitattributes export-ignore
.gitignore export-ignore

130
.gitignore vendored Normal file
View file

@ -0,0 +1,130 @@
# Compiled Source
*.o
*.class
# Editor files and various other junk
.*.sw?
*.bak
# Local PCRE
pcre
*.gz
# C/C++ object files, based on:
# https://github.com/github/gitignore/blob/master/C.gitignore
# https://github.com/github/gitignore/blob/master/C%2B%2B.gitignore
*.slo
*.lo
# C/C++ dynamic libraries, based on:
# https://github.com/github/gitignore/blob/master/C.gitignore
# https://github.com/github/gitignore/blob/master/C%2B%2B.gitignore
*.dll
*.so
*.so.*
*.dylib
# C/C++ static libraries, based on:
# https://github.com/github/gitignore/blob/master/C.gitignore
# https://github.com/github/gitignore/blob/master/C%2B%2B.gitignore
*.lib
*.lai
*.la
*.a
# C/C++ executables, based on:
# https://github.com/github/gitignore/blob/master/C.gitignore
# https://github.com/github/gitignore/blob/master/C%2B%2B.gitignore
*.exe
*.out
*.app
# Generated by autogen.sh
CCache/autom4te.cache/
CCache/config.h.in
CCache/configure
Source/Include/swigconfig.h.in
Source/Include/swigconfig.h.in~
Source/Makefile.in
Tools/config/compile
Tools/config/config.guess
Tools/config/config.sub
Tools/config/depcomp
Tools/config/install-sh
Tools/config/missing
Tools/config/ylwrap
aclocal.m4
autom4te.cache/
configure
# Generated by ./configure
CCache/Makefile
CCache/ccache_swig_config.h
CCache/config.h
CCache/config.log
CCache/config.status
Examples/Makefile
Examples/guile/Makefile
Examples/test-suite/*/Makefile
Examples/xml/Makefile
/Makefile
Source/Include/stamp-h1
Source/Include/swigconfig.h
Source/Makefile
.deps
config.log
config.status
preinst-swig
swig.spec
# Build Artifacts
.dirstamp
CCache/ccache-swig
CCache/ccache-swig.1
Lib/swigwarn.swg
Source/CParse/parser.c
Source/CParse/parser.h
Source/eswig
swig
# Generated documentation
Doc/Manual/CCache.html
Doc/Manual/SWIGDocumentation.html
Doc/Manual/SWIGDocumentation.pdf
Doc/Manual/*.book
# Test Suite Generated Files
Examples/test-suite/allegrocl/*/
Examples/test-suite/cffi/*/
Examples/test-suite/chicken/*/
Examples/test-suite/clisp/*/
Examples/test-suite/csharp/*/
Examples/test-suite/d/*/
Examples/test-suite/go/*/
Examples/test-suite/guile/*/
Examples/test-suite/java/*/
Examples/test-suite/lua/*/
Examples/test-suite/mzscheme/*/
Examples/test-suite/ocaml/*/
Examples/test-suite/octave/*/
Examples/test-suite/perl5/*/
Examples/test-suite/php/*/
Examples/test-suite/pike/*/
Examples/test-suite/python/*/
Examples/test-suite/r/*/
Examples/test-suite/ruby/*/
Examples/test-suite/tcl/*/
Examples/test-suite/uffi/*/
# Python generated files, based on:
# https://github.com/github/gitignore/blob/master/Python.gitignore
*.py[cod]
*/__pycache__/
/__pycache__/
# C# generated files
*_runme.exe.mdb
*_runme.exe
# Scratch directories
Examples/scratch

View file

@ -1,32 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SWIG</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.autotools.core.genmakebuilderV2</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>org.eclipse.cdt.autotools.core.autotoolsNatureV2</nature>
</natures>
</projectDescription>

View file

@ -1,8 +1,73 @@
language: cpp
compiler:
- gcc
- clang
script: ./autogen.sh && ./configure && make -s
- gcc
env:
- SWIGLANG=
matrix:
include:
- compiler: gcc
env: SWIGLANG=csharp
- compiler: gcc
env: SWIGLANG=go
- compiler: gcc
env: SWIGLANG=guile
- compiler: gcc
env: SWIGLANG=java
- compiler: gcc
env: SWIGLANG=lua
- compiler: gcc
env: SWIGLANG=octave SWIGJOBS=-j4
- compiler: gcc
env: SWIGLANG=perl5
- compiler: gcc
env: SWIGLANG=php
- compiler: gcc
env: SWIGLANG=python VER=2.4
- compiler: gcc
env: SWIGLANG=python VER=2.5
- compiler: gcc
env: SWIGLANG=python VER=2.6
- compiler: gcc
env: SWIGLANG=python # 2.7
- compiler: gcc
env: SWIGLANG=python PY3=3 # 3.2
- compiler: gcc
env: SWIGLANG=python PY3=3 VER=3.3
- compiler: gcc
env: SWIGLANG=python PY3=3 VER=3.4
- compiler: gcc
env: SWIGLANG=ruby
- compiler: gcc
env: SWIGLANG=tcl
allow_failures:
# None
before_install:
- date -u
- lsb_release -a
- uname -a
- sudo apt-get -qq update
- 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" = "go"; then go env | sed -e 's/^/export /' > goenvsetup && source goenvsetup && rm -f goenvsetup; fi # Until configure.ac is fixed
- 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" = "php"; then sudo apt-get install php5-cli php5-dev; fi
- if test "$SWIGLANG" = "python" -a "$PY3" -a -z "$VER"; then sudo apt-get install -qq python3-dev; fi
- if test "$SWIGLANG" = "python" -a "$VER"; then sudo add-apt-repository -y ppa:fkrull/deadsnakes && sudo apt-get -qq update && sudo apt-get -qq install python${VER}-dev && export CONFIGOPTS="--with-python${PY3}=python${VER}"; fi
- if test "$SWIGLANG" = "tcl"; then sudo apt-get -qq install tcl8.4-dev; fi
script:
- ./autogen.sh && ./configure $CONFIGOPTS
- make -s $SWIGJOBS
- ./swig -version && ./swig -pcreversion
- if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-ccache; fi
- if test -z "$SWIGLANG"; then make -s $SWIGJOBS check-errors-test-suite; fi
- if test -z "$SWIGLANG"; then sudo make -s install && swig -version && ccache-swig -V; fi
- if test -n "$SWIGLANG"; then make -s check-$SWIGLANG-version; fi
- if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-examples; fi
- if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-test-suite; fi
branches:
only:
- master

View file

@ -1,31 +1,31 @@
*** ANNOUNCE: SWIG 2.0.6 (30 April 2012) ***
*** ANNOUNCE: SWIG 3.0.1 (in progress) ***
http://www.swig.org
We're pleased to announce SWIG-2.0.6, the latest SWIG release.
We're pleased to announce SWIG-3.0.1, the latest SWIG release.
What is SWIG?
=============
SWIG is a software development tool that reads C/C++ header files and
generates the wrapper code needed to make C and C++ code accessible
from other languages including Perl, Python, Tcl, Ruby, PHP, Java,
Scheme (Guile, MzScheme, CHICKEN), D, Ocaml, Lua, Pike, C#, Modula-3,
Octave, R, Common Lisp (CLISP, Allegro CL, CFFI, UFFI). SWIG can also
export its parse tree in the form of XML and Lisp s-expressions. Major
applications of SWIG include generation of scripting language extension
modules, rapid prototyping, testing, and user interface development for
large C/C++ systems.
from other programming languages including Perl, Python, Tcl, Ruby,
PHP, C#, Go, Java, Lua, Scheme (Guile, MzScheme, CHICKEN), D, Ocaml,
Pike, Modula-3, Octave, R, Common Lisp (CLISP, Allegro CL, CFFI, UFFI).
SWIG can also export its parse tree in the form of XML and Lisp
s-expressions. Major applications of SWIG include generation of
scripting language extension modules, rapid prototyping, testing,
and user interface development for large C/C++ systems.
Availability
============
The release is available for download on Sourceforge at
http://prdownloads.sourceforge.net/swig/swig-2.0.6.tar.gz
http://prdownloads.sourceforge.net/swig/swig-3.0.1.tar.gz
A Windows version is also available at
http://prdownloads.sourceforge.net/swig/swigwin-2.0.6.zip
http://prdownloads.sourceforge.net/swig/swigwin-3.0.1.zip
Please report problems with this release to the swig-devel mailing list,
details at http://www.swig.org/mail.html.

View file

@ -712,12 +712,13 @@ static void from_cache(int first)
passfail = retrieve_from_cache(hashname, output_file, hardlink);
}
free(stderr_file);
if (passfail == -1) {
close(fd_stderr);
unlink(stderr_file);
free(stderr_file);
return;
}
free(stderr_file);
}
/* get rid of the intermediate preprocessor file */

View file

@ -159,7 +159,7 @@ int asprintf(char **ptr, const char *format, ...);
int snprintf(char *,size_t ,const char *, ...);
#endif
void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize);
void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize, size_t minfiles);
void cleanup_all(const char *dir);
void wipe_all(const char *dir);
@ -200,6 +200,8 @@ typedef int (*COMPAR_FN_T)(const void *, const void *);
/* mkstemp() on some versions of cygwin don't handle binary files, so
override */
/* Seems okay in Cygwin 1.7.0
#ifdef __CYGWIN__
#undef HAVE_MKSTEMP
#endif
*/

View file

@ -75,21 +75,40 @@ static void traverse_fn(const char *fname, struct stat *st)
/* sort the files we've found and delete the oldest ones until we are
below the thresholds */
static void sort_and_clean(void)
static void sort_and_clean(size_t minfiles)
{
unsigned i;
size_t adjusted_minfiles = minfiles;
if (num_files > 1) {
/* sort in ascending data order */
qsort(files, num_files, sizeof(struct files *),
(COMPAR_FN_T)files_compare);
}
/* ensure newly cached files (minfiles) are kept - instead of matching
the filenames of those newly cached, a faster and simpler approach
assumes these are the most recent in the cache and if any other
cached files have an identical time stamp, they will also be kept -
this approach would not be needed if the cleanup was done at exit. */
if (minfiles != 0 && minfiles < num_files) {
unsigned minfiles_index = num_files - minfiles;
time_t minfiles_time = files[minfiles_index]->mtime;
for (i=1; i<=minfiles_index; i++) {
if (files[minfiles_index-i]->mtime == minfiles_time)
adjusted_minfiles++;
else
break;
}
}
/* delete enough files to bring us below the threshold */
for (i=0;i<num_files; i++) {
if ((size_threshold==0 || total_size < size_threshold) &&
(files_threshold==0 || (num_files-i) < files_threshold)) break;
if (adjusted_minfiles != 0 && num_files-i <= adjusted_minfiles)
break;
if (unlink(files[i]->fname) != 0 && errno != ENOENT) {
fprintf(stderr, "unlink %s - %s\n",
files[i]->fname, strerror(errno));
@ -103,7 +122,7 @@ static void sort_and_clean(void)
}
/* cleanup in one cache subdir */
void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize)
void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize, size_t minfiles)
{
unsigned i;
@ -117,7 +136,7 @@ void cleanup_dir(const char *dir, size_t maxfiles, size_t maxsize)
traverse(dir, traverse_fn);
/* clean the cache */
sort_and_clean();
sort_and_clean(minfiles);
stats_set_sizes(dir, total_files, total_size);
@ -151,7 +170,8 @@ void cleanup_all(const char *dir)
cleanup_dir(dname,
counters[STATS_MAXFILES],
counters[STATS_MAXSIZE]);
counters[STATS_MAXSIZE],
0);
free(dname);
free(sfile);
}

View file

@ -168,7 +168,8 @@ static void stats_update_size(enum stats stat, size_t size, size_t numfiles)
if (need_cleanup) {
char *p = dirname(stats_file);
cleanup_dir(p, counters[STATS_MAXFILES], counters[STATS_MAXSIZE]);
cleanup_dir(p, counters[STATS_MAXFILES], counters[STATS_MAXSIZE],
numfiles);
free(p);
}
}

View file

@ -142,7 +142,7 @@ basetests() {
testname="non-regular"
mkdir testd
$CCACHE_COMPILE -o testd -c test1.c > /dev/null 2>&1
rmdir testd
rm -rf testd
checkstat 'output to a non-regular file' 1
testname="no-input"
@ -315,7 +315,7 @@ swigtests() {
testname="non-regular"
mkdir testd
$CCACHE_COMPILE -o testd -java testswig1.i > /dev/null 2>&1
rmdir testd
rm -rf testd
checkstat 'output to a non-regular file' 1
testname="no-input"

View file

@ -82,7 +82,7 @@ void copy_fd(int fd_in, int fd_out)
#ifndef HAVE_MKSTEMP
/* cheap and nasty mkstemp replacement */
static int mkstemp(char *template)
int mkstemp(char *template)
{
mktemp(template);
return open(template, O_RDWR | O_CREAT | O_EXCL | O_BINARY, 0600);

1264
CHANGES

File diff suppressed because it is too large Load diff

View file

@ -2,16 +2,40 @@ Below are the changes for the current release.
See the CHANGES file for changes in older releases.
See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.6 (30 April 2012)
=============================
Version 3.0.1 (in progress)
===========================
2012-04-25: wsfulton
[Lua] Fix uninitialised variable in SWIGTYPE **OUTPUT typemaps as reported by Jim Anderson.
2014-04-08: wsfulton
SF Bug #1366 - Remove duplicate declarations of strtoimax and strtoumax in inttypes.i
2012-04-28: wsfulton
[Python] Fix compilation errors when wrapping STL containers on Mac OSX and possibly other systems.
2014-04-08: wsfulton
[Java C#] Enums which have been ignored via %ignore and are subsequently
used are handled slightly differently. Type wrapper classes are now generated
which are effectively a wrapper of an empty enum. Previously in Java uncompilable
code was generated and in C# an int was used.
2012-04-28: wsfulton
[Java] Patch 3521811 from Leo Davis - char **STRING_ARRAY typemaps fixed to handle
null pointers.
2014-04-04: wsfulton
Fix regression in 3.0.0 where legal code following an operator<< definition might
give a syntax error. SF Bug #1365.
2014-04-03: olly
[PHP] Fix wrapping director constructors with default parameters
with a ZTS-enabled build of PHP.
2014-04-02: olly
[PHP] Pass the ZTS context we already have to avoid needing to
call TSRMLS_FETCH, which is relatively expensive.
2014-04-02: olly
[PHP] Pass ZTS context through to t_output_helper() so it works
with a ZTS-enabled build of PHP. Reported by Pierre Labastie in
github PR#155.
2014-03-28: wsfulton
[Java C# D Go] Fixes for C enums used in an API and the definition of the enum
has not been parsed. For D, this fixes a segfault in SWIG. The other languages
now produce code that compiles, although the definition of the enum is needed
in order to use the enum properly from the target language.
2014-03-23: v-for-vandal
[Lua] Fix for usage of snprintf in Lua runtime which Visual Studio does not have.

View file

@ -66,7 +66,7 @@ Past contributors include:
James Michael DuPont, Clark McGrew, Dustin Mitchell, Ian Cooke, Catalin Dumitrescu, Baran
Kovuk, Oleg Tolmatcev, Tal Shalif, Lluis Padro, Chris Seatory, Igor Bely, Robin Dunn,
Edward Zimmermann, David Ascher, Dominique Dumont, Pier Giorgio Esposito, Hasan Baran Kovuk,
Klaus Wiederänders
Klaus Wiederänders, Richard Beare, Hans Oesterholt.
(See CHANGES and CHANGES.current and the bug tracker for a more complete list).
Past students:

788
Doc/Devel/cpp11.html Normal file
View file

@ -0,0 +1,788 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
<TITLE></TITLE>
<META NAME="GENERATOR" CONTENT="OpenOffice.org 3.0 (Unix)">
<META NAME="CREATED" CONTENT="20090712;16061100">
<META NAME="CHANGED" CONTENT="20090817;17311900">
<META NAME="Podatek 1" CONTENT="">
<META NAME="Podatek 2" CONTENT="">
<META NAME="Podatek 3" CONTENT="">
<META NAME="Podatek 4" CONTENT="">
<STYLE TYPE="text/css">
<!--
@page { margin: 2cm }
H1 { margin-bottom: 0.21cm }
H1.western { font-family: "Liberation Serif", serif }
H1.cjk { font-family: "DejaVu Sans" }
H1.ctl { font-family: "DejaVu Sans" }
P { margin-bottom: 0.21cm }
H2 { margin-bottom: 0.21cm }
A:link { so-language: zxx }
-->
</STYLE>
</HEAD>
<BODY LANG="en-US" DIR="LTR">
<H1 CLASS="western"><U>C++0x/C++11 support for SWIG</U></H1>
<H1 CLASS="western">Summary</H1>
<P>This is a technical overview of the C++0x/C++11 support for the Swig.
This area of Swig is a work in progress. Initial C++0x/C++11 support for
Swig was written during the Google Summer of Code 2009 period by
Matevž Jekovec.</P>
<H1 CLASS="western">SVN branch</H1>
<P>branches/gsoc2009-matevz</P>
<H1 CLASS="western">New C++11 features status</H1>
<P>Wikipedia article: <A HREF="http://en.wikipedia.org/wiki/C++0x">http://en.wikipedia.org/wiki/C%2B%2B0x</A>
</P>
<H2>Rvalue reference and move semantics [done]</H2>
<P>The Rvalues are used in practice to speed up the move operations
on different containers.</P>
<P>In the following example, we want to swap the given elements:</P>
<PRE>template &lt;class T&gt; swap(T&amp; a, T&amp; b) {
T tmp(a); // now we have two copies of a
a = b; // now we have two copies of b
b = tmp; // now we have two copies of tmp (aka a)
}</PRE><P>
This can now be solved using the new function std::move():</P>
<PRE>template &lt;class T&gt; swap(T&amp; a, T&amp; b) {
T tmp(std::move(a));
a = std::move(b);
b = std::move(tmp);
}</PRE><P STYLE="margin-bottom: 0cm">
For the move function to take effect, user needs to reimplement the
move constructor (taking ClassType&amp;&amp; as an argument) and
operator=(ClassType&amp;&amp;):</P>
<PRE>class MyClass {
MyClass(MyClass&amp;&amp; p) : ptr(p.ptr) {p.ptr = 0;}
MyClass&amp; operator=(MyClass&amp;&amp; p) {
std::swap(ptr, p.ptr);
return *this;
}
};</PRE><P>
In practice, the Rvalues are used for temporaries (when passing the
result of one function as an argument to another).</P>
<P>Done: Added type&amp;&amp; to Swig parser. Added testcase
cpp11_rvalue_reference.i. Operator &amp;&amp; is treated the same as
operator &amp;. R11450</P>
<P STYLE="margin-bottom: 0cm">Article:
<A HREF="http://www.artima.com/cppsource/rvalue.html">http://www.artima.com/cppsource/rvalue.html</A></P>
<H2>Generalized constant expressions [done]</H2>
<P>In C++11 you can define functions as constant expressions.
Functions need to return constant value in form &quot;return expr&quot;,
where expr is a constant expression.
</P>
<P>A keyword &quot;constexpr&quot; is introduced for this. eg.:
constexpr int getNumber() { return 5; } const int MY_CONSTANT =
getNumber();
</P>
<P>Constants are treated as normal variables in interpreted languages
because they are not compiled into the executable. Java &quot;final&quot;
constants are defined runtime as well. C++ constants need to be
declared in the header file and defined in the implementation file,
so swig doesn't need to know about the constant values when parsing
the header file.
</P>
<P>Done: Added the “constexpr “ keyword to Swig. Added testcase
cpp11_constexpr. R11322</P>
<P>Problem: No compilers were known to support constexpr yet, so the
testcase was temporarily commented out in common.mk.
</P>
<H2>Extern template [done]</H2>
<P>Extern template forces the GCC compiler to not instantiate the
template in the translation unit at that time. It's a feature
specifically aimed at compilers to speed up the compilation process.
</P>
<P>Done: Added support for 'extern template class
std::vector&lt;MyClass&gt;;'. Added testcase cpp11_template_explicit.
R11385 , R11386</P>
<H2>Initializer lists [done]</H2>
<P>Initializer list is a new type in standard library:
std::initializer_list&lt;T&gt;. New symbols {} are introduced for the
initializer lists.
</P>
<P>One can now use:
</P>
<PRE> class A {
public:
A( std::initializer_list&lt;int&gt; );
};
A a1 = {1,2,3,4};</PRE><P>
Languages like Java, C# and Python already support direct creation of
lists natively.</P>
<P>Problem: initializer_list cannot be treated as an ordinary list.
The constructor containing initializer_list can only be accessed by
assigning the value using the {} brackets. I also don't think there
is a simple way to convert an ordinary list or a vector to the
initializer_list.</P>
<P>Done: Ignored the constructor having initializer_list as its
argument. Show warning to the user. Added testcase
cpp11_initializer_list. R11450</P>
<P>Article:
<A HREF="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1919.pdf">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1919.pdf</A></P>
<H2>Uniform initialization [done]</H2>
<P>The new C++11 standard will allow the following:</P>
<PRE>struct IdString {
std::string name;
int identifier;
};
IdString GetString() {
return {&quot;SomeName&quot;, 4}; //Note the lack of explicit type.
}</PRE><P>
The feature works exactly as it did now for POD types only (eg. int
a[] = {1,2,3};). The following declarations are the same in the new
C++11:</P>
<PRE>IdString str1 = {„SomeName“, 4};
IdString str2{„SomeName“, 4};</PRE><P>
The new way of using uniform initialization allows the following:</P>
<PRE>struct BasicStruct {
int x;
double y;
};
struct AltStruct {
AltStruct(int x, double y) : x_{x}, y_{y} {}
private:
int x_;
double y_;
};
BasicStruct var1{5, 3.2}; // only fills the struct components
AltStruct var2{2, 4.3}; // calls the constructor</PRE><P>
The new syntax is specific to C++. Java, C# and scripting languages
do not support this behaviour, but always need constructors. They
support {} brackets for declaration of arrays as C does + they add
support for creation of arrays on-the-fly (what C++11 introduced with
this feature and more).</P>
<P>Done: Added syntax for {} member initialization in class
constructor. Added testcase cpp11_uniform_initialization. R11413</P>
<H2>Type inference [partially done]</H2>
<P>A new keyword 'auto' is introduced in C++11:</P>
<PRE>auto a1 = 100;
auto a2 = myFunc();</PRE><P>
The type of a1 and a2 is automatically determined according to the
initialization value during the semantic phase of the compiler.</P>
<P>Another macro 'decltype()' is introduced. The macro takes the
concrete object as an argument and returns its type. User could use
this as:</P>
<PRE>int i = 100;
decltype(i) j = 200; // decltype(i) = int</PRE><P STYLE="margin-bottom: 0cm">
Calling operators are allowed as well:</P>
<PRE STYLE="margin-bottom: 0.5cm">decltype(i+j) k = 300;</PRE><P>
Done: Added support for decltype() syntax. Test cases for normal
decltype members and alternate function members work fine. Currently
only syntax in form decltype(variable name) work. No support for
custom expresions eg. decltype(i+j) yet. R11525</P>
<P>TODO: William proposed to support the hidden variables as well
(ones not parsed by Swig and added to symbol table). This also allows
Swig to parse custom expressions like decltype(i+j). The idea is to
introduce a new SwigType for this.</P>
<H2>Range-based for-loop [ignored]</H2>
<P>This feature is always present inside the implementation block
only.
</P>
<H2>Lambda functions and expressions [done]</H2>
<P>C++11 introduces lambda functions defined as:</P>
<PRE STYLE="margin-bottom: 0.5cm">[](int x, int y) -&gt; int { return x + y; }</PRE><P>
If the lambda function contains a single return statement only or the
function doesn't return any type, the return type '-&gt;' can be
omitted. Lambda functions are function objects.</P>
<P>The following example prints the number of items stored in a list:</P>
<PRE>std::vector&lt;int&gt; someList;
int total = 0;
std::for_each( someList.begin(), someList.end(), [&amp;total](int x) {total += x} );
std::cout &lt;&lt; total;</PRE><P>
Parameters inside the [] are the visible parameters of the lambda
functions. These can be &amp; (references), = (copies), variable name
(variable copy), &amp;variable name (variable reference) or this
(copy of the current object).</P>
<P>Lambda functions can be stored using:</P>
<PRE STYLE="margin-bottom: 0.5cm">auto myLambdaFunc = [this]() { this-&gt;SomePrivateMemberFunction() };</PRE><P>
Proposal: Lambda functions are most commonly used inside the function
block to quickly define how the sort, find and similar functions
should work (the other way would be overriding a class the Java
style). The latest GCC does not support lambda functions yet so it is
difficult to test the feature once implemented. I would implement the
syntax support for this feature, but produce no wrapper code. Lambda
functions still work inside the function block though.</P>
<P>Article:
<A HREF="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2550.pdf">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2550.pdf</A></P>
<P>Done: Added syntax support for the lambda functions. Added
testcase cpp11_lambda_functions.i. R11491, R11492</P>
<H2>Alternate function syntax [done]</H2>
<P>The problem with decltype() is that the parameters need to be
defined before the decltype. The following syntax is not valid,
because lhs and rhs hasn't been defined at the time of decltype:</P>
<PRE>template&lt; typename LHS, typename RHS&gt;
decltype(lhs+rhs) AddingFunc(const LHS &amp;lhs, const RHS &amp;rhs) {return lhs + rhs;} //Not legal C++11</PRE><P>
The solution C++11 offers is the combination of the 'auto' keyword
before and '-&gt; rettype' after the function declaration:</P>
<PRE>template&lt; typename LHS, typename RHS&gt;
auto AddingFunc(const LHS &amp;lhs, const RHS &amp;rhs) -&gt; decltype(lhs+rhs) {return lhs + rhs;}</PRE><P>
The new syntax only makes the job for the C++ compilers easier when
parsing such functions. The new syntax can be used for ordinary
functions as well:</P>
<PRE>struct SomeStruct {
auto FuncName(int x, int y) -&gt; int;
};
auto SomeStruct::FuncName(int x, int y) -&gt; int {
return x + y;
}</PRE><P>
Done: Added support for the 'auto' return type. Added support for the
'-&gt; type' after the funtion declaration. Added testcases
cpp11_alternate_function_syntax.i and
cpp11_alternate_function_syntax_runme.py. R11414</P>
<H2>Concepts, Axioms [ignored]</H2>
<P>In C++ there is a common problem when you use a template in the
class which doesn't support all the operations the functions in the
class actually do on the type. Compiler errors are usually very long
and unreadable. C++11 adds support for the &quot;concepts&quot;. The
idea is to define what operations and attributes should the template
have. In contrast to class inheritance and polimorphism, all lookups
are done in compile-time.
</P>
<P>Basic syntax (note LessThanComparable<A HREF="http://www.dabeaz.com/cgi-bin/wiki.pl?action=change1&amp;id=LessThanComparable">?</A>
instead of &quot;class&quot; or &quot;typename&quot;):
</P>
<PRE> template&lt;LessThanComparable<A HREF="http://www.dabeaz.com/cgi-bin/wiki.pl?action=change1&amp;id=LessThanComparable">?</A> T&gt;
const T&amp; min(const T &amp;x, const T &amp;y) {
return y &lt; x ? y : x;
}</PRE><P>
Extended syntax (requires conditions are separated with &amp;&amp;,
|| or !):
</P>
<PRE> template&lt; typename T&gt; requires LessThanComparable<A HREF="http://www.dabeaz.com/cgi-bin/wiki.pl?action=change1&amp;id=LessThanComparable">?</A>&lt;T&gt;
const T&amp; min(const T &amp;x, const T &amp;y) {
return y &lt; x ? y : x;
}</PRE><P>
Definition of the concepts:
</P>
<PRE> concept LessThanComparable<A HREF="http://www.dabeaz.com/cgi-bin/wiki.pl?action=change1&amp;id=LessThanComparable">?</A>&lt; typename T &gt; {
bool operator&lt;(T,T);
requires GreaterThanComparable<A HREF="http://www.dabeaz.com/cgi-bin/wiki.pl?action=change1&amp;id=GreaterThanComparable">?</A>&lt;T&gt;;
typename value_type;
typename reference;
};</PRE><P>
Concept maps allow usage of a specific type:
</P>
<PRE> template&lt; typename T&gt;
concept_map InputIterator<A HREF="http://www.dabeaz.com/cgi-bin/wiki.pl?action=change1&amp;id=InputIterator">?</A>&lt;T*&gt; {
typedef T value_type ;
typedef T&amp; reference ;
typedef T* pointer ;
typedef std::ptrdiff_t difference_type ;
};</PRE><P>
Concept maps can act as mini-types, with function definitions and
other constructs commonly associated with classes:
</P>
<PRE> concept Stack&lt; typename X&gt; {
typename value_type;
void push(X&amp;, const value_type&amp;);
void pop(X&amp;);
value_type top(const X&amp;);
bool empty(const X&amp;);
};
template&lt; typename T&gt;
concept_map Stack&lt;std::vector&lt;T&gt; &gt; {
typedef T value_type;
void push(std::vector&lt;T&gt;&amp; v, const T&amp; x) { v.push_back(x); }
void pop(std::vector&lt;T&gt;&amp; v) { v.pop_back(); }
T top(const std::vector&lt;T&gt;&amp; v) { return v.back(); }
bool empty(const std::vector&lt;T&gt;&amp; v) { return v.empty(); }
};</PRE><P>
Axioms are a facility pertaining to concepts supplied by C++11 to
express the semantic properties of concepts. For example, the concept
Semigroup can be defined with an axiom Associativity as:
</P>
<PRE> concept Semigroup&lt; typename Op, typename T&gt; : CopyConstructible<A HREF="http://www.dabeaz.com/cgi-bin/wiki.pl?action=change1&amp;id=CopyConstructible">?</A>&lt;T&gt; {
T operator()(Op, T, T);
axiom Associativity(Op op, T x, T y, T z) {
op(x, op(y, z)) == op(op(x, y), z);
}
};</PRE><P>
Axioms are more like hints to the compiler to speed-up the process of
compilation.
</P>
<P>Ignored: Concepts and axioms were removed from the C++11 standard.
</P>
<H2>Object construction improvement [done]</H2>
<P>This feature allows classes constructors to call other
constructors with different arguments (similar to Java and C#
behaviour).
</P>
<P>The syntax is as follows:
</P>
<PRE> class SomeType {
int number;
public:
SomeType(int newNumber) : number(newNumber) {}
SomeType() : SomeType(42) {}
};</PRE><P>
Also when using the inheritance, the feature introduces inheritance
of all superclass constructors without being defined separately in
the inherited class:
</P>
<PRE> class BaseClass {
public:
BaseClass(int iValue);
};
class DerivedClass: public BaseClass {
public:
using BaseClass::BaseClass; // Adds DerivedClass(int) constructor
};</PRE><P>
Swig already correctly parses and produces the correct wrapper for
the “using” keyword.</P>
<P>Done: Added testcase cpp11_constructors.i which covers both
constructor delegation and constructor inheritance. R11532</P>
<P>Problem: Constructor delegation and constructor inheritance is not
supported by any compiler yet, so it's impossible to try and test
this feature.</P>
<H2>Null pointer constant [done]</H2>
<P>nullptr is part of the standard library.
</P>
<P>It's defined as typedef decltype(nullptr) nullptr_t;
</P>
<P>nullptr_t is defined in &lt;cstddef&gt;.
</P>
<P>As far as the C++ is compatible with 0 as the pointer value, swig
values will work for the C++. And the other way around, nullptr
behaves as the ordinary pointer (false, if empty, true, if not
empty), so it's ok for swig to compare it.</P>
<P>Done: Written a testcase cpp11_null_pointer_constant.i and
cpp11_null_pointer_constant_runme.py to prove the nullptr
functionality. R11484</P>
<H2>Strongly typed enumerations [partially done]</H2>
<P>C++11 introduces a new syntax for strongly typed enum declaration:
</P>
<PRE> enum class Enumeration {
Val1,
Val2,
Val3 = 100,
Val4 /* = 101 */
};</PRE><P>
Typing if (Val4 == 101) will result in compilation error.
</P>
<P>The enum itself can now be explicitely of type int, long, unsigned
int etc.:
</P>
<PRE STYLE="margin-bottom: 0.5cm"> enum class Enum2 : unsigned int {Val1, Val2};</PRE><P>
And it can be forward declared as well:
</P>
<PRE> enum Enum1; //Illegal in C++ and C++11; no size is explicitly specified.
enum Enum2 : unsigned int; //Legal in C++11.
enum class Enum3; //Legal in C++11, because enum class declarations have a default type of &quot;int&quot;.
enum class Enum4: unsigned int; //Legal C++11.
enum Enum2 : unsigned short; //Illegal in C++11, because Enum2 was previously declared with a different type.</PRE><P>
Done: Added syntax 'enum class Name' and forward declarators 'enum
Name : inherited type' or 'enum class Name : inherited type' in
R11449.</P>
<P>TODO: Add semantic support for enum elements not clashing with
enum elements in other enum classes. See cpp11_strongly_typed_enums.i
warnings.</P>
<P>Problem: Swig currently doesn't support nested classes. This
feature should be implemented using a new nested class when using
“enum class” with a single anonymous “enum {elements}”
element inside. For example:</P>
<PRE STYLE="margin-bottom: 0.5cm">class A { enum class EA { a,b,c,d }; };</PRE><P>
should be mapped to</P>
<PRE STYLE="margin-bottom: 0.5cm">class A { class EA { enum {a,b,c,d}; }; };</PRE><H2>
Angle bracket [done]</H2>
<P>Support for right angled brackets was implemented using the
following article as a base:
<A HREF="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1757.html">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1757.html</A>
</P>
<P>Done: Added support for angle brackets. Used the preferred
&quot;Approach 1&quot;. Added a testcase named
cpp11_template_double_brackets. R11245</P>
<H2>Explicit conversion operators [done]</H2>
<P>This is used when converting one type to another (eg. if
(myObject) {}, where myObject is your custom class converted to
bool).
</P>
<P>Requires both operator and function overloading which is not
supported in any target language (eg. python, php).
</P>
<P>Done: Swig already supports the keyword &quot;explicit&quot; for
function types as well. Added test case
cpp11_explicit_conversion_operators. R11323</P>
<H2>Template typedefs [partially done]</H2>
<P>The new C++11 will allow creation of wrapper around the template.
For example, if we want to do this:</P>
<PRE>template&lt; typename first, typename second, int third&gt;
class SomeType;
template&lt; typename second&gt;
typedef SomeType&lt;OtherType, second, 5&gt; TypedefName; //Illegal in C++</PRE><P>
This is still illegal! But we can now use the new syntax for
achieving the same effect:</P>
<PRE>template&lt; typename first, typename second, int third&gt;
class SomeType;
template&lt; typename second&gt;
using TypedefName = SomeType&lt;OtherType, second, 5&gt;;</PRE><P>
Here we created a new wrapper TypedefName taking one template
argument &lt;second&gt; which creates a type SomeType&lt;OtherType,
second, 5&gt;. OtherType and 5 are predefined here and hidden from
the user the user only uses TypedefName type.</P>
<P>The same goes for the following example:</P>
<PRE>typedef void (*PFD)(double); // Old style
using PF = void (*)(double); // New introduced syntax</PRE><P>
Swig supports parsing typedefs for templates as well for example:</P>
<PRE STYLE="margin-bottom: 0.5cm">typedef List&lt;int&gt; intList;</PRE><P>
Done: Expanded support for the new 'using' syntax and template
aliasing. Added testcase cpp11_template_typedefs. R11533</P>
<P>TODO: Make Swig aware of the newly defined typedef. The TYPEDEF
keyword is part of the storage_class rule and type+declarator (see
c_decl rule) is the right part of the definition for example void
(*PFD)(double) cannot be transformed to void *(double) easily. To
fully support the new 'using' form, we'll probably have to change the
type, type_right rules and declarator, direct_declarator,
notso_direct_declarator etc., which is PITA.</P>
<H2>Unrestricted unions [done]</H2>
<P>C++ currently offers usage of unions for types with trivial
constructors only. The new C++11 standard allows usage of types with
non-trivial constructors as well:</P>
<PRE> struct point {
point() {}
point(int x, int y): x_(x), y_(y) {}
int x_, y_;
};
union P {
int z;
double w;
point p; // Illegal in C++; point has a non-trivial constructor. However, this is legal in C++11.
} p1;</PRE><P>
Swig already parses the given syntax.</P>
<P>Done: Added testcase cpp11_unrestricted_unions. R11435, R11447</P>
<P>Problem: GCC doesn't support unrestricted unions yet so there is
no way to actually test, if it works.</P>
<H2>Variadic templates [partially done]</H2>
<P>The new C++11 offers the following syntax:</P>
<PRE STYLE="margin-bottom: 0.5cm">template&lt;typename... Values&gt; class tuple;</PRE><P>
This can be used for example:</P>
<PRE STYLE="margin-bottom: 0.5cm">class tuple&lt;int, std::vector&lt;int&gt;, std::map&lt;std::string, std::vector&lt;int&gt;&gt;&gt; someInstanceName;</PRE><P>
The ... is used in two cases. One is in the template header where it
marks on the left the keywords 'typename' or 'class' and a type name
on the right. The second case is usually in the function block to
decompose typename on the left of the ... . For example:</P>
<PRE>void printf(const char *s) {
while (*s) {
if (*s == '%' &amp;&amp; *(++s) != '%')
throw std::runtime_error(&quot;invalid format string: missing arguments&quot;);
std::cout &lt;&lt; *s++;
}
}
template&lt;typename T, typename... Args&gt;
void printf(const char* s, T value, Args... args) { // recursive action split previous args to value + args
while (*s) {
if (*s == '%' &amp;&amp; *(++s) != '%') {
std::cout &lt;&lt; value;
printf(*s ? ++s : s, args...); // call even when *s == 0 to detect extra arguments
return;
}
std::cout &lt;&lt; *s++;
}
throw std::logic_error(&quot;extra arguments provided to printf&quot;);
}</PRE><P>
The tricky part is that variadic templates can unpack actually
anywhere including the class inheritance :(</P>
<PRE>template &lt;typename... BaseClasses&gt; class ClassName : public BaseClasses... {
public:
ClassName (BaseClasses&amp;&amp;... baseClasses) : BaseClasses(baseClasses)... {}
}</PRE><P>
A new extension to sizeof is also introduced with this feature. The
... after sizeof returns number of arguments:</P>
<PRE>template&lt;typename ...Args&gt; struct SomeStruct {
static const int size = sizeof...(Args);
}
// SomeStruct&lt;Type1, Type2&gt;::size is 2 and SomeStruct&lt;&gt;::size is 0</PRE><P>
Done: Added syntax support for 'typename' or 'class' + ... + id.
Added testcase cpp11_variadic_templates. R11458</P>
<P>Done: Added syntax support for BaseClass + ..., type + ... + id in
parameters and baseclass + ... for intializers after constructor.
Extended Swig syntax to support sizeof...(Args). R11467</P>
<P>Done: Fixed %template to support variadic number of templates.</P>
<P>TODO: Only (if present) first variadically defined argument is
currently used in %template directive. The next ones are ignored.</P>
<H2>New string literals [partially done]</H2>
<P>Beside the implementation, the new C++11 Unicode and custom
delimeter constants can occur in templates in the header file.
</P>
<P>Done: Added symbols 'u', 'u8' and 'U' to mark the beginning of the
UTF string. Also added test case cpp11_raw_string_literals. R11327</P>
<P>Done: Added R&quot;DELIMITER[, ]DELIMITER&quot; for a custom
delimiter for the beginning/end of the string. R11328</P>
<P>TODO: Fix the Swig's C++ preprocessor bug when parsing an odd
number of “ inside the string brackets. See
Source/Preprocessor/cpp.c.</P>
<H2>User-defined literals [partially done]</H2>
<P>C++ has different suffix literals. eg. 12.5f marks the number 12.5
as float.
</P>
<P>C++11 allows user to define his own suffix for the strings always
starting with the underscore (_). eg. int a = &quot;hello&quot;_mySuffix;
</P>
<P>The syntax is similar to other operator overloading functions:
</P>
<PRE STYLE="margin-bottom: 0.5cm"> OutputType operator &quot;&quot; _mySuffix(const char * string_values);</PRE><P>
The null terminated const char* is the string between the &quot;&quot;.
The _mySuffix is the name of the suffix operator. And the OutputType
is the outputType the operator returns.
</P>
<P>Other forms are:
</P>
<PRE> OutputType operator &quot;&quot; _mySuffix(const char * string_values, size_t num_chars);
OutputType operator &quot;&quot; _mySuffix(const wchar_t * string_values, size_t num_chars);
OutputType operator &quot;&quot; _mySuffix(const char16_t * string_values, size_t num_chars);
OutputType operator &quot;&quot; _mySuffix(const char32_t * string_values, size_t num_chars);
OutputType operator &quot;&quot; _mySuffix(int value); /* cooked version - ie. atoi() of string */</PRE><P>
Another possibility is to use variadic templates:
</P>
<PRE> template&lt;char...&gt; OutputType operator &quot;&quot; _mySuffix();
OutputType someVariable = &quot;1234&quot;_mySuffix;</PRE><P>
This instantiates the literal processing function as
operator&quot;&quot;_Suffix&lt;'1', '2', '3', '4'&gt;. In this form,
there is no terminating null character to the string. The main
purpose to doing this is to use C++11's constexpr keyword and the
compiler to allow the literal to be transformed entirely at compile
time, assuming OutputType is a constexpr-constructable and copyable
type, and the literal processing function is a constexpr function.</P>
<P>Article:
<A HREF="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2765.pdf">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2765.pdf</A></P>
<P>Done: Added syntax support for userdefined literals. Added
testcase cpp11_userdefined_literals.i. R11494</P>
<P>TODO: %rename doesn't parse operator”” yet.</P>
<H2>Thread-local storage [done]
</H2>
<P>New C++11 introduces keyword &quot;thread_local&quot; which marks
the following variable dynamically located depending on the current
thread when using the address-of (&amp;) operator.
</P>
<P>Syntax:
</P>
<PRE> struct A {
thread_local int val;
};</PRE><P>
Done: Add &quot;thread_local&quot; keyword to Swig. Added testcase
cpp11_thread_local. R11393</P>
<H2>Defaulting/deleting of standard functions on C++ objects [done]</H2>
<P>C++ automatically creates default constructor with empty
parameters, copy constructor, operator= and destructor for any class.
Sometimes user wants to explicitly remove one of them or enable them
(eg. default constructor with empty parameters doesn't work any more,
if any other constructor is defined).
</P>
<P>Words &quot;default&quot; and &quot;delete&quot; are introduced.
The syntax is similar to declaration of pure virtual function:
</P>
<PRE> struct NonCopyable {
NonCopyable &amp; operator=(const NonCopyable&amp;) = delete; /* Removes operator= */
NonCopyable(const NonCopyable&amp;) = delete; /* Removed copy constructor */
NonCopyable() = default; /* Explicitly allows the empty constructor */
void *operator new(std::size_t) = delete; /* Removes new NonCopyable */
};</PRE><P>
User has the ability by using keyword delete to disallow calling of
the standard functions brought by C++ itself.
</P>
<PRE> struct A1 {
void f(int i);
void f(double i) = delete; /* Don't cast double to int. Compiler returns an error */
};
struct A2 {
void f(int i);
template&lt;class T&gt; void f(T) = delete; /* Only accept int */
};</PRE><P>
Ignored: Swig already parses the keywords &quot;= delete&quot; and &quot;=
default&quot;. These keywords are used for built-in functions (copy
constructor, operator= etc.), which are ignored by Swig anyway.</P>
<P>Done: Added testcase cpp11_default_delete. R11535</P>
<H2>Type long long int [done]</H2>
<P>Type long long int is an integer type that has at least 64 useful
bits. C99 added it to its standard, but the C++ didn't adopt it until
C++11. Most C++ compilers supported it though.
</P>
<P>Done: Swig already parses the C code including the long long type.
</P>
<H2>Static assertions [done]</H2>
<P>static_assert() can be used at class scope as well eg.:
</P>
<PRE> template &lt;typename T&gt;
struct Check {
static_assert(sizeof(int) &lt;= sizeof(T), &quot;not big enough&quot;);
};</PRE><P>
Done: Added syntax support for &quot;static_assert()&quot;. Added
test case cpp11_static_assert. R11369</P>
<H2>Allow sizeof to work on members of classes without an explicit
object [done]</H2>
<P>C++11 allows calls of sizeof to concrete objects as well:
</P>
<PRE> struct A { int member; };
sizeof(A::member); //Does not work with C++03. Okay with C++11</PRE><P>
This kind of syntax is already supported by Swig.</P>
<P>Done: Added testcase cpp11_sizeof_objects. R11538
</P>
<H2>Threading facilities [ignored]</H2>
<P>C++11 will add the following classes to the standard library:
</P>
<PRE> * std::thread
* std::mutex, std::recursive_mutex
* std::condition_variable, std::condition_variable_any
* std::lock_guard, std::unique_lock
* std::packaged_task</PRE><P>
Ignored: No changes to the language itself is made.
</P>
<H2>Tuple types [TODO]</H2>
<P>Tuple is array of various types. C++11 introduced this feature
using variadic templates. Tuple is defined as:</P>
<PRE STYLE="margin-bottom: 0.5cm">template &lt;class ...Types&gt; class tuple;</PRE><P>
Constructor is automatically generated filling the tuple elements.
get&lt;X&gt; function is introduced to get the Xth element in the
tuple.</P>
<PRE>typedef tuple&lt; int, double, long &amp;, const char * &gt; test_tuple ;
long lengthy = 12 ;
test_tuple proof( 18, 6.5, lengthy, &quot;Ciao!&quot; ) ;
lengthy = get&lt;0&gt;(proof) ; // Assign to 'lengthy' the value 18.
get&lt;3&gt;(proof) = &quot; Beautiful!&quot; ; // Modify the tuples fourth element.</PRE><P>
Tuples can be copied to each other, if all the elements are copiable:</P>
<PRE>typedef tuple&lt; int , double, string &gt; tuple_1 t1 ;
typedef tuple&lt; char, short , const char * &gt; tuple_2 t2( 'X', 2, &quot;Hola!&quot; ) ;
t1 = t2 ; // Ok, first two elements can be converted,
// the third one can be constructed from a 'const char *'.</PRE><P>
TODO: Implement wrappers for the tuplet&lt;&gt; class.</P>
<H2>Hash tables [TODO]</H2>
<P>C++11 introduces the &quot;unordered&quot; version of existing
types, which in practice work faster than the linear types:
</P>
<PRE> - unordered set
- unordered multiset
- unordered map
- unordered multimap</PRE><P>
Swig should use the &quot;unordered&quot; types exactly the same as
the original linear types.</P>
<P>Problem: Unordered types do not contain exactly same members as
ordered ones (eg. _Hashtable_iterator does not offer operator--() and
constructor with compare function which is required). So simply
aliasing unordered classes to ordered ones doesn't work.</P>
<P>TODO: Implement wrappers for unordered_ types. Initial work is
already done in Lib/std/unordered_*.i files.</P>
<H2>Regular expressions [ignored]</H2>
<P>Two new classes are introduced in C++11: basic_regex and
match_results. Both are defined in regex header file.
</P>
<P>Ignored: The new feature extends the standardy library only. No
changes to Swig needed.
</P>
<H2>General-purpose smart pointers [done]</H2>
<P>This feature deprecates auto_ptr and adds shared_ptr, weak_ptr and
unique_ptr to the standard library.
</P>
<P>This feature only adds the smart pointers to the standard library
and doesn't effect the C++ syntax.</P>
<P>Done: Added test case which uses all three smart pointers in the
class. R11394</P>
<P>Problem: GCC standard library doesn't contain the new smart
pointers yet.
</P>
<H2>Extensible random number facility [ignored]</H2>
<P>This feature standardize the pseudo random number algorithm
(currently, the random number generator was dependent on the
platform/compiler). It adds functions linear_congruential,
subtract_with_carry and mersenne_twister and symbols
uniform_int_distribution, bernoulli_distribution,
geometric_distribution, poisson_distribution, binomial_distribution,
uniform_real_distribution, exponential_distribution,
normal_distribution and gamma_distribution to the standard library.
</P>
<P>Ignored: The new feature extends the standardy library only. No
changes to Swig needed.
</P>
<H2>Wrapper reference [ignored]</H2>
<P>This feature adds ref and cref classes to the standard library
(#include &lt;utility&gt;) usually used in tempalte functions.
</P>
<P>Ignored: The new feature extends the standardy library only. No
changes to Swig needed.
</P>
<H2>Polymorphous wrappers for function objects [done]</H2>
<P>Two features are introduced:
</P>
<UL>
<LI><P>The function template wrapper:
</P>
</UL>
<PRE STYLE="margin-bottom: 0.5cm"> function&lt;int ( int, int )&gt; pF;</PRE>
<UL>
<LI><P>and the function object:
</P>
</UL>
<PRE> struct Test {
bool operator()( short x, short y );
};</PRE><P>
Swig already supports the two.</P>
<P>Done: Added a runtime testcase for function objects
cpp11_function_objects. R11419.</P>
<H2>Type traits for metaprogramming [ignored]</H2>
<P>C++11 adds a new header file &lt;type_traits&gt; which includes
helper functions to determine the template type while initializing
the object at compile time.
</P>
<P>Swig already supports the following code:
</P>
<PRE> template&lt; int B, int N &gt;
struct Pow {
// recursive call and recombination.
enum{ value = B*Pow&lt; B, N-1 &gt;::value };
};
template&lt; int B &gt; struct Pow&lt; B, 0 &gt; // <EM>N == 0</EM> condition of termination.
{
enum{ value = 1 };
};
int quartic_of_three = Pow&lt; 3, 4 &gt;::value ;</PRE><P>
Functions is_convertible, is_integral, is_integral_const etc. are
part of the new header:
</P>
<PRE>// First way of operating.
template&lt; bool B &gt; struct algorithm {
template&lt; class T1, class T2 &gt; int do_it( T1 &amp;, T2 &amp; ) { /*...*/ }
};
// Second way of operating.
template&lt;&gt; struct algorithm&lt;true&gt; {
template&lt; class T1, class T2 &gt; int do_it( T1, T2 ) { /*...*/ }
};
// Instantiating 'elaborate' will automatically instantiate the correct way to operate.
template&lt; class T1, class T2 &gt; int elaborate( T1 A, T2 B ) {
// Use the second way only if 'T1' is an integer and if 'T2' is
// in floating point, otherwise use the first way.
return algorithm&lt; is_integral&lt;T1&gt;::value &amp;&amp; is_floating_point&lt;T2&gt;::value &gt;::do_it( A, B );
}</PRE><P>
Swig correctly parses the syntax for template&lt;bool&gt;,
template&lt;class T&gt; and template&lt;&gt;.
</P>
<P>Ignored: Swig requires explicitly defined template class
(%template directive) to export it to the target language.</P>
<H2>Uniform method for computing return type of function objects
[partially done]</H2>
<P>The template function is introduced: std::result_of() which
depends on decltype:
</P>
<PRE>template&lt; class Obj &gt;
class calculus_ver2 {
public:
template&lt; class Arg &gt;
typename std::result_of&lt;Obj(Arg)&gt;::type operator()( Arg&amp; a ) const {
return member(a);
}
private:
Obj member;
};</PRE><P>
Swig correctly parses the result_of class.</P>
<P>TODO: The return type (the result_of::type member) is not
calculated by Swig. This needs a much more complex semantic parser.</P>
<P>Done: Added testcase cpp11_result_of. R11534</P>
</BODY>
</HTML>

View file

@ -25,7 +25,7 @@
<li><a name="i8" href="#8">8. Naming Conventions</a>
<li><a name="i9" href="#9">9. Visibility</a>
<li><a name="i10" href="#10">10. Miscellaneous Coding Guidelines</a>
<li><a name="i11" href="#11">11. SVN Tagging Conventions</a>
<li><a name="i11" href="#11">11. Git Tagging Conventions</a>
</ul>
<a name="1" href="#i1">
@ -119,8 +119,8 @@ are case-insensitive on Windows so this convention will prevent you from inadver
creating two files that differ in case-only.
<p>
Each file should include a short abstract, license information and
a SVN revision tag like this:
Each file should include a short abstract and license information
like this:
<blockquote>
<pre>
@ -137,8 +137,6 @@ a SVN revision tag like this:
* This file defines ...
* ----------------------------------------------------------------------------- */
static char cvs[] = "&#36Id&#36";
#include "swig.h"
/* Declarations */
@ -159,12 +157,6 @@ static int avariable;
</pre>
</blockquote>
The SVN revision tag should be placed into a static string as shown
above mangled with the name of the file.
This adds the revision information to the SWIG executable and
makes it possible to extract version information from a raw binary
(sometimes useful in debugging).
<p>
As a general rule, files start to get unmanageable once they exceed
about 2000 lines. Files larger than this should be broken up into
@ -379,10 +371,10 @@ making your changes.
These are largely covered in the main documentation in the Extending.html file.
<a name="11" href="#i11">
<h2>11. SVN Tagging Conventions</h2>
<h2>11. Git Tagging Conventions</h2>
</a>
Use <tt>svn tag</tt> to declare some set of file revisions as related in some
Use <tt>git tag</tt> to declare some set of file revisions as related in some
symbolic way. This eases reference, retrieval and manipulation of these files
later. At the moment (2001/01/16 14:02:53), the conventions are very simple;
let's hope they stay that way!
@ -390,10 +382,10 @@ let's hope they stay that way!
<p>
There are two types of tags, internal (aka personal) and external.
Internal tags are used by SWIG developers primarily, whereas external
tags are used when communicating with people w/ anonymous svn access.
tags are used when communicating with people w/ anonymous git access.
<ul>
<li> Internal tags should start with the developer name and a hyphen.
<li> External tags should start with "v-".
<li> External tags should start with "rel-".
</ul>
That's all there is to it. Some example tags:
@ -402,10 +394,8 @@ That's all there is to it. Some example tags:
<li> ttn-pre-xml-patch
<li> ttn-post-xml-patch
<li> ttn-going-on-vacation-so-dutifully-tagging-now
<li> v-1-3-a37-fixes-bug-2432
<li> v-1-3-a37-fixes-bug-2433
<li> v-1-3-a37-fixes-bug-2432-again
<li> v-1-3-a37-release
<li> rel-1.3.40
<li> rel-2.0.9
</ul>
<hr>

View file

@ -42,6 +42,7 @@
<li><a name="i7" href="#7">7. Debugging SWIG</a>
<ul>
<li><a name="i7.1" href="#7.1">7.1 Debugging DOH Types The Hard Way</a>
<li><a name="i7.2" href="#7.2">7.2 Debugging DOH memory allocation problems</a>
</ul>
</ul>
@ -346,7 +347,7 @@ Delete(a); /* Destroy a */
All objects are referenced counted and given a reference count of 1 when initially created. The
<tt>Delete()</tt> function only destroys an object when the reference count reaches zero. When
an object is placed in a list or hash table, it's reference count is automatically increased. For example:
an object is placed in a list or hash table, its reference count is automatically increased. For example:
<blockquote>
<pre>
@ -843,7 +844,7 @@ Returns a type object corresponding to the type string produced by the Swig_cloc
<li><tt>char *Swig_clocal_deref(DataType *t, char *name)</tt><br>
This function is the inverse of the <tt>clocal()</tt> function. Given a type and a name,
it produces a string containing the code needed to cast/convert the type produced by
<tt>Swig_clocal()</tt> back into it's original type.
<tt>Swig_clocal()</tt> back into its original type.
<p>
<li><tt>char *Swig_clocal_assign(DataType *t, char *name)</tt><br>
@ -1179,6 +1180,34 @@ Either <br>
</ul>
<a name="7.2" href="#i7.2">
<h3>7.2 Debugging DOH memory allocation problems</h3>
</a>
<p>
The DOH objects are reference counted and use pools for memory allocation.
The implementation is in <tt>memory.c</tt>. When there are memory corruption problems,
various memory allocator tools are normally used to diagnose problems. These can be used
on SWIG and can be very useful. However, they won't necessarily find use of stale DOH objects,
that is, DOH objects
that are used after they have been deleted. This is because the DOH memory allocator
grabs a chunk of memory from the C memory allocator and manages the usage internally.
Stale DOH object usage can be checked for by defining <tt>DOH_DEBUG_MEMORY_POOLS</tt> in
<tt>memory.c</tt>. If an attempt to use an object is made after the reference count is
zero, an assertion is triggered instead of quietly re-using the stale object...
</p>
<blockquote>
<pre>
swig: DOH/memory.c:91: DohCheck: Assertion `!DOH_object_already_deleted' failed.
</pre>
</blockquote>
<p>
This can be memory intensive as previously used memory in the pool is not re-used so is
only recommended for diagnosing memory corruption problems.
</p>
<hr>
Copyright (C) 1999-2010 SWIG Development Team.

View file

@ -185,7 +185,7 @@ this function merely records that those attributes did not exist in the original
<blockquote>
This function is similar to <tt>Swig_save()</tt> except that adds additional attribute checking. There are different interpretations
of the attribute names. A name of "attr" merely requests that the function check for the presence of an attribute. If the attribute is missing, SWIG will exit with a failed assertion. An attribute name of "?attr" specifies that the attribute "attr" is optional and
that it's old value must be saved (if any). An attribute name of "*attr" specifies that the attribute is required and that
that its old value must be saved (if any). An attribute name of "*attr" specifies that the attribute is required and that
its value must be saved. The saving of attributes is performed in the same manner as with <tt>Swig_save()</tt>. Here is an example:
<pre>

View file

@ -8,7 +8,7 @@
<body bgcolor="#ffffff">
<H1><a name="Allegrocl"></a>17 SWIG and Allegro Common Lisp</H1>
<H1><a name="Allegrocl"></a>18 SWIG and Allegro Common Lisp</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -135,10 +135,10 @@ be unhappy to see some enterprising folk use this work to add
to it.
</p>
<H2><a name="Allegrocl_nn2"></a>17.1 Basics</H2>
<H2><a name="Allegrocl_nn2"></a>18.1 Basics</H2>
<H3><a name="Allegrocl_nn3"></a>17.1.1 Running SWIG</H3>
<H3><a name="Allegrocl_nn3"></a>18.1.1 Running SWIG</H3>
<p>
@ -360,7 +360,7 @@ need to link in the Allegro shared library. The library you create from
the C++ wrapper will be what you then load into Allegro CL.
</p>
<H3><a name="Allegrocl_nn4"></a>17.1.2 Command Line Options</H3>
<H3><a name="Allegrocl_nn4"></a>18.1.2 Command Line Options</H3>
<p>
@ -396,7 +396,7 @@ See <a href="#Allegrocl_nn47">Section 17.5 Identifier converter
functions</a> for more details.
</p>
<H3><a name="Allegrocl_nn5"></a>17.1.3 Inserting user code into generated files</H3>
<H3><a name="Allegrocl_nn5"></a>18.1.3 Inserting user code into generated files</H3>
<p>
@ -436,7 +436,7 @@ Note that the block <tt>%{ ... %}</tt> is effectively a shortcut for
</p>
<H2><a name="Allegrocl_nn6"></a>17.2 Wrapping Overview</H2>
<H2><a name="Allegrocl_nn6"></a>18.2 Wrapping Overview</H2>
<p>
@ -446,7 +446,7 @@ New users to SWIG are encouraged to read
interested in generating an interface to C++.
</p>
<H3><a name="Allegrocl_nn7"></a>17.2.1 Function Wrapping</H3>
<H3><a name="Allegrocl_nn7"></a>18.2.1 Function Wrapping</H3>
<p>
@ -499,7 +499,7 @@ interested in generating an interface to C++.
</pre>
</div>
<H3><a name="Allegrocl_nn8"></a>17.2.2 Foreign Wrappers</H3>
<H3><a name="Allegrocl_nn8"></a>18.2.2 Foreign Wrappers</H3>
<p>
@ -512,7 +512,7 @@ interested in generating an interface to C++.
typemap.
</p>
<H3><a name="Allegrocl_nn9"></a>17.2.3 FFI Wrappers</H3>
<H3><a name="Allegrocl_nn9"></a>18.2.3 FFI Wrappers</H3>
<p>
@ -593,7 +593,7 @@ char *xxx();
ff:def-foreign-call's.
</p>
<H3><a name="Allegrocl_nn10"></a>17.2.4 Non-overloaded Defuns</H3>
<H3><a name="Allegrocl_nn10"></a>18.2.4 Non-overloaded Defuns</H3>
<p>
@ -606,7 +606,7 @@ char *xxx();
this function can be manipulated via the <tt>lout</tt> typemap.
</p>
<H3><a name="Allegrocl_nn11"></a>17.2.5 Overloaded Defuns</H3>
<H3><a name="Allegrocl_nn11"></a>18.2.5 Overloaded Defuns</H3>
<p>
@ -622,7 +622,7 @@ char *xxx();
can be manipulated via the <tt>lout</tt> typemap.
</p>
<H3><a name="Allegrocl_nn12"></a>17.2.6 What about constant and variable access?</H3>
<H3><a name="Allegrocl_nn12"></a>18.2.6 What about constant and variable access?</H3>
<p>
@ -635,7 +635,7 @@ char *xxx();
into the foreign module.
</p>
<H3><a name="Allegrocl_nn13"></a>17.2.7 Object Wrapping</H3>
<H3><a name="Allegrocl_nn13"></a>18.2.7 Object Wrapping</H3>
<p>
@ -657,7 +657,7 @@ char *xxx();
foreign function interface.
</p>
<H2><a name="Allegrocl_nn14"></a>17.3 Wrapping Details</H2>
<H2><a name="Allegrocl_nn14"></a>18.3 Wrapping Details</H2>
<p>
@ -665,7 +665,7 @@ char *xxx();
translated into lisp.
</p>
<H3><a name="Allegrocl_nn15"></a>17.3.1 Namespaces</H3>
<H3><a name="Allegrocl_nn15"></a>18.3.1 Namespaces</H3>
<p>
@ -742,13 +742,13 @@ namespace car {
function such as <tt>(car '(1 2 3)</tt>.
</p>
<H3><a name="Allegrocl_nn16"></a>17.3.2 Constants</H3>
<H3><a name="Allegrocl_nn16"></a>18.3.2 Constants</H3>
<p>
Constants, as declared by the preprocessor #define macro or SWIG
<tt>%constant</tt> directive, are included in SWIGs parse tree
<tt>%constant</tt> directive, are included in SWIG's parse tree
when it can be determined that they are, or could be reduced to,
a literal value. Such values are translated into defconstant
forms in the generated lisp wrapper when the -nocwrap command-line
@ -803,7 +803,7 @@ namespace car {
not use the <tt>-nocwrap</tt> command-line option.
</p>
<H3><a name="Allegrocl_nn17"></a>17.3.3 Variables</H3>
<H3><a name="Allegrocl_nn17"></a>18.3.3 Variables</H3>
<p>
@ -881,13 +881,13 @@ globalvar&gt; (globalvar.nnn::glob_float)
</pre>
</div>
<H3><a name="Allegrocl_nn18"></a>17.3.4 Enumerations</H3>
<H3><a name="Allegrocl_nn18"></a>18.3.4 Enumerations</H3>
<p>
In C, an enumeration value is an integer value, while in C++ an
enumeration value is implicitly convertible to an integer value,
but can also be distinguished by it's enum type. For each enum
but can also be distinguished by its enum type. For each enum
declaration a def-foreign-type is generated, assigning the enum
a default type of :int. Users may adjust the foreign type of
enums via SWIG <tt>typemaps</tt>.
@ -901,7 +901,7 @@ globalvar&gt; (globalvar.nnn::glob_float)
of it not being necessary to probe into foreign space to retrieve enum
values. When generating a .cxx wrapper file, a more general solution is
employed. A wrapper variable is created in the module_wrap.cxx file, and
a ff:def-foreign-variable call is generated to retrieve it's value into lisp.
a ff:def-foreign-variable call is generated to retrieve its value into lisp.
</p>
<p>For example, the following header file
@ -957,7 +957,7 @@ EXPORT const int ACL_ENUM___FOO3__SWIG_0 = FOO3;
</pre>
</div>
<H3><a name="Allegrocl_nn19"></a>17.3.5 Arrays</H3>
<H3><a name="Allegrocl_nn19"></a>18.3.5 Arrays</H3>
<p>
@ -1105,10 +1105,10 @@ namespace BAR {
</pre>
</div>
<H3><a name="Allegrocl_nn20"></a>17.3.6 Classes and Structs and Unions (oh my!)</H3>
<H3><a name="Allegrocl_nn20"></a>18.3.6 Classes and Structs and Unions (oh my!)</H3>
<H4><a name="Allegrocl_nn21"></a>17.3.6.1 CLOS wrapping of</H4>
<H4><a name="Allegrocl_nn21"></a>18.3.6.1 CLOS wrapping of</H4>
<p>
@ -1118,12 +1118,12 @@ namespace BAR {
function that returns an object (or pointer/reference) of C/C++
type <tt>X</tt>, the wrapping defun (or defmethod) on the Lisp
side will automatically wrap the pointer returned in an instance
of the apropriate class. This makes it much easier to write and
of the appropriate class. This makes it much easier to write and
debug code than if pointers were passed around as a jumble of
integer values.
</p>
<H4><a name="Allegrocl_nn22"></a>17.3.6.2 CLOS Inheritance</H4>
<H4><a name="Allegrocl_nn22"></a>18.3.6.2 CLOS Inheritance</H4>
<p>
@ -1131,12 +1131,12 @@ namespace BAR {
inheritance of the classes in foreign code, with the
ff:foreign-pointer class at its root. ff:foreign-pointer is a thin
wrapper for pointers that is made available by the foreign function
interface. It's key benefit is that it may be passed as an argument
interface. Its key benefit is that it may be passed as an argument
to any ff:def-foreign-call that is expecting a pointer as the
parameter.
</p>
<H4><a name="Allegrocl_nn23"></a>17.3.6.3 Member fields and functions</H4>
<H4><a name="Allegrocl_nn23"></a>18.3.6.3 Member fields and functions</H4>
<p>
@ -1152,7 +1152,7 @@ namespace BAR {
the interface does nothing for <tt>friend</tt> directives,
</p>
<H4><a name="Allegrocl_nn24"></a>17.3.6.4 Why not directly access C++ classes using foreign types?</H4>
<H4><a name="Allegrocl_nn24"></a>18.3.6.4 Why not directly access C++ classes using foreign types?</H4>
<p>
@ -1170,11 +1170,11 @@ namespace BAR {
use the more robust wrapper functions.
</p>
<H3><a name="Allegrocl_nn25"></a>17.3.7 Templates</H3>
<H3><a name="Allegrocl_nn25"></a>18.3.7 Templates</H3>
<H4><a name="Allegrocl_nn26"></a>17.3.7.1 Generating wrapper code for templates</H4>
<H4><a name="Allegrocl_nn26"></a>18.3.7.1 Generating wrapper code for templates</H4>
<p>
@ -1187,7 +1187,7 @@ namespace BAR {
directive.
</p>
<H4><a name="Allegrocl_nn27"></a>17.3.7.2 Implicit Template instantiation</H4>
<H4><a name="Allegrocl_nn27"></a>18.3.7.2 Implicit Template instantiation</H4>
<p>
@ -1197,7 +1197,7 @@ namespace BAR {
class schema.
</p>
<H3><a name="Allegrocl_nn28"></a>17.3.8 Typedef, Templates, and Synonym Types</H3>
<H3><a name="Allegrocl_nn28"></a>18.3.8 Typedef, Templates, and Synonym Types</H3>
<p>
@ -1277,7 +1277,7 @@ synonym&gt;
</pre>
</div>
<H4><a name="Allegrocl_nn29"></a>17.3.8.1 Choosing a primary type</H4>
<H4><a name="Allegrocl_nn29"></a>18.3.8.1 Choosing a primary type</H4>
<p>
@ -1298,7 +1298,7 @@ synonym&gt;
</li>
</ul>
<H3><a name="Allegrocl_nn30"></a>17.3.9 Function overloading/Parameter defaulting</H3>
<H3><a name="Allegrocl_nn30"></a>18.3.9 Function overloading/Parameter defaulting</H3>
<p>
@ -1461,7 +1461,7 @@ overload&gt;
</pre>
</div>
<H3><a name="Allegrocl_nn31"></a>17.3.10 Operator wrapping and Operator overloading</H3>
<H3><a name="Allegrocl_nn31"></a>18.3.10 Operator wrapping and Operator overloading</H3>
<p>
@ -1607,28 +1607,28 @@ opoverload&gt;
</pre>
</div>
<H3><a name="Allegrocl_nn32"></a>17.3.11 Varargs</H3>
<H3><a name="Allegrocl_nn32"></a>18.3.11 Varargs</H3>
<p>
Variable length argument lists are not supported, by default. If
such a function is encountered, a warning will generated to
stderr. Varargs are supported via the SWIG <tt>%vararg</tt>
stderr. Varargs are supported via the SWIG <tt>%varargs</tt>
directive. This directive allows you to specify a (finite)
argument list which will be inserted into the wrapper in place
of the variable length argument indicator. As an example,
consider the function <tt>printf()</tt>. It's declaration would
consider the function <tt>printf()</tt>. Its declaration would
appear as follows:
</p>
<p>
See the following section
on <a href="Varargs.html#Varargs">Variable Length arguments</a>
provides examples on how <tt>%vararg</tt> can be used, along
provides examples on how <tt>%varargs</tt> can be used, along
with other ways such functions can be wrapped.
</p>
<H3><a name="Allegrocl_nn33"></a>17.3.12 C++ Exceptions</H3>
<H3><a name="Allegrocl_nn33"></a>18.3.12 C++ Exceptions</H3>
<p>
@ -1640,7 +1640,7 @@ opoverload&gt;
implemented.
</p>
<H3><a name="Allegrocl_nn34"></a>17.3.13 Pass by value, pass by reference</H3>
<H3><a name="Allegrocl_nn34"></a>18.3.13 Pass by value, pass by reference</H3>
<p>
@ -1652,7 +1652,7 @@ opoverload&gt;
newly defined types.
</p>
<H2><a name="Allegrocl_nn35"></a>17.4 Typemaps</H2>
<H2><a name="Allegrocl_nn35"></a>18.4 Typemaps</H2>
<p>
@ -1663,7 +1663,7 @@ opoverload&gt;
on <a href="Typemaps.html#Typemaps">Typemaps</a> for more information.
</p>
<H3><a name="Allegrocl_nn36"></a>17.4.1 Code Generation in the C++ Wrapper</H3>
<H3><a name="Allegrocl_nn36"></a>18.4.1 Code Generation in the C++ Wrapper</H3>
@ -1693,7 +1693,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
</pre>
</div>
<H4><a name="Allegrocl_nn37"></a>17.4.1.1 IN Typemap</H4>
<H4><a name="Allegrocl_nn37"></a>18.4.1.1 IN Typemap</H4>
<p>
@ -1728,14 +1728,14 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
</pre>
</div>
<H4><a name="Allegrocl_nn38"></a>17.4.1.2 OUT Typemap</H4>
<H4><a name="Allegrocl_nn38"></a>18.4.1.2 OUT Typemap</H4>
<p>
The <tt>out</tt> typemap is used to generate code to form the
return value of the wrapper from the return value of the wrapped
function. This code is placed in the &lt;convert and bind result to lresult&gt;
section of the above code diagram. It's default mapping is as follows:
section of the above code diagram. Its default mapping is as follows:
</p>
<div class="code">
@ -1752,13 +1752,13 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
</pre>
</div>
<H4><a name="Allegrocl_nn39"></a>17.4.1.3 CTYPE Typemap</H4>
<H4><a name="Allegrocl_nn39"></a>18.4.1.3 CTYPE Typemap</H4>
<p>
This typemap is not used for code generation, but purely for the
transformation of types in the parameter list of the wrapper function.
It's primary use is to handle by-value to by-reference conversion in the
Its primary use is to handle by-value to by-reference conversion in the
wrappers parameter list. Its default settings are:
</p>
@ -1784,7 +1784,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
these <a href="Typemaps.html#Typemaps_nn25">common typemaps</a> here.
</p>
<H3><a name="Allegrocl_nn40"></a>17.4.2 Code generation in Lisp wrappers</H3>
<H3><a name="Allegrocl_nn40"></a>18.4.2 Code generation in Lisp wrappers</H3>
<p>
@ -1803,7 +1803,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
<a href="#Allegrocl_nn15">16.3.1 Namespaces</a> for details.
</p>
<H4><a name="Allegrocl_nn41"></a>17.4.2.1 LIN Typemap</H4>
<H4><a name="Allegrocl_nn41"></a>18.4.2.1 LIN Typemap</H4>
<p>
@ -1846,7 +1846,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
</pre>
</div>
<H4><a name="Allegrocl_nn42"></a>17.4.2.2 LOUT Typemap</H4>
<H4><a name="Allegrocl_nn42"></a>18.4.2.2 LOUT Typemap</H4>
<p>
@ -1889,7 +1889,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
</pre>
</div>
<H4><a name="Allegrocl_nn43"></a>17.4.2.3 FFITYPE Typemap</H4>
<H4><a name="Allegrocl_nn43"></a>18.4.2.3 FFITYPE Typemap</H4>
@ -1939,7 +1939,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
</pre>
</div>
<H4><a name="Allegrocl_nn44"></a>17.4.2.4 LISPTYPE Typemap</H4>
<H4><a name="Allegrocl_nn44"></a>18.4.2.4 LISPTYPE Typemap</H4>
<p>
@ -1959,7 +1959,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
</pre>
</div>
<H4><a name="Allegrocl_nn45"></a>17.4.2.5 LISPCLASS Typemap</H4>
<H4><a name="Allegrocl_nn45"></a>18.4.2.5 LISPCLASS Typemap</H4>
<p>
@ -1983,7 +1983,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
</pre>
</div>
<H3><a name="Allegrocl_nn46"></a>17.4.3 Modifying SWIG behavior using typemaps</H3>
<H3><a name="Allegrocl_nn46"></a>18.4.3 Modifying SWIG behavior using typemaps</H3>
<p>
@ -2017,10 +2017,10 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
</pre>
</div>
<H2><a name="Allegrocl_nn47"></a>17.5 Identifier Converter functions</H2>
<H2><a name="Allegrocl_nn47"></a>18.5 Identifier Converter functions</H2>
<H3><a name="Allegrocl_nn48"></a>17.5.1 Creating symbols in the lisp environment</H3>
<H3><a name="Allegrocl_nn48"></a>18.5.1 Creating symbols in the lisp environment</H3>
<p>
@ -2041,11 +2041,11 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
of arguments.
</p>
<H3><a name="Allegrocl_nn49"></a>17.5.2 Existing identifier-converter functions</H3>
<H3><a name="Allegrocl_nn49"></a>18.5.2 Existing identifier-converter functions</H3>
<p>Two basic identifier routines have been defined.
<H4><a name="Allegrocl_nn50"></a>17.5.2.1 identifier-convert-null</H4>
<H4><a name="Allegrocl_nn50"></a>18.5.2.1 identifier-convert-null</H4>
<p>
@ -2054,7 +2054,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
strings, from which a symbol will be created.
</p>
<H4><a name="Allegrocl_nn51"></a>17.5.2.2 identifier-convert-lispify</H4>
<H4><a name="Allegrocl_nn51"></a>18.5.2.2 identifier-convert-lispify</H4>
<p>
@ -2063,7 +2063,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
same symbol transformations.
</p>
<H4><a name="Allegrocl_nn52"></a>17.5.2.3 Default identifier to symbol conversions</H4>
<H4><a name="Allegrocl_nn52"></a>18.5.2.3 Default identifier to symbol conversions</H4>
<p>
@ -2072,7 +2072,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN)
default naming conventions.
</p>
<H3><a name="Allegrocl_nn53"></a>17.5.3 Defining your own identifier-converter</H3>
<H3><a name="Allegrocl_nn53"></a>18.5.3 Defining your own identifier-converter</H3>
<p>
@ -2093,7 +2093,7 @@ foreign environment.
<p>
The :type keyword argument provides more information on the type of
identifier. It's value is a symbol. This allows the
identifier. Its value is a symbol. This allows the
identifier-converter to apply different heuristics when mapping
different types of identifiers to symbols. SWIG will generate calls
to your identifier-converter using the following types.
@ -2123,12 +2123,12 @@ scope in the specified class.
<p>
The :arity keyword argument only appears in swig:swig-defmethod forms
generated for overloaded functions. It's value is an integer
generated for overloaded functions. Its value is an integer
indicating the number of arguments passed to the routine indicated by
this identifier.
</p>
<H3><a name="Allegrocl_nn54"></a>17.5.4 Instructing SWIG to use a particular identifier-converter</H3>
<H3><a name="Allegrocl_nn54"></a>18.5.4 Instructing SWIG to use a particular identifier-converter</H3>
<p>

View file

@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body bgcolor="#FFFFFF">
<H1><a name="Android"></a>18 SWIG and Android</H1>
<H1><a name="Android"></a>19 SWIG and Android</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -15,7 +15,9 @@
<li><a href="#Android_examples_intro">Examples introduction</a>
<li><a href="#Android_example_simple">Simple C example</a>
<li><a href="#Android_example_class">C++ class example</a>
<li><a href="#Android_examples_other">Other examples</a>
</ul>
<li><a href="#Android_stl">C++ STL</a>
</ul>
</div>
<!-- INDEX -->
@ -28,7 +30,7 @@ This chapter describes SWIG's support of Android.
<H2><a name="Android_overview"></a>18.1 Overview</H2>
<H2><a name="Android_overview"></a>19.1 Overview</H2>
<p>
@ -38,14 +40,14 @@ Everything in the <a href="Java.html">Java chapter</a> applies to generating cod
This chapter contains a few Android specific notes and examples.
</p>
<H2><a name="Android_examples"></a>18.2 Android examples</H2>
<H2><a name="Android_examples"></a>19.2 Android examples</H2>
<H3><a name="Android_examples_intro"></a>18.2.1 Examples introduction</H3>
<H3><a name="Android_examples_intro"></a>19.2.1 Examples introduction</H3>
<p>
The examples require the the <a href="http://developer.android.com/sdk/index.html">Android SDK</a> and <a href="http://developer.android.com/sdk/ndk/index.html">Android NDK</a> which can be installed as per instructions in the links.
The examples require the <a href="http://developer.android.com/sdk/index.html">Android SDK</a> and <a href="http://developer.android.com/sdk/ndk/index.html">Android NDK</a> which can be installed as per instructions in the links.
The Eclipse version is not required for these examples as just the command line tools are used (shown for Linux as the host, but Windows will be very similar, if not identical in most places).
Add the SDK tools and NDK tools to your path and create a directory somewhere for your Android projects (adjust PATH as necessary to where you installed the tools):
</p>
@ -74,7 +76,7 @@ $ android list targets
The following examples are shipped with SWIG under the Examples/android directory and include a Makefile to build and install each example.
</p>
<H3><a name="Android_example_simple"></a>18.2.2 Simple C example</H3>
<H3><a name="Android_example_simple"></a>19.2.2 Simple C example</H3>
<p>
@ -396,7 +398,7 @@ Run the app again and this time you will see the output pictured below, showing
<center><img src="android-simple.png" alt="Android screenshot of SwigSimple example"></center>
<H3><a name="Android_example_class"></a>18.2.3 C++ class example</H3>
<H3><a name="Android_example_class"></a>19.2.3 C++ class example</H3>
<p>
@ -433,11 +435,11 @@ public:
}
virtual ~Shape() {
nshapes--;
};
}
double x, y;
void move(double dx, double dy);
virtual double area(void) = 0;
virtual double perimeter(void) = 0;
virtual double area() = 0;
virtual double perimeter() = 0;
static int nshapes;
};
@ -445,18 +447,18 @@ class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { };
virtual double area(void);
virtual double perimeter(void);
Circle(double r) : radius(r) { }
virtual double area();
virtual double perimeter();
};
class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
virtual double area(void);
virtual double perimeter(void);
Square(double w) : width(w) { }
virtual double area();
virtual double perimeter();
};
</pre>
</div>
@ -480,19 +482,19 @@ void Shape::move(double dx, double dy) {
int Shape::nshapes = 0;
double Circle::area(void) {
double Circle::area() {
return M_PI*radius*radius;
}
double Circle::perimeter(void) {
double Circle::perimeter() {
return 2*M_PI*radius;
}
double Square::area(void) {
double Square::area() {
return width*width;
}
double Square::perimeter(void) {
double Square::perimeter() {
return 4*width;
}
</pre>
@ -744,6 +746,36 @@ Run the app to see the result of calling the C++ code from Java:
<center><img src="android-class.png" alt="Android screenshot of SwigClass example"></center>
<H3><a name="Android_examples_other"></a>19.2.4 Other examples</H3>
<p>
The Examples/android directory contains further examples which can be run and installed in a similar manner to the previous two examples.
</p>
<p>
Note that the 'extend' example is demonstrates the directors feature.
Normally C++ exception handling and the STL is not available by default in the version of g++ shipped with Android, but this example turns these features on as described in the next section.
</p>
<H2><a name="Android_stl"></a>19.3 C++ STL</H2>
<p>
Should the C++ Standard Template Library (STL) be required, an <tt>Application.mk</tt> file needs to be created
in the same directory as the <tt>Android.mk</tt> directory containing information about the STL to use.
See the NDK documentation in the $NDKROOT/docs folder especially CPLUSPLUS-SUPPORT.html.
Below is an example of the <tt>Application.mk</tt> file to make the STLport static library available for use:
</p>
<div class="code">
<pre>
# File: Application.mk
APP_STL := gnustl_static
</pre>
</div>
</body>
</html>

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Arguments"></a>9 Argument Handling</H1>
<H1><a name="Arguments"></a>10 Argument Handling</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -42,7 +42,7 @@ return multiple values through the arguments of a function. This chapter
describes some of the techniques for doing this.
</p>
<H2><a name="Arguments_nn2"></a>9.1 The typemaps.i library</H2>
<H2><a name="Arguments_nn2"></a>10.1 The typemaps.i library</H2>
<p>
@ -50,7 +50,7 @@ This section describes the <tt>typemaps.i</tt> library file--commonly used to
change certain properties of argument conversion.
</p>
<H3><a name="Arguments_nn3"></a>9.1.1 Introduction</H3>
<H3><a name="Arguments_nn3"></a>10.1.1 Introduction</H3>
<p>
@ -194,7 +194,7 @@ else. To clear a typemap, the <tt>%clear</tt> directive should be used. For e
</pre>
</div>
<H3><a name="Arguments_nn4"></a>9.1.2 Input parameters</H3>
<H3><a name="Arguments_nn4"></a>10.1.2 Input parameters</H3>
<p>
@ -247,7 +247,7 @@ When the function is used in the scripting language interpreter, it will work li
result = add(3,4)
</pre></div>
<H3><a name="Arguments_nn5"></a>9.1.3 Output parameters</H3>
<H3><a name="Arguments_nn5"></a>10.1.3 Output parameters</H3>
<p>
@ -314,7 +314,7 @@ iresult, dresult = foo(3.5, 2)
</pre>
</div>
<H3><a name="Arguments_nn6"></a>9.1.4 Input/Output parameters</H3>
<H3><a name="Arguments_nn6"></a>10.1.4 Input/Output parameters</H3>
<p>
@ -379,7 +379,7 @@ rather than directly overwriting the value of the original input object.
SWIG. Backwards compatibility is preserved, but deprecated.
</p>
<H3><a name="Arguments_nn7"></a>9.1.5 Using different names</H3>
<H3><a name="Arguments_nn7"></a>10.1.5 Using different names</H3>
<p>
@ -413,7 +413,7 @@ Typemap declarations are lexically scoped so a typemap takes effect from the poi
file or a matching <tt>%clear</tt> declaration.
</p>
<H2><a name="Arguments_nn8"></a>9.2 Applying constraints to input values</H2>
<H2><a name="Arguments_nn8"></a>10.2 Applying constraints to input values</H2>
<p>
@ -423,7 +423,7 @@ insure that a value is positive, or that a pointer is non-NULL. This
can be accomplished including the <tt>constraints.i</tt> library file.
</p>
<H3><a name="Arguments_nn9"></a>9.2.1 Simple constraint example</H3>
<H3><a name="Arguments_nn9"></a>10.2.1 Simple constraint example</H3>
<p>
@ -449,7 +449,7 @@ the arguments violate the constraint condition, a scripting language
exception will be raised. As a result, it is possible to catch bad
values, prevent mysterious program crashes and so on.</p>
<H3><a name="Arguments_nn10"></a>9.2.2 Constraint methods</H3>
<H3><a name="Arguments_nn10"></a>10.2.2 Constraint methods</H3>
<p>
@ -465,7 +465,7 @@ NONNULL Non-NULL pointer (pointers only).
</pre></div>
<H3><a name="Arguments_nn11"></a>9.2.3 Applying constraints to new datatypes</H3>
<H3><a name="Arguments_nn11"></a>10.2.3 Applying constraints to new datatypes</H3>
<p>

1182
Doc/Manual/CPlusPlus11.html Normal file

File diff suppressed because it is too large Load diff

View file

@ -5,11 +5,14 @@
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body bgcolor="#FFFFFF">
<H1><a name="CSharp"></a>19 SWIG and C#</H1>
<H1><a name="CSharp"></a>20 SWIG and C#</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
<li><a href="#CSharp_introduction">Introduction</a>
<ul>
<li><a href="#CSharp_introduction_swig2_compatibility">SWIG 2 Compatibility</a>
</ul>
<li><a href="#CSharp_differences_java">Differences to the Java module</a>
<li><a href="#CSharp_void_pointers">Void pointers</a>
<li><a href="#CSharp_arrays">C# Arrays</a>
@ -38,6 +41,7 @@
<li><a href="#CSharp_memory_management_objects">Memory management for objects passed to the C++ layer</a>
<li><a href="#CSharp_date_marshalling">Date marshalling using the csin typemap and associated attributes</a>
<li><a href="#CSharp_date_properties">A date example demonstrating marshalling of C# properties</a>
<li><a href="#CSharp_date_pre_post_directors">Date example demonstrating the 'pre' and 'post' typemap attributes for directors</a>
<li><a href="#CSharp_partial_classes">Turning wrapped classes into partial classes</a>
<li><a href="#CSharp_extending_proxy_class">Extending proxy classes with additional C# code</a>
<li><a href="#CSharp_enum_underlying_type">Underlying type for enums</a>
@ -48,7 +52,7 @@
<H2><a name="CSharp_introduction"></a>19.1 Introduction</H2>
<H2><a name="CSharp_introduction"></a>20.1 Introduction</H2>
<p>
@ -68,7 +72,14 @@ The <a href="http://msdn.microsoft.com">Microsoft Developer Network (MSDN)</a> h
Monodoc, available from the Mono project, has a very useful section titled <a href="http://www.mono-project.com/Interop_with_Native_Libraries">Interop with native libraries</a>.
</p>
<H2><a name="CSharp_differences_java"></a>19.2 Differences to the Java module</H2>
<H3><a name="CSharp_introduction_swig2_compatibility"></a>20.1.1 SWIG 2 Compatibility</H3>
<p>
In order to minimize name collisions between names generated based on input to SWIG and names used in the generated code from the .NET framework, SWIG 3 fully qualifies the use of all .NET types. Furthermore, SWIG 3 avoids <tt>using</tt> directives in generated code. This breaks backwards compatibility with typemaps, pragmas, etc written for use with SWIG 2 that assume the presence of <tt>using System;</tt> or <tt>using System.Runtime.InteropServices;</tt> directives in the intermediate class imports, module imports, or proxy imports. SWIG 3 supports backwards compatibility though the use of the <tt>SWIG2_CSHARP</tt> macro. If <tt>SWIG2_CSHARP</tt> is defined, SWIG 3 generates <tt>using</tt> directives in the intermediate class, module class, and proxy class code similar to those generated by SWIG 2. This can be done without modifying any of the input code by passing the <tt>-DSWIG2_CSHARP</tt> commandline parameter when executing <tt>swig</tt>.
</p>
<H2><a name="CSharp_differences_java"></a>20.2 Differences to the Java module</H2>
<p>
@ -190,6 +201,20 @@ csattributes C# attributes for attaching to proxy classes/enums
</li>
<li>
<p>Additional typemap attributes:</p>
<p>
The "null" attribute in the "out" typemap can be specified to provide a value for <tt>$null</tt> to expand into for wrapped functions that return non-void. Normally the default value of <tt>0</tt> is used.
For example this is needed if you change the return type to void:
</p>
<div class="code"><pre>
%typemap(ctype) Status "void"
%typemap(out, null="") Status { ... }
</pre></div>
</li>
<li>
<p>Feature equivalent names:</p>
<div class="code"><pre>
@ -227,10 +252,12 @@ $jnicall -&gt; $imcall
<p>
Unlike the "javain" typemap, the "csin" typemap does not support the 'pgcpp' attribute as the C# module does not have a premature garbage collection prevention parameter.
The "csin" typemap supports additional optional attributes called 'cshin' and 'terminator'.
The "csdirectorin" typemap supports additional optional attributes called 'terminator'.
The 'cshin' attribute should contain the parameter type and name whenever a <a href="Java.html#Java_constructor_helper_function">constructor helper function</a> is generated due to the 'pre' or 'post' attributes.
The 'terminator' attribute normally just contains a closing brace for when the 'pre' attribute contains an opening brace, such as when a C# <tt>using</tt> or <tt>fixed</tt> block is started.
Note that 'pre', 'post', 'terminator' and 'cshin' attributes are not used for marshalling the property set.
Please see the <a href="#CSharp_date_marshalling">Date marshalling example</a> and <a href="#CSharp_date_properties">Date marshalling of properties example</a> for further understanding of these "csin" applicable attributes.
Please see the <a href="#CSharp_date_pre_post_directors">Date marshalling director example</a> for further understanding of the "csdirectorin" attributes.
</p>
</li>
@ -245,7 +272,7 @@ An example shows that <tt>char *</tt> could be marshalled in different ways,
<div class="code">
<pre>
%typemap(imtype, out="IntPtr") char * "string"
%typemap(imtype, out="global::System.IntPtr") char * "string"
char * function(char *);
</pre>
</div>
@ -256,7 +283,7 @@ The output type is thus IntPtr and the input type is string. The resulting inter
<div class="code">
<pre>
public static extern IntPtr function(string jarg1);
public static extern global::System.IntPtr function(string jarg1);
</pre>
</div>
@ -277,8 +304,8 @@ For example:
<div class="code">
<pre>
%typemap(imtype,
inattributes="[MarshalAs(UnmanagedType.LPStr)]",
outattributes="[return: MarshalAs(UnmanagedType.LPStr)]") const char * "String"
inattributes="[global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPStr)]",
outattributes="[return: global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPStr)]") const char * "String"
const char * GetMsg() {}
void SetMsg(const char *msg) {}
@ -293,12 +320,12 @@ The intermediary class will then have the marshalling as specified by everything
<pre>
class examplePINVOKE {
...
[DllImport("example", EntryPoint="CSharp_GetMsg")]
[return: MarshalAs(UnmanagedType.LPStr)]
[global::System.Runtime.InteropServices.DllImport("example", EntryPoint="CSharp_GetMsg")]
[return: global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPStr)]
public static extern String GetMsg();
[DllImport("example", EntryPoint="CSharp_SetMsg")]
public static extern void SetMsg([MarshalAs(UnmanagedType.LPStr)]String jarg1);
[global::System.Runtime.InteropServices.DllImport("example", EntryPoint="CSharp_SetMsg")]
public static extern void SetMsg([global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPStr)]String jarg1);
}
</pre>
</div>
@ -351,7 +378,7 @@ will generate a C# proxy class:
<div class="code">
<pre>
[ThreadSafe]
public class AClass : IDisposable {
public class AClass : global::System.IDisposable {
...
[ThreadSafe(false)]
public AClass(double a) ...
@ -375,9 +402,9 @@ An example for attaching attributes to the enum and enum values is shown below.
<div class="code">
<pre>
%typemap(csattributes) Couleur "[System.ComponentModel.Description(\"Colours\")]"
%csattributes Rouge "[System.ComponentModel.Description(\"Red\")]"
%csattributes Vert "[System.ComponentModel.Description(\"Green\")]"
%typemap(csattributes) Couleur "[global::System.ComponentModel.Description(\"Colours\")]"
%csattributes Rouge "[global::System.ComponentModel.Description(\"Red\")]"
%csattributes Vert "[global::System.ComponentModel.Description(\"Green\")]"
%inline %{
enum Couleur { Rouge, Orange, Vert };
%}
@ -390,12 +417,12 @@ which will result in the following C# enum:
<div class="code">
<pre>
[System.ComponentModel.Description("Colours")]
[global::System.ComponentModel.Description("Colours")]
public enum Couleur {
[System.ComponentModel.Description("Red")]
[global::System.ComponentModel.Description("Red")]
Rouge,
Orange,
[System.ComponentModel.Description("Green")]
[global::System.ComponentModel.Description("Green")]
Vert
}
</pre>
@ -465,7 +492,7 @@ Windows users can also get the examples working using a
<a href="http://www.cygwin.com">Cygwin</a> or <a href="http://www.mingw.org">MinGW</a> environment for automatic configuration of the example makefiles.
Any one of the three C# compilers (Portable.NET, Mono or Microsoft) can be detected from within a Cygwin or Mingw environment if installed in your path.
<H2><a name="CSharp_void_pointers"></a>19.3 Void pointers</H2>
<H2><a name="CSharp_void_pointers"></a>20.3 Void pointers</H2>
<p>
@ -483,7 +510,7 @@ void * f(void *v);
</pre>
</div>
<H2><a name="CSharp_arrays"></a>19.4 C# Arrays</H2>
<H2><a name="CSharp_arrays"></a>20.4 C# Arrays</H2>
<p>
@ -495,7 +522,7 @@ with one of the following three approaches; namely the SWIG C arrays library, P/
pinned arrays.
</p>
<H3><a name="CSharp_arrays_swig_library"></a>19.4.1 The SWIG C arrays library</H3>
<H3><a name="CSharp_arrays_swig_library"></a>20.4.1 The SWIG C arrays library</H3>
<p>
@ -532,7 +559,7 @@ example.print_array(c.cast()); // Pass to C
</div>
<H3><a name="CSharp_arrays_pinvoke_default_array_marshalling"></a>19.4.2 Managed arrays using P/Invoke default array marshalling</H3>
<H3><a name="CSharp_arrays_pinvoke_default_array_marshalling"></a>20.4.2 Managed arrays using P/Invoke default array marshalling</H3>
<p>
@ -601,9 +628,9 @@ marshalling for the arrays:
<div class="code">
<pre>
[DllImport("example", EntryPoint="CSharp_myArrayCopy")]
public static extern void myArrayCopy([In, MarshalAs(UnmanagedType.LPArray)]int[] jarg1,
[Out, MarshalAs(UnmanagedType.LPArray)]int[] jarg2,
[global::System.Runtime.InteropServices.DllImport("example", EntryPoint="CSharp_myArrayCopy")]
public static extern void myArrayCopy([global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray)]int[] jarg1,
[global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray)]int[] jarg2,
int jarg3);
</pre>
</div>
@ -651,15 +678,15 @@ and intermediary class method
<div class="code">
<pre>
[DllImport("example", EntryPoint="CSharp_myArraySwap")]
public static extern void myArraySwap([In, Out, MarshalAs(UnmanagedType.LPArray)]int[] jarg1,
[In, Out, MarshalAs(UnmanagedType.LPArray)]int[] jarg2,
[global::System.Runtime.InteropServices.DllImport("example", EntryPoint="CSharp_myArraySwap")]
public static extern void myArraySwap([global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray)]int[] jarg1,
[global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.Out, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray)]int[] jarg2,
int jarg3);
</pre>
</div>
<H3><a name="CSharp_arrays_pinning"></a>19.4.3 Managed arrays using pinning</H3>
<H3><a name="CSharp_arrays_pinning"></a>20.4.3 Managed arrays using pinning</H3>
<p>
@ -726,7 +753,7 @@ As a result, we get the following method in the module class:
fixed ( int *swig_ptrTo_sourceArray = sourceArray ) {
fixed ( int *swig_ptrTo_targetArray = targetArray ) {
{
examplePINVOKE.myArrayCopy((IntPtr)swig_ptrTo_sourceArray, (IntPtr)swig_ptrTo_targetArray,
examplePINVOKE.myArrayCopy((global::System.IntPtr)swig_ptrTo_sourceArray, (global::System.IntPtr)swig_ptrTo_targetArray,
nitems);
}
}
@ -747,14 +774,14 @@ example - the method is expecting an IntPtr as the parameter type.
<div class="code">
<pre>
[DllImport("example", EntryPoint="CSharp_myArrayCopy")]
public static extern void myArrayCopy(IntPtr jarg1, IntPtr jarg2, int jarg3);
[global::System.Runtime.InteropServices.DllImport("example", EntryPoint="CSharp_myArrayCopy")]
public static extern void myArrayCopy(global::System.IntPtr jarg1, global::System.IntPtr jarg2, int jarg3);
</pre>
</div>
<H2><a name="CSharp_exceptions"></a>19.5 C# Exceptions</H2>
<H2><a name="CSharp_exceptions"></a>20.5 C# Exceptions</H2>
<p>
@ -851,11 +878,11 @@ set so should only be used when a C# exception is not created.
</p>
<H3><a name="CSharp_exception_example_check_typemap"></a>19.5.1 C# exception example using "check" typemap</H3>
<H3><a name="CSharp_exception_example_check_typemap"></a>20.5.1 C# exception example using "check" typemap</H3>
<p>
Lets say we have the following simple C++ method:
Let's say we have the following simple C++ method:
</p>
@ -1033,7 +1060,7 @@ method and C# code does not handle pending exceptions via the canthrow attribute
Actually it will issue this warning for any function beginning with <tt>SWIG_CSharpSetPendingException</tt>.
</P>
<H3><a name="CSharp_exception_example_percent_exception"></a>19.5.2 C# exception example using %exception</H3>
<H3><a name="CSharp_exception_example_percent_exception"></a>20.5.2 C# exception example using %exception</H3>
<p>
@ -1098,7 +1125,7 @@ The managed code generated does check for the pending exception as mentioned ear
</pre>
</div>
<H3><a name="CSharp_exception_example_exception_specifications"></a>19.5.3 C# exception example using exception specifications</H3>
<H3><a name="CSharp_exception_example_exception_specifications"></a>20.5.3 C# exception example using exception specifications</H3>
<p>
@ -1155,7 +1182,7 @@ SWIGEXPORT void SWIGSTDCALL CSharp_evensonly(int jarg1) {
Multiple catch handlers are generated should there be more than one exception specifications declared.
</p>
<H3><a name="CSharp_custom_application_exception"></a>19.5.4 Custom C# ApplicationException example</H3>
<H3><a name="CSharp_custom_application_exception"></a>20.5.4 Custom C# ApplicationException example</H3>
<p>
@ -1203,7 +1230,7 @@ the C# code can be generated into the intermediary class using the <tt>imclassco
static CustomExceptionDelegate customDelegate =
new CustomExceptionDelegate(SetPendingCustomException);
[DllImport("$dllimport", EntryPoint="CustomExceptionRegisterCallback")]
[global::System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="CustomExceptionRegisterCallback")]
public static extern
void CustomExceptionRegisterCallback(CustomExceptionDelegate customCallback);
@ -1247,7 +1274,7 @@ The boiler plate code above must be used in addition to a handcrafted <tt>Custom
<div class="code">
<pre>
// Custom C# Exception
class CustomApplicationException : System.ApplicationException {
class CustomApplicationException : global::System.ApplicationException {
public CustomApplicationException(string message)
: base(message) {
}
@ -1289,7 +1316,7 @@ try {
</pre>
</div>
<H2><a name="CSharp_directors"></a>19.6 C# Directors</H2>
<H2><a name="CSharp_directors"></a>20.6 C# Directors</H2>
<p>
@ -1302,7 +1329,7 @@ The following sections provide information on the C# director implementation and
However, the <a href="Java.html#Java_directors">Java directors</a> section should also be read in order to gain more insight into directors.
</p>
<H3><a name="CSharp_directors_example"></a>19.6.1 Directors example</H3>
<H3><a name="CSharp_directors_example"></a>20.6.1 Directors example</H3>
<p>
@ -1423,7 +1450,7 @@ CSharpDerived - UIntMethod(123)
</pre>
</div>
<H3><a name="CSharp_directors_implementation"></a>19.6.2 Directors implementation</H3>
<H3><a name="CSharp_directors_implementation"></a>20.6.2 Directors implementation</H3>
<p>
@ -1440,20 +1467,17 @@ Below is the generated C# <tt>Base</tt> director class.
<div class="code">
<pre>
using System;
using System.Runtime.InteropServices;
public class Base : IDisposable {
private HandleRef swigCPtr;
public class Base : global::System.IDisposable {
private global::System.Runtime.InteropServices.HandleRef swigCPtr;
protected bool swigCMemOwn;
internal Base(IntPtr cPtr, bool cMemoryOwn) {
internal Base(global::System.IntPtr cPtr, bool cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = new HandleRef(this, cPtr);
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
}
internal static HandleRef getCPtr(Base obj) {
return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Base obj) {
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
~Base() {
@ -1462,12 +1486,12 @@ public class Base : IDisposable {
public virtual void Dispose() {
lock(this) {
if(swigCPtr.Handle != IntPtr.Zero &amp;&amp; swigCMemOwn) {
if(swigCPtr.Handle != global::System.IntPtr.Zero &amp;&amp; swigCMemOwn) {
swigCMemOwn = false;
examplePINVOKE.delete_Base(swigCPtr);
}
swigCPtr = new HandleRef(null, IntPtr.Zero);
GC.SuppressFinalize(this);
swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
global::System.GC.SuppressFinalize(this);
}
}
@ -1494,7 +1518,7 @@ public class Base : IDisposable {
examplePINVOKE.Base_director_connect(swigCPtr, swigDelegate0, swigDelegate1);
}
private bool SwigDerivedClassHasMethod(string methodName, Type[] methodTypes) {
private bool SwigDerivedClassHasMethod(string methodName, global::System.global::System.Type[] methodTypes) {
System.Reflection.MethodInfo methodInfo = this.GetType().GetMethod(methodName, methodTypes);
bool hasDerivedMethod = methodInfo.DeclaringType.IsSubclassOf(typeof(Base));
return hasDerivedMethod;
@ -1504,18 +1528,18 @@ public class Base : IDisposable {
return UIntMethod(x);
}
private void SwigDirectorBaseBoolMethod(IntPtr b, bool flag) {
private void SwigDirectorBaseBoolMethod(global::System.IntPtr b, bool flag) {
BaseBoolMethod(new Base(b, false), flag);
}
internal delegate uint SwigDelegateBase_0(uint x);
internal delegate void SwigDelegateBase_1(IntPtr b, bool flag);
internal delegate void SwigDelegateBase_1(global::System.IntPtr b, bool flag);
private SwigDelegateBase_0 swigDelegate0;
private SwigDelegateBase_1 swigDelegate1;
private static Type[] swigMethodTypes0 = new Type[] { typeof(uint) };
private static Type[] swigMethodTypes1 = new Type[] { typeof(Base), typeof(bool) };
private static global::System.Type[] swigMethodTypes0 = new global::System.Type[] { typeof(uint) };
private static global::System.Type[] swigMethodTypes1 = new global::System.Type[] { typeof(Base), typeof(bool) };
}
</pre>
</div>
@ -1609,7 +1633,7 @@ void SwigDirector_Base::BaseBoolMethod(Base const &amp;b, bool flag) {
</pre>
</div>
<H3><a name="CSharp_director_caveats"></a>19.6.3 Director caveats</H3>
<H3><a name="CSharp_director_caveats"></a>20.6.3 Director caveats</H3>
<p>
@ -1657,7 +1681,7 @@ However, a call from C# to <tt>CSharpDefaults.DefaultMethod()</tt> will of cours
should pass the call on to <tt>CSharpDefaults.DefaultMethod(int)</tt>using the C++ default value, as shown above.
</p>
<H2><a name="CSharp_multiple_modules"></a>19.7 Multiples modules</H2>
<H2><a name="CSharp_multiple_modules"></a>20.7 Multiples modules</H2>
<p>
@ -1692,7 +1716,7 @@ the <tt>[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrows
if you don't want users to easily stumble upon these so called 'internal workings' of the wrappers.
</p>
<H2><a name="CSharp_typemap_examples"></a>19.8 C# Typemap examples</H2>
<H2><a name="CSharp_typemap_examples"></a>20.8 C# Typemap examples</H2>
This section includes a few examples of typemaps. For more examples, you
@ -1700,7 +1724,7 @@ might look at the files "<tt>csharp.swg</tt>" and "<tt>typemaps.i</tt>" in
the SWIG library.
<H3><a name="CSharp_memory_management_member_variables"></a>19.8.1 Memory management when returning references to member variables</H3>
<H3><a name="CSharp_memory_management_member_variables"></a>20.8.1 Memory management when returning references to member variables</H3>
<p>
@ -1738,9 +1762,9 @@ and the following usage from C# after running the code through SWIG:
Wheel wheel = new Bike(10).getWheel();
Console.WriteLine("wheel size: " + wheel.size);
// Simulate a garbage collection
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
Console.WriteLine("wheel size: " + wheel.size);
global::System.GC.Collect();
global::System.GC.WaitForPendingFinalizers();
global::System.Console.WriteLine("wheel size: " + wheel.size);
</pre>
</div>
@ -1778,9 +1802,9 @@ is called using the following typemaps.
// of dangling C++ pointer. Intended for methods that return pointers or
// references to a member variable.
%typemap(csout, excode=SWIGEXCODE) Wheel&amp; getWheel {
IntPtr cPtr = $imcall;$excode
global::System.IntPtr cPtr = $imcall;$excode
$csclassname ret = null;
if (cPtr != IntPtr.Zero) {
if (cPtr != global::System.IntPtr.Zero) {
ret = new $csclassname(cPtr, $owner);
ret.addReference(this);
}
@ -1796,7 +1820,7 @@ The code in the second typemap constitutes the bulk of the code in the generated
<div class="code">
<pre>
public class Wheel : IDisposable {
public class Wheel : global::System.IDisposable {
...
// Ensure that the GC doesn't collect any Bike instance set from C#
private Bike bikeReference;
@ -1805,12 +1829,12 @@ public class Wheel : IDisposable {
}
}
public class Bike : IDisposable {
public class Bike : global::System.IDisposable {
...
public Wheel getWheel() {
IntPtr cPtr = examplePINVOKE.Bike_getWheel(swigCPtr);
global::System.IntPtr cPtr = examplePINVOKE.Bike_getWheel(swigCPtr);
Wheel ret = null;
if (cPtr != IntPtr.Zero) {
if (cPtr != global::System.IntPtr.Zero) {
ret = new Wheel(cPtr, false);
ret.addReference(this);
}
@ -1824,7 +1848,7 @@ public class Bike : IDisposable {
Note the <tt>addReference</tt> call.
</p>
<H3><a name="CSharp_memory_management_objects"></a>19.8.2 Memory management for objects passed to the C++ layer</H3>
<H3><a name="CSharp_memory_management_objects"></a>20.8.2 Memory management for objects passed to the C++ layer</H3>
<p>
@ -1887,9 +1911,9 @@ In order to understand why, consider a garbage collection occuring...
container.setElement(element);
Console.WriteLine("element.value: " + container.getElement().value);
// Simulate a garbage collection
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
Console.WriteLine("element.value: " + container.getElement().value);
global::System.GC.Collect();
global::System.GC.WaitForPendingFinalizers();
global::System.Console.WriteLine("element.value: " + container.getElement().value);
</pre>
</div>
@ -1901,14 +1925,14 @@ One solution is to add in the appropriate references in the C# layer...
<div class="code">
<pre>
public class Container : IDisposable {
public class Container : global::System.IDisposable {
...
// Ensure that the GC doesn't collect any Element set from C#
// as the underlying C++ class stores a shallow copy
private Element elementReference;
private HandleRef getCPtrAndAddReference(Element element) {
private global::System.Runtime.InteropServices.HandleRef getCPtrAndAddReference(Element element) {
elementReference = element;
return Element.getCPtr(element);
}
@ -1934,7 +1958,7 @@ The 'cscode' typemap simply adds in the specified code into the C# proxy class.
// Ensure that the GC doesn't collect any Element set from C#
// as the underlying C++ class stores a shallow copy
private Element elementReference;
private HandleRef getCPtrAndAddReference(Element element) {
private global::System.Runtime.InteropServices.HandleRef getCPtrAndAddReference(Element element) {
elementReference = element;
return Element.getCPtr(element);
}
@ -1943,7 +1967,7 @@ The 'cscode' typemap simply adds in the specified code into the C# proxy class.
</div>
<H3><a name="CSharp_date_marshalling"></a>19.8.3 Date marshalling using the csin typemap and associated attributes</H3>
<H3><a name="CSharp_date_marshalling"></a>20.8.3 Date marshalling using the csin typemap and associated attributes</H3>
<p>
@ -1983,7 +2007,7 @@ First let's look at the code that is generated by default, where the C# proxy cl
<div class="code">
<pre>
public class Action : IDisposable {
public class Action : global::System.IDisposable {
...
public Action(CDate dateIn, CDate dateOut)
: this(examplePINVOKE.new_Action(CDate.getCPtr(dateIn), CDate.getCPtr(dateOut)), true) {
@ -2040,13 +2064,13 @@ The typemaps to achieve this are shown below.
<div class="code">
<pre>
%typemap(cstype) const CDate&amp; "System.DateTime"
%typemap(cstype) const CDate &amp; "System.DateTime"
%typemap(csin,
pre=" CDate temp$csinput = new CDate($csinput.Year, $csinput.Month, $csinput.Day);"
) const CDate &amp;
"$csclassname.getCPtr(temp$csinput)"
%typemap(cstype) CDate&amp; "out System.DateTime"
%typemap(cstype) CDate &amp; "out System.DateTime"
%typemap(csin,
pre=" CDate temp$csinput = new CDate();",
post=" $csinput = new System.DateTime(temp$csinput.getYear(),"
@ -2064,7 +2088,7 @@ The resulting generated proxy code in the <tt>Action</tt> class follows:
<div class="code">
<pre>
public class Action : IDisposable {
public class Action : global::System.IDisposable {
...
public int doSomething(System.DateTime dateIn, out System.DateTime dateOut) {
CDate tempdateIn = new CDate(dateIn.Year, dateIn.Month, dateIn.Day);
@ -2082,7 +2106,7 @@ public class Action : IDisposable {
}
}
static private IntPtr SwigConstructAction(System.DateTime dateIn, out System.DateTime dateOut) {
static private global::System.IntPtr SwigConstructAction(System.DateTime dateIn, out System.DateTime dateOut) {
CDate tempdateIn = new CDate(dateIn.Year, dateIn.Month, dateIn.Day);
CDate tempdateOut = new CDate();
try {
@ -2229,7 +2253,7 @@ public class example {
</pre>
</div>
<H3><a name="CSharp_date_properties"></a>19.8.4 A date example demonstrating marshalling of C# properties</H3>
<H3><a name="CSharp_date_properties"></a>20.8.4 A date example demonstrating marshalling of C# properties</H3>
<p>
@ -2257,7 +2281,7 @@ Console.WriteLine("Important date: " + importantDate);
</div>
<p>
When SWIG wraps a variable that is a class/struct/union, it is wrapped using a pointer to the type for the reasons given in <a href="SWIG.html#SWIG_structure_data_members">Stucture data members</a>.
When SWIG wraps a variable that is a class/struct/union, it is wrapped using a pointer to the type for the reasons given in <a href="SWIG.html#SWIG_structure_data_members">Structure data members</a>.
The typemap type required is thus <tt>CDate *</tt>. Given that the previous section already designed <tt>CDate *</tt> typemaps, we'll use those same typemaps plus the 'csvarin' and 'csvarout' typemaps.
<div class="code">
@ -2282,8 +2306,8 @@ The typemap type required is thus <tt>CDate *</tt>. Given that the previous sect
%typemap(csvarout, excode=SWIGEXCODE2) CDate * %{
/* csvarout typemap code */
get {
IntPtr cPtr = $imcall;
CDate tempDate = (cPtr == IntPtr.Zero) ? null : new CDate(cPtr, $owner);$excode
global::System.IntPtr cPtr = $imcall;
CDate tempDate = (cPtr == global::System.IntPtr.Zero) ? null : new CDate(cPtr, $owner);$excode
return new System.DateTime(tempDate.getYear(), tempDate.getMonth(), tempDate.getDay(),
0, 0, 0);
} %}
@ -2305,8 +2329,8 @@ public class example {
}
/* csvarout typemap code */
get {
IntPtr cPtr = examplePINVOKE.ImportantDate_get();
CDate tempDate = (cPtr == IntPtr.Zero) ? null : new CDate(cPtr, false);
global::System.IntPtr cPtr = examplePINVOKE.ImportantDate_get();
CDate tempDate = (cPtr == global::System.IntPtr.Zero) ? null : new CDate(cPtr, false);
return new System.DateTime(tempDate.getYear(), tempDate.getMonth(), tempDate.getDay(),
0, 0, 0);
}
@ -2329,8 +2353,69 @@ Some points to note:
<li>The 'csin' typemap has 'pre', 'post' and 'cshin' attributes, and these are all ignored in the property set. The code in these attributes must instead be replicated within the 'csvarin' typemap. The line creating the <tt>temp$csinput</tt> variable is such an example; it is identical to what is in the 'pre' attribute.
</ul>
<H3><a name="CSharp_date_pre_post_directors"></a>20.8.5 Date example demonstrating the 'pre' and 'post' typemap attributes for directors</H3>
<H3><a name="CSharp_partial_classes"></a>19.8.5 Turning wrapped classes into partial classes</H3>
<p>
The 'pre' and 'post' attributes in the "csdirectorin" typemap act like the attributes of the same name in the "csin" typemap.
For example if we modify the <a href="#CSharp_date_marshalling">Date marshalling example</a> like this:
</p>
<div class="code"><pre>
class CDate {
...
void setYear(int);
void setMonth(int);
void setDay(int);
};
struct Action {
virtual void someCallback(CDate &amp;date);
virtual ~Action();
...
};
</pre></div>
<p>
and declare <tt>%feature ("director")</tt> for the <tt>Action</tt> class, we would have to define additional
marshalling rules for <tt>CDate &amp;</tt> parameter. The typemap may look like this:
</p>
<div class="code"><pre>
%typemap(csdirectorin,
pre="System.DateTime temp$iminput = new System.DateTime();",
post="CDate temp2$iminput = new CDate($iminput, false);\n"
"temp2$iminput.setYear(tempdate.Year);\n"
"temp2$iminput.setMonth(tempdate.Month);\n"
"temp2$iminput.setDay(tempdate.Day);"
) CDate &amp;date "out temp$iminput"
</pre></div>
<p>
The generated proxy class code will then contain the following wrapper for calling user-overloaded <tt>someCallback()</tt>:
</p>
<div class="code"><pre>
...
private void SwigDirectorsomeCallback(global::System.IntPtr date) {
System.DateTime tempdate = new System.DateTime();
try {
someCallback(out tempdate);
} finally {
// we create a managed wrapper around the existing C reference, just for convenience
CDate temp2date = new CDate(date, false);
temp2date.setYear(tempdate.Year);
temp2date.setMonth(tempdate.Month);
temp2date.setDay(tempdate.Day);
}
}
...
</pre></div>
<p>
Pay special attention to the memory management issues, using these attributes.
</p>
<H3><a name="CSharp_partial_classes"></a>20.8.6 Turning wrapped classes into partial classes</H3>
<p>
@ -2354,7 +2439,7 @@ The default C# proxy class generated is:
<div class="code">
<pre>
public class ExtendMe : IDisposable {
public class ExtendMe : global::System.IDisposable {
...
public int Part1() {
...
@ -2390,7 +2475,7 @@ The C# proxy class becomes a partial class:
<div class="code">
<pre>
public partial class ExtendMe : IDisposable {
public partial class ExtendMe : global::System.IDisposable {
...
public int Part1() {
...
@ -2405,7 +2490,7 @@ You can then of course declare another part of the partial class elsewhere, for
<div class="code">
<pre>
public partial class ExtendMe : IDisposable {
public partial class ExtendMe : global::System.IDisposable {
public int Part2() {
return 2;
}
@ -2430,7 +2515,7 @@ demonstrating that the class contains methods calling both unmanaged code - <tt>
The following example is an alternative approach to adding managed code to the generated proxy class.
</p>
<H3><a name="CSharp_extending_proxy_class"></a>19.8.6 Extending proxy classes with additional C# code</H3>
<H3><a name="CSharp_extending_proxy_class"></a>20.8.7 Extending proxy classes with additional C# code</H3>
<p>
@ -2457,7 +2542,7 @@ The generated C# proxy class will instead be:
<div class="code">
<pre>
public class ExtendMe : IDisposable {
public class ExtendMe : global::System.IDisposable {
...
public int Part3() {
return 3;
@ -2469,7 +2554,7 @@ public class ExtendMe : IDisposable {
</pre>
</div>
<H3><a name="CSharp_enum_underlying_type"></a>19.8.7 Underlying type for enums</H3>
<H3><a name="CSharp_enum_underlying_type"></a>20.8.8 Underlying type for enums</H3>
<P>

View file

@ -8,7 +8,7 @@
<body bgcolor="#ffffff">
<H1><a name="Chicken"></a>20 SWIG and Chicken</H1>
<H1><a name="Chicken"></a>21 SWIG and Chicken</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -72,7 +72,7 @@
</p>
<H2><a name="Chicken_nn2"></a>20.1 Preliminaries</H2>
<H2><a name="Chicken_nn2"></a>21.1 Preliminaries</H2>
<p>
@ -89,7 +89,7 @@
directory for the basic steps to run SWIG CHICKEN.
</p>
<H3><a name="Chicken_nn3"></a>20.1.1 Running SWIG in C mode</H3>
<H3><a name="Chicken_nn3"></a>21.1.1 Running SWIG in C mode</H3>
<p>
@ -122,7 +122,7 @@
object files and linked into your project.
</p>
<H3><a name="Chicken_nn4"></a>20.1.2 Running SWIG in C++ mode</H3>
<H3><a name="Chicken_nn4"></a>21.1.2 Running SWIG in C++ mode</H3>
<p>
@ -151,10 +151,10 @@
object files and linked into your project.
</p>
<H2><a name="Chicken_nn5"></a>20.2 Code Generation</H2>
<H2><a name="Chicken_nn5"></a>21.2 Code Generation</H2>
<H3><a name="Chicken_nn6"></a>20.2.1 Naming Conventions</H3>
<H3><a name="Chicken_nn6"></a>21.2.1 Naming Conventions</H3>
<p>
@ -170,7 +170,7 @@
<tt>%rename</tt> SWIG directive in the SWIG interface file.
</p>
<H3><a name="Chicken_nn7"></a>20.2.2 Modules</H3>
<H3><a name="Chicken_nn7"></a>21.2.2 Modules</H3>
<p>
@ -192,7 +192,7 @@
(uses <i>modulename</i>))</code> CHICKEN Scheme form.
</p>
<H3><a name="Chicken_nn8"></a>20.2.3 Constants and Variables</H3>
<H3><a name="Chicken_nn8"></a>21.2.3 Constants and Variables</H3>
<p>
@ -229,7 +229,7 @@
for info on how to apply the %feature.
</p>
<H3><a name="Chicken_nn9"></a>20.2.4 Functions</H3>
<H3><a name="Chicken_nn9"></a>21.2.4 Functions</H3>
<p>
@ -248,7 +248,7 @@
parameters). The return values can then be accessed with <code>(call-with-values)</code>.
</p>
<H3><a name="Chicken_nn10"></a>20.2.5 Exceptions</H3>
<H3><a name="Chicken_nn10"></a>21.2.5 Exceptions</H3>
<p>The SWIG chicken module has support for exceptions thrown from
@ -290,7 +290,7 @@
</pre></div>
<H2><a name="Chicken_nn11"></a>20.3 TinyCLOS</H2>
<H2><a name="Chicken_nn11"></a>21.3 TinyCLOS</H2>
<p>
@ -333,7 +333,7 @@
</p>
<H2><a name="Chicken_nn12"></a>20.4 Linkage</H2>
<H2><a name="Chicken_nn12"></a>21.4 Linkage</H2>
<p>
@ -354,7 +354,7 @@
</p>
<H3><a name="Chicken_nn13"></a>20.4.1 Static binary or shared library linked at compile time</H3>
<H3><a name="Chicken_nn13"></a>21.4.1 Static binary or shared library linked at compile time</H3>
<p>We can easily use csc to build a static binary.</p>
@ -395,7 +395,7 @@ in which case the test script does not need to be linked with example.so. The t
be run with <tt>csi</tt>.
</p>
<H3><a name="Chicken_nn14"></a>20.4.2 Building chicken extension libraries</H3>
<H3><a name="Chicken_nn14"></a>21.4.2 Building chicken extension libraries</H3>
<p>Building a shared library like in the above section only works if the library
@ -453,7 +453,7 @@ distributed and used by anyone, even if SWIG is not installed.</p>
<p>See the <tt>Examples/chicken/egg</tt> directory in the SWIG source for an example that builds
two eggs, one using the first method and one using the second method.</p>
<H3><a name="Chicken_nn15"></a>20.4.3 Linking multiple SWIG modules with TinyCLOS</H3>
<H3><a name="Chicken_nn15"></a>21.4.3 Linking multiple SWIG modules with TinyCLOS</H3>
<p>Linking together multiple modules that share type information using the <code>%import</code>
@ -477,7 +477,7 @@ with <code>(declare (uses ...))</code>.
To create an extension library or an egg, just create a <tt>module_load.scm</tt> file that <code>(declare (uses ...))</code>
all the modules.</p>
<H2><a name="Chicken_nn16"></a>20.5 Typemaps</H2>
<H2><a name="Chicken_nn16"></a>21.5 Typemaps</H2>
<p>
@ -486,7 +486,7 @@ all the modules.</p>
<code>Lib/chicken/chicken.swg</code>.
</p>
<H2><a name="Chicken_nn17"></a>20.6 Pointers</H2>
<H2><a name="Chicken_nn17"></a>21.6 Pointers</H2>
<p>
@ -519,7 +519,7 @@ all the modules.</p>
type. flags is either zero or SWIG_POINTER_DISOWN (see below).
</p>
<H3><a name="Chicken_collection"></a>20.6.1 Garbage collection</H3>
<H3><a name="Chicken_collection"></a>21.6.1 Garbage collection</H3>
<p>If the owner flag passed to <code>SWIG_NewPointerObj</code> is 1, <code>NewPointerObj</code> will add a
@ -550,7 +550,7 @@ all the modules.</p>
must be called manually.
</p>
<H2><a name="Chicken_nn18"></a>20.7 Unsupported features and known problems</H2>
<H2><a name="Chicken_nn18"></a>21.7 Unsupported features and known problems</H2>
<ul>
@ -560,7 +560,7 @@ all the modules.</p>
<a href="SWIGPlus.html#SWIGPlus_default_args">%feature(compactdefaultargs)</a>.</li>
</ul>
<H3><a name="Chicken_nn19"></a>20.7.1 TinyCLOS problems with Chicken version &lt;= 1.92</H3>
<H3><a name="Chicken_nn19"></a>21.7.1 TinyCLOS problems with Chicken version &lt;= 1.92</H3>
<p>In Chicken versions equal to or below 1.92, TinyCLOS has a limitation such that generic methods do not properly work on methods

View file

@ -16,13 +16,23 @@
<ul>
<li><a href="Preface.html#Preface_nn2">Introduction</a>
<li><a href="Preface.html#Preface_nn4">SWIG Versions</a>
<li><a href="Preface.html#Preface_license">SWIG License</a>
<li><a href="Preface.html#Preface_nn5">SWIG resources</a>
<li><a href="Preface.html#Preface_nn6">Prerequisites</a>
<li><a href="Preface.html#Preface_nn7">Organization of this manual</a>
<li><a href="Preface.html#Preface_nn8">How to avoid reading the manual</a>
<li><a href="Preface.html#Preface_nn9">Backwards compatibility</a>
<li><a href="Preface.html#Preface_release_notes">Release notes</a>
<li><a href="Preface.html#Preface_nn10">Credits</a>
<li><a href="Preface.html#Preface_nn11">Bug reports</a>
<li><a href="Preface.html#Preface_installation">Installation</a>
<ul>
<li><a href="Preface.html#Preface_windows_installation">Windows installation</a>
<li><a href="Preface.html#Preface_unix_installation">Unix installation</a>
<li><a href="Preface.html#Preface_osx_installation">Macintosh OS X installation</a>
<li><a href="Preface.html#Preface_testing">Testing</a>
<li><a href="Preface.html#Preface_examples">Examples</a>
</ul>
</ul>
</div>
<!-- INDEX -->
@ -252,7 +262,61 @@
</div>
<!-- INDEX -->
<h3><a href="Preprocessor.html#Preprocessor">7 Preprocessing</a></h3>
<h3><a href="CPlusPlus11.html#CPlusPlus11">7 SWIG and C++11</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
<li><a href="CPlusPlus11.html#CPlusPlus11_introduction">Introduction</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_core_language_changes">Core language changes</a>
<ul>
<li><a href="CPlusPlus11.html#CPlusPlus11_rvalue_reference_and_move_semantics">Rvalue reference and move semantics</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_generalized_constant_expressions">Generalized constant expressions</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_extern_template">Extern template</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_initializer_lists">Initializer lists</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_uniform_initialization">Uniform initialization</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_type_inference">Type inference</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_range_based_for_loop">Range-based for-loop</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_lambda_functions_and_expressions">Lambda functions and expressions</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_alternate_function_syntax">Alternate function syntax</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_object_construction_improvement">Object construction improvement</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_explicit_overrides_final">Explicit overrides and final</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_null_pointer_constant">Null pointer constant</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_strongly_typed_enumerations">Strongly typed enumerations</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_double_angle_brackets">Double angle brackets</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_explicit_conversion_operators">Explicit conversion operators</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_alias_templates">Alias templates</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_unrestricted_unions">Unrestricted unions</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_variadic_templates">Variadic templates</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_new_string_literals">New string literals</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_user_defined_literals">User-defined literals</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_thread_local_storage">Thread-local storage</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_defaulted_deleted">Explicitly defaulted functions and deleted functions</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_type_long_long_int">Type long long int</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_static_assertions">Static assertions</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_sizeof">Allow sizeof to work on members of classes without an explicit object</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_noexcept">Exception specifications and noexcept</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_alignment">Control and query object alignment</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_attributes">Attributes</a>
</ul>
<li><a href="CPlusPlus11.html#CPlusPlus11_standard_library_changes">Standard library changes</a>
<ul>
<li><a href="CPlusPlus11.html#CPlusPlus11_threading_facilities">Threading facilities</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_tuple_types">Tuple types</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_hash_tables">Hash tables</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_regular_expressions">Regular expressions</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_general_purpose_smart_pointers">General-purpose smart pointers</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_extensible_random_number_facility">Extensible random number facility</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_wrapper_reference">Wrapper reference</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_polymorphous_wrappers_for_function_objects">Polymorphous wrappers for function objects</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_type_traits_for_metaprogramming">Type traits for metaprogramming</a>
<li><a href="CPlusPlus11.html#CPlusPlus11_uniform_method_for_computing_return_type_of_function_objects">Uniform method for computing return type of function objects</a>
</ul>
</ul>
</div>
<!-- INDEX -->
<h3><a href="Preprocessor.html#Preprocessor">8 Preprocessing</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -275,7 +339,7 @@
</div>
<!-- INDEX -->
<h3><a href="Library.html#Library">8 SWIG library</a></h3>
<h3><a href="Library.html#Library">9 SWIG library</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -301,6 +365,7 @@
<li><a href="Library.html#Library_std_vector">std::vector</a>
<li><a href="Library.html#Library_stl_exceptions">STL exceptions</a>
<li><a href="Library.html#Library_std_shared_ptr">shared_ptr smart pointer</a>
<li><a href="Library.html#Library_std_auto_ptr">auto_ptr smart pointer</a>
</ul>
<li><a href="Library.html#Library_nn16">Utility Libraries</a>
<ul>
@ -310,7 +375,7 @@
</div>
<!-- INDEX -->
<h3><a href="Arguments.html#Arguments">9 Argument Handling</a></h3>
<h3><a href="Arguments.html#Arguments">10 Argument Handling</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -333,7 +398,7 @@
</div>
<!-- INDEX -->
<h3><a href="Typemaps.html#Typemaps">10 Typemaps</a></h3>
<h3><a href="Typemaps.html#Typemaps">11 Typemaps</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -421,7 +486,7 @@
</div>
<!-- INDEX -->
<h3><a href="Customization.html#Customization">11 Customization Features</a></h3>
<h3><a href="Customization.html#Customization">12 Customization Features</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -449,7 +514,7 @@
</div>
<!-- INDEX -->
<h3><a href="Contract.html#Contract">12 Contracts</a></h3>
<h3><a href="Contract.html#Contract">13 Contracts</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -462,7 +527,7 @@
</div>
<!-- INDEX -->
<h3><a href="Varargs.html#Varargs">13 Variable Length Arguments</a></h3>
<h3><a href="Varargs.html#Varargs">14 Variable Length Arguments</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -480,7 +545,7 @@
</div>
<!-- INDEX -->
<h3><a href="Warnings.html#Warnings">14 Warning Messages</a></h3>
<h3><a href="Warnings.html#Warnings">15 Warning Messages</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -508,7 +573,7 @@
</div>
<!-- INDEX -->
<h3><a href="Modules.html#Modules">15 Working with Modules</a></h3>
<h3><a href="Modules.html#Modules">16 Working with Modules</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -524,7 +589,33 @@
</div>
<!-- INDEX -->
<h3><a href="Allegrocl.html#Allegrocl">17 SWIG and Allegro Common Lisp</a></h3>
<h3><a href="CCache.html#CCache">17 Using SWIG with ccache - ccache-swig(1) manpage</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
<li><a href="CCache.html#CCache_nn2">NAME</a>
<li><a href="CCache.html#CCache_nn3">SYNOPSIS</a>
<li><a href="CCache.html#CCache_nn4">DESCRIPTION</a>
<li><a href="CCache.html#CCache_nn5">OPTIONS SUMMARY</a>
<li><a href="CCache.html#CCache_nn6">OPTIONS</a>
<li><a href="CCache.html#CCache_nn7">INSTALLATION</a>
<li><a href="CCache.html#CCache_nn8">EXTRA OPTIONS</a>
<li><a href="CCache.html#CCache_nn9">ENVIRONMENT VARIABLES</a>
<li><a href="CCache.html#CCache_nn10">CACHE SIZE MANAGEMENT</a>
<li><a href="CCache.html#CCache_nn11">CACHE COMPRESSION</a>
<li><a href="CCache.html#CCache_nn12">HOW IT WORKS</a>
<li><a href="CCache.html#CCache_nn13">USING CCACHE WITH DISTCC</a>
<li><a href="CCache.html#CCache_nn14">SHARING A CACHE</a>
<li><a href="CCache.html#CCache_nn15">HISTORY</a>
<li><a href="CCache.html#CCache_nn16">DIFFERENCES FROM COMPILERCACHE</a>
<li><a href="CCache.html#CCache_nn17">CREDITS</a>
<li><a href="CCache.html#CCache_nn18">AUTHOR</a>
</ul>
</div>
<!-- INDEX -->
<h3><a href="Allegrocl.html#Allegrocl">18 SWIG and Allegro Common Lisp</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -608,7 +699,7 @@
</div>
<!-- INDEX -->
<h3><a href="Android.html#Android">18 SWIG and Android</a></h3>
<h3><a href="Android.html#Android">19 SWIG and Android</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -619,17 +710,22 @@
<li><a href="Android.html#Android_examples_intro">Examples introduction</a>
<li><a href="Android.html#Android_example_simple">Simple C example</a>
<li><a href="Android.html#Android_example_class">C++ class example</a>
<li><a href="Android.html#Android_examples_other">Other examples</a>
</ul>
<li><a href="Android.html#Android_stl">C++ STL</a>
</ul>
</div>
<!-- INDEX -->
<h3><a href="CSharp.html#CSharp">19 SWIG and C#</a></h3>
<h3><a href="CSharp.html#CSharp">20 SWIG and C#</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
<li><a href="CSharp.html#CSharp_introduction">Introduction</a>
<ul>
<li><a href="CSharp.html#CSharp_introduction_swig2_compatibility">SWIG 2 Compatibility</a>
</ul>
<li><a href="CSharp.html#CSharp_differences_java">Differences to the Java module</a>
<li><a href="CSharp.html#CSharp_void_pointers">Void pointers</a>
<li><a href="CSharp.html#CSharp_arrays">C# Arrays</a>
@ -658,6 +754,7 @@
<li><a href="CSharp.html#CSharp_memory_management_objects">Memory management for objects passed to the C++ layer</a>
<li><a href="CSharp.html#CSharp_date_marshalling">Date marshalling using the csin typemap and associated attributes</a>
<li><a href="CSharp.html#CSharp_date_properties">A date example demonstrating marshalling of C# properties</a>
<li><a href="CSharp.html#CSharp_date_pre_post_directors">Date example demonstrating the 'pre' and 'post' typemap attributes for directors</a>
<li><a href="CSharp.html#CSharp_partial_classes">Turning wrapped classes into partial classes</a>
<li><a href="CSharp.html#CSharp_extending_proxy_class">Extending proxy classes with additional C# code</a>
<li><a href="CSharp.html#CSharp_enum_underlying_type">Underlying type for enums</a>
@ -666,7 +763,7 @@
</div>
<!-- INDEX -->
<h3><a href="Chicken.html#Chicken">20 SWIG and Chicken</a></h3>
<h3><a href="Chicken.html#Chicken">21 SWIG and Chicken</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -704,7 +801,7 @@
</div>
<!-- INDEX -->
<h3><a href="D.html#D">21 SWIG and D</a></h3>
<h3><a href="D.html#D">22 SWIG and D</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -738,7 +835,7 @@
</div>
<!-- INDEX -->
<h3><a href="Go.html#Go">22 SWIG and Go</a></h3>
<h3><a href="Go.html#Go">23 SWIG and Go</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -769,13 +866,14 @@
</div>
<!-- INDEX -->
<h3><a href="Guile.html#Guile">23 SWIG and Guile</a></h3>
<h3><a href="Guile.html#Guile">24 SWIG and Guile</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
<li><a href="Guile.html#Guile_nn1">Supported Guile Versions</a>
<li><a href="Guile.html#Guile_nn2">Meaning of "Module"</a>
<li><a href="Guile.html#Guile_nn3">Using the SCM or GH Guile API</a>
<li><a href="Guile.html#Guile_nn3">Old GH Guile API</a>
<li><a href="Guile.html#Guile_nn4">Linkage</a>
<ul>
<li><a href="Guile.html#Guile_nn5">Simple Linkage</a>
@ -788,8 +886,7 @@
<li><a href="Guile.html#Guile_nn11">Typemaps</a>
<li><a href="Guile.html#Guile_nn12">Representation of pointers as smobs</a>
<ul>
<li><a href="Guile.html#Guile_nn13">GH Smobs</a>
<li><a href="Guile.html#Guile_nn14">SCM Smobs</a>
<li><a href="Guile.html#Guile_nn14">Smobs</a>
<li><a href="Guile.html#Guile_nn15">Garbage Collection</a>
</ul>
<li><a href="Guile.html#Guile_nn16">Exception Handling</a>
@ -804,7 +901,7 @@
</div>
<!-- INDEX -->
<h3><a href="Java.html#Java">24 SWIG and Java</a></h3>
<h3><a href="Java.html#Java">25 SWIG and Java</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -886,6 +983,8 @@
<li><a href="Java.html#Java_directors_overhead">Overhead and code bloat</a>
<li><a href="Java.html#Java_directors_example">Simple directors example</a>
<li><a href="Java.html#Java_directors_threading">Director threading issues</a>
<li><a href="Java.html#Java_directors_performance">Director performance tuning</a>
<li><a href="Java.html#Java_exceptions_from_directors">Java exceptions from directors</a>
</ul>
<li><a href="Java.html#Java_allprotected">Accessing protected members</a>
<li><a href="Java.html#Java_common_customization">Common customization features</a>
@ -947,7 +1046,7 @@
</div>
<!-- INDEX -->
<h3><a href="Lisp.html#Lisp">25 SWIG and Common Lisp</a></h3>
<h3><a href="Lisp.html#Lisp">26 SWIG and Common Lisp</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -970,7 +1069,7 @@
</div>
<!-- INDEX -->
<h3><a href="Lua.html#Lua">26 SWIG and Lua</a></h3>
<h3><a href="Lua.html#Lua">27 SWIG and Lua</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -989,8 +1088,11 @@
<li><a href="Lua.html#Lua_nn9">Functions</a>
<li><a href="Lua.html#Lua_nn10">Global variables</a>
<li><a href="Lua.html#Lua_nn11">Constants and enums</a>
<ul>
<li><a href="Lua.html#Lua_nn13">Constants/enums and classes/structures</a>
</ul>
<li><a href="Lua.html#Lua_nn12">Pointers</a>
<li><a href="Lua.html#Lua_nn13">Structures</a>
<li><a href="Lua.html#Lua_structures">Structures</a>
<li><a href="Lua.html#Lua_nn14">C++ classes</a>
<li><a href="Lua.html#Lua_nn15">C++ inheritance</a>
<li><a href="Lua.html#Lua_nn16">Pointers, references, values, and arrays</a>
@ -1001,17 +1103,23 @@
<li><a href="Lua.html#Lua_nn21">C++ templates</a>
<li><a href="Lua.html#Lua_nn22">C++ Smart Pointers</a>
<li><a href="Lua.html#Lua_nn23">C++ Exceptions</a>
<li><a href="Lua.html#Lua_namespaces">Namespaces </a>
<ul>
<li><a href="Lua.html#Lua_nn27">Compatibility Note </a>
<li><a href="Lua.html#Lua_nn29">Names </a>
<li><a href="Lua.html#Lua_nn30">Inheritance </a>
</ul>
</ul>
<li><a href="Lua.html#Lua_nn24">Typemaps</a>
<ul>
<li><a href="Lua.html#Lua_nn25">What is a typemap?</a>
<li><a href="Lua.html#Lua_nn26">Using typemaps</a>
<li><a href="Lua.html#Lua_nn27">Typemaps and arrays</a>
<li><a href="Lua.html#Lua_nn28">Typemaps and pointer-pointer functions</a>
<li><a href="Lua.html#Lua_typemap_arrays">Typemaps and arrays</a>
<li><a href="Lua.html#Lua_typemaps_ptr_ptr_functions">Typemaps and pointer-pointer functions</a>
</ul>
<li><a href="Lua.html#Lua_nn29">Writing typemaps</a>
<li><a href="Lua.html#Lua_writing_typemaps">Writing typemaps</a>
<ul>
<li><a href="Lua.html#Lua_nn30">Typemaps you can write</a>
<li><a href="Lua.html#Lua_typemaps_write">Typemaps you can write</a>
<li><a href="Lua.html#Lua_nn31">SWIG's Lua-C API</a>
</ul>
<li><a href="Lua.html#Lua_nn32">Customization of your Bindings</a>
@ -1029,7 +1137,7 @@
</div>
<!-- INDEX -->
<h3><a href="Modula3.html#Modula3">27 SWIG and Modula-3</a></h3>
<h3><a href="Modula3.html#Modula3">28 SWIG and Modula-3</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -1067,7 +1175,7 @@
</div>
<!-- INDEX -->
<h3><a href="Mzscheme.html#Mzscheme">28 SWIG and MzScheme/Racket</a></h3>
<h3><a href="Mzscheme.html#Mzscheme">29 SWIG and MzScheme/Racket</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -1079,7 +1187,7 @@
</div>
<!-- INDEX -->
<h3><a href="Ocaml.html#Ocaml">29 SWIG and Ocaml</a></h3>
<h3><a href="Ocaml.html#Ocaml">30 SWIG and Ocaml</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -1130,7 +1238,7 @@
</div>
<!-- INDEX -->
<h3><a href="Octave.html#Octave">30 SWIG and Octave</a></h3>
<h3><a href="Octave.html#Octave">31 SWIG and Octave</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -1166,7 +1274,7 @@
</div>
<!-- INDEX -->
<h3><a href="Perl5.html#Perl5">31 SWIG and Perl5</a></h3>
<h3><a href="Perl5.html#Perl5">32 SWIG and Perl5</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -1229,11 +1337,20 @@
<li><a href="Perl5.html#Perl5_nn46">Modifying the proxy methods</a>
</ul>
<li><a href="Perl5.html#Perl5_nn47">Adding additional Perl code</a>
<li><a href="Perl5.html#Perl5_directors">Cross language polymorphism</a>
<ul>
<li><a href="Perl5.html#Perl5_nn48">Enabling directors</a>
<li><a href="Perl5.html#Perl5_nn49">Director classes</a>
<li><a href="Perl5.html#Perl5_nn50">Ownership and object destruction</a>
<li><a href="Perl5.html#Perl5_nn51">Exception unrolling</a>
<li><a href="Perl5.html#Perl5_nn52">Overhead and code bloat</a>
<li><a href="Perl5.html#Perl5_nn53">Typemaps</a>
</ul>
</ul>
</div>
<!-- INDEX -->
<h3><a href="Php.html#Php">32 SWIG and PHP</a></h3>
<h3><a href="Php.html#Php">33 SWIG and PHP</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -1273,7 +1390,7 @@
</div>
<!-- INDEX -->
<h3><a href="Pike.html#Pike">33 SWIG and Pike</a></h3>
<h3><a href="Pike.html#Pike">34 SWIG and Pike</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -1297,7 +1414,7 @@
</div>
<!-- INDEX -->
<h3><a href="Python.html#Python">34 SWIG and Python</a></h3>
<h3><a href="Python.html#Python">35 SWIG and Python</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -1397,6 +1514,12 @@
<li><a href="Python.html#Python_nn71">%feature("docstring")</a>
</ul>
<li><a href="Python.html#Python_nn72">Python Packages</a>
<ul>
<li><a href="Python.html#Python_modulepackage">Setting the Python package</a>
<li><a href="Python.html#Python_absrelimports">Absolute and relative imports</a>
<li><a href="Python.html#Python_absimport">Enforcing absolute import semantics</a>
<li><a href="Python.html#Python_importfrominit">Importing from __init__.py</a>
</ul>
<li><a href="Python.html#Python_python3support">Python 3 Support</a>
<ul>
<li><a href="Python.html#Python_nn74">Function annotation</a>
@ -1407,7 +1530,7 @@
</div>
<!-- INDEX -->
<h3><a href="R.html#R">35 SWIG and R</a></h3>
<h3><a href="R.html#R">36 SWIG and R</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -1423,7 +1546,7 @@
</div>
<!-- INDEX -->
<h3><a href="Ruby.html#Ruby">36 SWIG and Ruby</a></h3>
<h3><a href="Ruby.html#Ruby">37 SWIG and Ruby</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -1488,9 +1611,9 @@
<li><a href="Ruby.html#Ruby_Placement_of_typemaps">Placement of typemaps</a>
<li><a href="Ruby.html#Ruby_nn39">Ruby typemaps</a>
<ul>
<li><a href="Ruby.html#Ruby_in_typemap">&nbsp;"in" typemap</a>
<li><a href="Ruby.html#Ruby_in_typemap">"in" typemap</a>
<li><a href="Ruby.html#Ruby_typecheck_typemap">"typecheck" typemap</a>
<li><a href="Ruby.html#Ruby_out_typemap">&nbsp;"out" typemap</a>
<li><a href="Ruby.html#Ruby_out_typemap">"out" typemap</a>
<li><a href="Ruby.html#Ruby_arginit_typemap">"arginit" typemap</a>
<li><a href="Ruby.html#Ruby_default_typemap">"default" typemap</a>
<li><a href="Ruby.html#Ruby_check_typemap">"check" typemap</a>
@ -1557,7 +1680,7 @@
</div>
<!-- INDEX -->
<h3><a href="Tcl.html#Tcl">37 SWIG and Tcl</a></h3>
<h3><a href="Tcl.html#Tcl">38 SWIG and Tcl</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -1623,7 +1746,7 @@
</div>
<!-- INDEX -->
<h3><a href="Extending.html#Extending">38 Extending SWIG to support new languages</a></h3>
<h3><a href="Extending.html#Extending">39 Extending SWIG to support new languages</a></h3>
<!-- INDEX -->
<div class="sectiontoc">
@ -1691,7 +1814,7 @@
</div>
<!-- INDEX -->
<h3><a href="Doxygen.html#Doxygen">39 SWIG and Doxygen Translation</a></h3>
<h3><a href="Doxygen.html#Doxygen">40 SWIG and Doxygen Translation</a></h3>
<!-- INDEX -->
<div class="sectiontoc">

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Contract"></a>12 Contracts</H1>
<H1><a name="Contract"></a>13 Contracts</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -38,7 +38,7 @@ When one of the rules is violated by a script, a runtime exception is
generated rather than having the program continue to execute.
</p>
<H2><a name="Contract_nn2"></a>12.1 The %contract directive</H2>
<H2><a name="Contract_nn2"></a>13.1 The %contract directive</H2>
<p>
@ -94,7 +94,7 @@ RuntimeError: Contract violation: require: (arg1&gt;=0)
</pre>
</div>
<H2><a name="Contract_nn3"></a>12.2 %contract and classes</H2>
<H2><a name="Contract_nn3"></a>13.2 %contract and classes</H2>
<p>
@ -173,7 +173,7 @@ specified for the derived class all must hold. In the above example,
this means that both the arguments to <tt>Spam::bar</tt> must be positive.
</p>
<H2><a name="Contract_nn4"></a>12.3 Constant aggregation and %aggregate_check</H2>
<H2><a name="Contract_nn4"></a>13.3 Constant aggregation and %aggregate_check</H2>
<p>
@ -262,7 +262,7 @@ Regrettably, there is no automatic way to perform similar checks with enums valu
release.
</p>
<H2><a name="Contract_nn5"></a>12.4 Notes</H2>
<H2><a name="Contract_nn5"></a>13.4 Notes</H2>
<p>

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Customization"></a>11 Customization Features</H1>
<H1><a name="Customization"></a>12 Customization Features</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -45,7 +45,7 @@ of exception handling is presented. Then, a more general-purpose
customization mechanism known as "features" is described.
</p>
<H2><a name="Customization_exception"></a>11.1 Exception handling with %exception</H2>
<H2><a name="Customization_exception"></a>12.1 Exception handling with %exception</H2>
<p>
@ -100,7 +100,7 @@ for exception handling. That directive is deprecated--<tt>%exception</tt>
provides the same functionality, but is substantially more flexible.
</p>
<H3><a name="Customization_nn3"></a>11.1.1 Handling exceptions in C code</H3>
<H3><a name="Customization_nn3"></a>12.1.1 Handling exceptions in C code</H3>
<p>
@ -166,7 +166,7 @@ Each target language has its own approach to creating a runtime error/exception
and for Perl it is the <tt>croak</tt> method shown above.
</p>
<H3><a name="Customization_nn4"></a>11.1.2 Exception handling with longjmp()</H3>
<H3><a name="Customization_nn4"></a>12.1.2 Exception handling with longjmp()</H3>
<p>
@ -240,7 +240,7 @@ Note: This implementation is only intended to illustrate the general idea. To m
modify it to handle nested <tt>try</tt> declarations.
</p>
<H3><a name="Customization_nn5"></a>11.1.3 Handling C++ exceptions</H3>
<H3><a name="Customization_nn5"></a>12.1.3 Handling C++ exceptions</H3>
<p>
@ -275,7 +275,7 @@ class OutOfMemory {};
</pre>
</div>
<H3><a name="Customization_allowexcept"></a>11.1.4 Exception handlers for variables</H3>
<H3><a name="Customization_allowexcept"></a>12.1.4 Exception handlers for variables</H3>
<p>
@ -300,7 +300,7 @@ The <tt>%allowexception</tt> feature works like any other feature and so can be
</pre>
</div>
<H3><a name="Customization_nn6"></a>11.1.5 Defining different exception handlers</H3>
<H3><a name="Customization_nn6"></a>12.1.5 Defining different exception handlers</H3>
<p>
@ -437,7 +437,7 @@ declarations. However, it never really worked that well and the new
%exception directive is much better.
</p>
<H3><a name="Customization_exception_special_variables"></a>11.1.6 Special variables for %exception</H3>
<H3><a name="Customization_exception_special_variables"></a>12.1.6 Special variables for %exception</H3>
<p>
@ -454,6 +454,11 @@ variables are replaced with.
<td>The actual operation to be performed (a function call, method invocation, variable access, etc.)</td>
</tr>
<tr>
<td>$name</td>
<td>The C/C++ symbol name for the function.</td>
</tr>
<tr>
<td>$symname</td>
<td>The symbol name used internally by SWIG</td>
@ -479,6 +484,16 @@ variables are replaced with.
<td>The fully qualified C/C++ declaration of the method being wrapped including the return type</td>
</tr>
<tr>
<td>$parentname</td>
<td>The parent class name (if any) for a method.</td>
</tr>
<tr>
<td>$parentsymname</td>
<td>The target language parent class name (if any) for a method.</td>
</tr>
</table>
<p>
@ -525,7 +540,7 @@ Below shows the expansions for the 1st of the overloaded <tt>something</tt> wrap
</pre></div>
<H3><a name="Customization_nn7"></a>11.1.7 Using The SWIG exception library</H3>
<H3><a name="Customization_nn7"></a>12.1.7 Using The SWIG exception library</H3>
<p>
@ -577,12 +592,10 @@ SWIG_NullReferenceError
</pre></div>
<p>
Since the <tt>SWIG_exception()</tt> function is defined at the C-level
it can be used elsewhere in SWIG. This includes typemaps and helper
functions.
The <tt>SWIG_exception()</tt> function can also be used in typemaps.
</p>
<H2><a name="Customization_ownership"></a>11.2 Object ownership and %newobject</H2>
<H2><a name="Customization_ownership"></a>12.2 Object ownership and %newobject</H2>
<p>
@ -739,7 +752,7 @@ char *strdup(const char *s);
The results might not be what you expect.
</p>
<H2><a name="Customization_features"></a>11.3 Features and the %feature directive</H2>
<H2><a name="Customization_features"></a>12.3 Features and the %feature directive</H2>
<p>
@ -821,7 +834,7 @@ The following are all equivalent:
The syntax in the first variation will generate the <tt>{ }</tt> delimiters used whereas the other variations will not.
</p>
<H3><a name="Customization_feature_attributes"></a>11.3.1 Feature attributes</H3>
<H3><a name="Customization_feature_attributes"></a>12.3.1 Feature attributes</H3>
<p>
@ -862,7 +875,7 @@ In the following example, <tt>MyExceptionClass</tt> is the name of the Java clas
Further details can be obtained from the <a href="Java.html#Java_exception_handling">Java exception handling</a> section.
</p>
<H3><a name="Customization_feature_flags"></a>11.3.2 Feature flags</H3>
<H3><a name="Customization_feature_flags"></a>12.3.2 Feature flags</H3>
<p>
@ -960,7 +973,7 @@ in the <tt>swig.swg</tt> Library file. The following shows the alternative synta
The concept of clearing features is discussed next.
</p>
<H3><a name="Customization_clearing_features"></a>11.3.3 Clearing features</H3>
<H3><a name="Customization_clearing_features"></a>12.3.3 Clearing features</H3>
<p>
@ -1053,7 +1066,7 @@ The three macros below show this for the "except" feature:
</pre>
</div>
<H3><a name="Customization_features_default_args"></a>11.3.4 Features and default arguments</H3>
<H3><a name="Customization_features_default_args"></a>12.3.4 Features and default arguments</H3>
<p>
@ -1128,7 +1141,7 @@ specifying or not specifying default arguments in a feature is not applicable as
in SWIG-1.3.23 when the approach to wrapping methods with default arguments was changed.
</p>
<H3><a name="Customization_features_example"></a>11.3.5 Feature example</H3>
<H3><a name="Customization_features_example"></a>12.3.5 Feature example</H3>
<p>

View file

@ -6,7 +6,7 @@
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#FFFFFF">
<H1><a name="D"></a>21 SWIG and D</H1>
<H1><a name="D"></a>22 SWIG and D</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -41,7 +41,7 @@
<H2><a name="D_introduction"></a>21.1 Introduction</H2>
<H2><a name="D_introduction"></a>22.1 Introduction</H2>
<p>From the <a href="http://www.digitalmars.com/d/">D Programming Language</a> web site: <em>D is a systems programming language. Its focus is on combining the power and high performance of C and C++ with the programmer productivity of modern languages like Ruby and Python. [...] The D language is statically typed and compiles directly to machine code.</em> As such, it is not very surprising that D is able to directly <a href="http://www.digitalmars.com/d/1.0/interfaceToC.html">interface with C libraries</a>. Why would a SWIG module for D be needed then in the first place?</p>
@ -53,7 +53,7 @@
<p>To help addressing these issues, the SWIG C# module has been forked to support D. Is has evolved quite a lot since then, but there are still many similarities, so if you do not find what you are looking for on this page, it might be worth having a look at the chapter on <a href="CSharp.html">C#</a> (and also on <a href="Java.html">Java</a>, since the C# module was in turn forked from it).</p>
<H2><a name="D_command_line_invocation"></a>21.2 Command line invocation</H2>
<H2><a name="D_command_line_invocation"></a>22.2 Command line invocation</H2>
<p>To activate the D module, pass the <tt>-d</tt> option to SWIG at the command line. The same standard command line switches as with any other language module are available, plus the following D specific ones:</p>
@ -83,10 +83,10 @@
</dl>
<H2><a name="D_typemaps"></a>21.3 Typemaps</H2>
<H2><a name="D_typemaps"></a>22.3 Typemaps</H2>
<H3><a name="D_typemap_name_comparison"></a>21.3.1 C# &lt;-&gt; D name comparison</H3>
<H3><a name="D_typemap_name_comparison"></a>22.3.1 C# &lt;-&gt; D name comparison</H3>
<p>If you already know the SWIG C# module, you might find the following name comparison table useful:</p>
@ -112,7 +112,7 @@
</pre></div>
<H3><a name="D_ctype_imtype_dtype"></a>21.3.2 ctype, imtype, dtype</H3>
<H3><a name="D_ctype_imtype_dtype"></a>22.3.2 ctype, imtype, dtype</H3>
<p>Mapping of types between the C/C++ library, the C/C++ library wrapper exposing the C functions, the D wrapper module importing these functions and the D proxy code.</p>
@ -120,7 +120,7 @@
<p>The <tt>ctype</tt> typemap is used to determine the types to use in the C wrapper functions. The types from the <tt>imtype</tt> typemap are used in the extern(C) declarations of these functions in the intermediary D module. The <tt>dtype</tt> typemap contains the D types used in the D proxy module/class.</p>
<H3><a name="D_in_out_directorin_direcetorout"></a>21.3.3 in, out, directorin, directorout</H3>
<H3><a name="D_in_out_directorin_direcetorout"></a>22.3.3 in, out, directorin, directorout</H3>
<p>Used for converting between the types for C/C++ and D when generating the code for the wrapper functions (on the C++ side).</p>
@ -130,7 +130,7 @@
<p>The <tt>directorin</tt> typemap is used to convert parameters to the type used in the D director callback function, its return value is processed by <tt>directorout</tt> (see below).</p>
<H3><a name="D_din_dout_ddirectorin_ddirectorout"></a>21.3.4 din, dout, ddirectorin, ddirectorout</H3>
<H3><a name="D_din_dout_ddirectorin_ddirectorout"></a>22.3.4 din, dout, ddirectorin, ddirectorout</H3>
<p>Typemaps for code generation in D proxy and type wrapper classes.</p>
@ -157,13 +157,13 @@
dtype DClass.method(dtype a)</pre></div>
<H3><a name="D_typecheck_typemaps"></a>21.3.5 typecheck typemaps</H3>
<H3><a name="D_typecheck_typemaps"></a>22.3.5 typecheck typemaps</H3>
<p>Because, unlike many scripting languages supported by SWIG, D does not need any dynamic dispatch helper to access an overloaded function, the purpose of these is merely to issue a warning for overloaded C++ functions that cannot be overloaded in D (as more than one C++ type maps to a single D type).</p>
<H3><a name="D_code_injection_typemaps"></a>21.3.6 Code injection typemaps</H3>
<H3><a name="D_code_injection_typemaps"></a>22.3.6 Code injection typemaps</H3>
<p>These typemaps are used for generating the skeleton of proxy classes for C++ types.</p>
@ -175,7 +175,7 @@
<p id="D_class_code_typemaps"><tt>dconstructor</tt>, <tt>ddestructor</tt>, <tt>ddispose</tt> and <tt>ddispose_derived</tt> are used to generate the class constructor, destructor and <tt>dispose()</tt> method, respectively. The auxiliary code for handling the pointer to the C++ object is stored in <tt>dbody</tt> and <tt>dbody_derived</tt>. You can override them for specific types.</p>
<H3><a name="D_special_variables"></a>21.3.7 Special variable macros</H3>
<H3><a name="D_special_variables"></a>22.3.7 Special variable macros</H3>
<p>The standard SWIG special variables are available for use within typemaps as described in the <a href="Typemaps.html#Typemaps">Typemaps documentation</a>, for example <tt>$1</tt>, <tt>$input</tt>, <tt>$result</tt> etc.</p>
@ -295,7 +295,7 @@ $importtype(AnotherInterface)
</dl>
<H2><a name="D_features"></a>21.4 <tt>%feature</tt>s</H2>
<H2><a name="D_features"></a>22.4 <tt>%feature</tt>s</H2>
<p>The D module defines a number of directives which modify the <a href="Customization.html#Customization_features">SWIG features</a> set globally or for a specific declaration:</p>
@ -325,7 +325,7 @@ struct A {
</dl>
<H2><a name="D_pragmas"></a>21.5 Pragmas</H2>
<H2><a name="D_pragmas"></a>22.5 Pragmas</H2>
<p>There are a few SWIG pragmas specific to the D module, which you can use to influence the D code SWIG generates:</p>
@ -364,7 +364,7 @@ struct A {
</dl>
<H2><a name="D_exceptions"></a>21.6 D Exceptions</H2>
<H2><a name="D_exceptions"></a>22.6 D Exceptions</H2>
<p>Out of the box, C++ exceptions are fundamentally incompatible to their equivalent in the D world and cannot simply be propagated to a calling D method. There is, however, an easy way to solve this problem: Just catch the exception in the C/C++ wrapper layer, pass the contents to D, and make the wrapper code rethrow the exception in the D world.</p>
@ -374,7 +374,7 @@ struct A {
<p>As this feature is implemented in exactly the same way it is for C#, please see the <a href="CSharp.html#CSharp_exceptions">C# documentation</a> for a more detailed explanation.</p>
<H2><a name="D_directors"></a>21.7 D Directors</H2>
<H2><a name="D_directors"></a>22.7 D Directors</H2>
<p>When the directors feature is activated, SWIG generates extra code on both the C++ and the D side to enable cross-language polymorphism. Essentially, this means that if you subclass a proxy class in D, C++ code can access any overridden virtual methods just as if you created a derived class in C++.</p>
@ -383,16 +383,16 @@ struct A {
</p>
<H2><a name="D_other_features"></a>21.8 Other features</H2>
<H2><a name="D_other_features"></a>22.8 Other features</H2>
<H3><a name="D_nspace"></a>21.8.1 Extended namespace support (<tt>nspace</tt>)</H3>
<H3><a name="D_nspace"></a>22.8.1 Extended namespace support (<tt>nspace</tt>)</H3>
<p>By default, SWIG flattens all C++ namespaces into a single target language namespace, but as for Java and C#, the <a href="SWIGPlus.html#SWIGPlus_nspace"><tt>nspace</tt></a> feature is supported for D. If it is active, C++ namespaces are mapped to D packages/modules. Note, however, that like for the other languages, <em>free</em> variables and functions are not supported yet; currently, they are all allows written to the main proxy D module.</p>
<H3><a name="D_native_pointer_support"></a>21.8.2 Native pointer support</H3>
<H3><a name="D_native_pointer_support"></a>22.8.2 Native pointer support</H3>
<p>Contrary to many of the scripting languages supported by SWIG, D fully supports C-style pointers. The D module thus includes a custom mechanism to wrap C pointers directly as D pointers where applicable, that is, if the type that is pointed to is represented the same in C and D (on the bit-level), dubbed a <em>primitive type</em> below.</p>
@ -404,7 +404,7 @@ struct A {
<p>To determine if a type should be considered primitive, the <tt>cprimitive</tt> attribute on its <tt>dtype</tt> attribute is used. For example, the <tt>dtype</tt> typemap for <tt>float</tt> has <tt>cprimitive="1"</tt>, so the code from the <tt>nativepointer</tt> attribute is taken into account e.g. for <tt>float **</tt> or the function pointer <tt>float (*)(float *)</tt>.</p>
<H3><a name="D_operator_overloading"></a>21.8.3 Operator overloading</H3>
<H3><a name="D_operator_overloading"></a>22.8.3 Operator overloading</H3>
<p>The D module comes with basic operator overloading support for both D1 and D2. There are, however, a few limitations arising from conceptual differences between C++ and D:</p>
@ -416,7 +416,7 @@ struct A {
<p>There are also some cases where the operators can be translated to D, but the differences in the implementation details are big enough that a rather involved scheme would be required for automatic wrapping them, which has not been implemented yet. This affects, for example, the array subscript operator, <tt>[]</tt>, in combination with assignments - while <tt>operator []</tt> in C++ simply returns a reference which is then written to, D resorts to a separate <tt>opIndexAssign</tt> method -, or implicit casting (which was introduced in D2 via <tt>alias this</tt>). Despite the lack of automatic support, manually handling these cases should be perfectly possible.</p>
<H3><a name="D_test_suite"></a>21.8.4 Running the test-suite</H3>
<H3><a name="D_test_suite"></a>22.8.4 Running the test-suite</H3>
<p>As with any other language, the SWIG test-suite can be built for D using the <tt>*-d-test-suite</tt> targets of the top-level Makefile. By default, D1 is targeted, to build it with D2, use the optional <tt>D_VERSION</tt> variable, e.g. <tt>make check-d-test-suite D_VERSION=2</tt>.</p>
@ -424,14 +424,14 @@ struct A {
<p>Note: If you want to use GDC on Linux or another platform which requires you to link <tt>libdl</tt> for dynamically loading the shared library, you might have to add <tt>-ldl</tt> manually to the <tt>d_compile</tt> target in <tt>Examples/Makefile</tt>, because GDC does not currently honor the <tt>pragma(lib,...)</tt> statement.</p>
<H2><a name="D_typemap_examples"></a>21.9 D Typemap examples</H2>
<H2><a name="D_typemap_examples"></a>22.9 D Typemap examples</H2>
<p>There are no D-specific typemap examples yet. However, with the above <a href="D.html#D_typemap_name_comparison">name comparison table</a>, you should be able to get an idea what can be done by looking at the <a href="CSharp.html#CSharp_typemap_examples">corresponding C# section</a>.</p>
<H2><a name="D_planned_features"></a>21.10 Work in progress and planned features</H2>
<H2><a name="D_planned_features"></a>22.10 Work in progress and planned features</H2>
<p>There are a couple of features which are not implemented yet, but would be very useful and might be added in the near future:</p>

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Extending"></a>38 Extending SWIG to support new languages</H1>
<H1><a name="Extending"></a>39 Extending SWIG to support new languages</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -75,7 +75,7 @@
<H2><a name="Extending_nn2"></a>38.1 Introduction</H2>
<H2><a name="Extending_nn2"></a>39.1 Introduction</H2>
<p>
@ -91,7 +91,7 @@ Also, this chapter is not meant to be a hand-holding tutorial. As a starting po
you should probably look at one of SWIG's existing modules.
</p>
<H2><a name="Extending_nn3"></a>38.2 Prerequisites</H2>
<H2><a name="Extending_nn3"></a>39.2 Prerequisites</H2>
<p>
@ -121,7 +121,7 @@ obvious, but almost all SWIG directives as well as the low-level generation of
wrapper code are driven by C++ datatypes.
</p>
<H2><a name="Extending_nn4"></a>38.3 The Big Picture</H2>
<H2><a name="Extending_nn4"></a>39.3 The Big Picture</H2>
<p>
@ -158,7 +158,7 @@ role in making the system work. For example, both typemaps and declaration anno
based on pattern matching and interact heavily with the underlying type system.
</p>
<H2><a name="Extending_nn5"></a>38.4 Execution Model</H2>
<H2><a name="Extending_nn5"></a>39.4 Execution Model</H2>
<p>
@ -203,7 +203,7 @@ latter stage of compilation.
The next few sections briefly describe some of these stages.
</p>
<H3><a name="Extending_nn6"></a>38.4.1 Preprocessing</H3>
<H3><a name="Extending_nn6"></a>39.4.1 Preprocessing</H3>
<p>
@ -284,7 +284,7 @@ been expanded as well as everything else that goes into the low-level
construction of the wrapper code.
</p>
<H3><a name="Extending_nn7"></a>38.4.2 Parsing</H3>
<H3><a name="Extending_nn7"></a>39.4.2 Parsing</H3>
<p>
@ -385,7 +385,7 @@ returning a <tt>foo</tt> and taking types <tt>a</tt> and <tt>b</tt> as
arguments).
</p>
<H3><a name="Extending_nn8"></a>38.4.3 Parse Trees</H3>
<H3><a name="Extending_nn8"></a>39.4.3 Parse Trees</H3>
<p>
@ -640,7 +640,7 @@ $ swig -c++ -python -debug-module 4 example.i
</pre>
</div>
<H3><a name="Extending_nn9"></a>38.4.4 Attribute namespaces</H3>
<H3><a name="Extending_nn9"></a>39.4.4 Attribute namespaces</H3>
<p>
@ -659,7 +659,7 @@ that matches the name of the target language. For example, <tt>python:foo</tt>
<tt>perl:foo</tt>.
</p>
<H3><a name="Extending_nn10"></a>38.4.5 Symbol Tables</H3>
<H3><a name="Extending_nn10"></a>39.4.5 Symbol Tables</H3>
<p>
@ -750,7 +750,7 @@ example.i:5. Previous declaration is foo_i(int )
</pre>
</div>
<H3><a name="Extending_nn11"></a>38.4.6 The %feature directive</H3>
<H3><a name="Extending_nn11"></a>39.4.6 The %feature directive</H3>
<p>
@ -806,7 +806,7 @@ For example, the exception code above is simply
stored without any modifications.
</p>
<H3><a name="Extending_nn12"></a>38.4.7 Code Generation</H3>
<H3><a name="Extending_nn12"></a>39.4.7 Code Generation</H3>
<p>
@ -928,7 +928,7 @@ public :
The role of these functions is described shortly.
</p>
<H3><a name="Extending_nn13"></a>38.4.8 SWIG and XML</H3>
<H3><a name="Extending_nn13"></a>39.4.8 SWIG and XML</H3>
<p>
@ -941,7 +941,7 @@ internal data structures, it may be useful to keep XML in the back of
your mind as a model.
</p>
<H2><a name="Extending_nn14"></a>38.5 Primitive Data Structures</H2>
<H2><a name="Extending_nn14"></a>39.5 Primitive Data Structures</H2>
<p>
@ -987,7 +987,7 @@ typedef Hash Typetab;
</pre>
</div>
<H3><a name="Extending_nn15"></a>38.5.1 Strings</H3>
<H3><a name="Extending_nn15"></a>39.5.1 Strings</H3>
<p>
@ -1128,7 +1128,7 @@ Returns the number of replacements made (if any).
</div>
<H3><a name="Extending_nn16"></a>38.5.2 Hashes</H3>
<H3><a name="Extending_nn16"></a>39.5.2 Hashes</H3>
<p>
@ -1205,7 +1205,7 @@ Returns the list of hash table keys.
</div>
<H3><a name="Extending_nn17"></a>38.5.3 Lists</H3>
<H3><a name="Extending_nn17"></a>39.5.3 Lists</H3>
<p>
@ -1294,7 +1294,7 @@ If <tt>t</tt> is not a standard object, it is assumed to be a <tt>char *</tt>
and is used to create a String object.
</div>
<H3><a name="Extending_nn18"></a>38.5.4 Common operations</H3>
<H3><a name="Extending_nn18"></a>39.5.4 Common operations</H3>
The following operations are applicable to all datatypes.
@ -1349,7 +1349,7 @@ objects and report errors.
Gets the line number associated with <tt>x</tt>.
</div>
<H3><a name="Extending_nn19"></a>38.5.5 Iterating over Lists and Hashes</H3>
<H3><a name="Extending_nn19"></a>39.5.5 Iterating over Lists and Hashes</H3>
To iterate over the elements of a list or a hash table, the following functions are used:
@ -1394,7 +1394,7 @@ for (j = First(j); j.item; j= Next(j)) {
</div>
<H3><a name="Extending_nn20"></a>38.5.6 I/O</H3>
<H3><a name="Extending_nn20"></a>39.5.6 I/O</H3>
Special I/O functions are used for all internal I/O. These operations
@ -1500,12 +1500,11 @@ Create a File object wrapper around an existing <tt>FILE *</tt> object.
</div>
<p>
<b><tt>int Close(String_or_FILE *f)</tt></b>
There's no explicit function to close a file, just call <tt>Delete(f)</tt> -
this decreases the reference count, and the file will be closed when the
reference count reaches zero.
</p>
<div class="indent">
<p>Closes a file. Has no effect on strings.</p>
<p>
The use of the above I/O functions and strings play a critical role in SWIG. It is
common to see small code fragments of code generated using code like this:
@ -1529,9 +1528,7 @@ Printf(f, "%s\n", s);
Similarly, the preprocessor and parser all operate on string-files.
</p>
</div>
<H2><a name="Extending_nn21"></a>38.6 Navigating and manipulating parse trees</H2>
<H2><a name="Extending_nn21"></a>39.6 Navigating and manipulating parse trees</H2>
Parse trees are built as collections of hash tables. Each node is a hash table in which
@ -1665,7 +1662,7 @@ Deletes a node from the parse tree. Deletion reconnects siblings and properly u
the parent so that sibling nodes are unaffected.
</div>
<H2><a name="Extending_nn22"></a>38.7 Working with attributes</H2>
<H2><a name="Extending_nn22"></a>39.7 Working with attributes</H2>
<p>
@ -1782,7 +1779,7 @@ the attribute is optional. <tt>Swig_restore()</tt> must always be called after
function.
</div>
<H2><a name="Extending_nn23"></a>38.8 Type system</H2>
<H2><a name="Extending_nn23"></a>39.8 Type system</H2>
<p>
@ -1791,7 +1788,7 @@ pointers, references, and pointers to members. A detailed discussion of
type theory is impossible here. However, let's cover the highlights.
</p>
<H3><a name="Extending_nn24"></a>38.8.1 String encoding of types</H3>
<H3><a name="Extending_nn24"></a>39.8.1 String encoding of types</H3>
<p>
@ -1892,7 +1889,7 @@ make the final type, the two parts are just joined together using
string concatenation.
</p>
<H3><a name="Extending_nn25"></a>38.8.2 Type construction</H3>
<H3><a name="Extending_nn25"></a>39.8.2 Type construction</H3>
<p>
@ -2061,7 +2058,7 @@ Returns the prefix of a type. For example, if <tt>ty</tt> is
<tt>ty</tt> is unmodified.
</div>
<H3><a name="Extending_nn26"></a>38.8.3 Type tests</H3>
<H3><a name="Extending_nn26"></a>39.8.3 Type tests</H3>
<p>
@ -2148,7 +2145,7 @@ Checks if <tt>ty</tt> is a varargs type.
Checks if <tt>ty</tt> is a templatized type.
</div>
<H3><a name="Extending_nn27"></a>38.8.4 Typedef and inheritance</H3>
<H3><a name="Extending_nn27"></a>39.8.4 Typedef and inheritance</H3>
<p>
@ -2250,7 +2247,7 @@ Fully reduces <tt>ty</tt> according to typedef rules. Resulting datatype
will consist only of primitive typenames.
</div>
<H3><a name="Extending_nn28"></a>38.8.5 Lvalues</H3>
<H3><a name="Extending_nn28"></a>39.8.5 Lvalues</H3>
<p>
@ -2287,7 +2284,7 @@ Literal y; // type = 'Literal', ltype='p.char'
</pre>
</div>
<H3><a name="Extending_nn29"></a>38.8.6 Output functions</H3>
<H3><a name="Extending_nn29"></a>39.8.6 Output functions</H3>
<p>
@ -2349,7 +2346,7 @@ SWIG, but is most commonly associated with type-descriptor objects
that appear in wrappers (e.g., <tt>SWIGTYPE_p_double</tt>).
</div>
<H2><a name="Extending_nn30"></a>38.9 Parameters</H2>
<H2><a name="Extending_nn30"></a>39.9 Parameters</H2>
<p>
@ -2448,7 +2445,7 @@ included. Used to emit prototypes.
Returns the number of required (non-optional) arguments in <tt>p</tt>.
</div>
<H2><a name="Extending_nn31"></a>38.10 Writing a Language Module</H2>
<H2><a name="Extending_nn31"></a>39.10 Writing a Language Module</H2>
<p>
@ -2463,7 +2460,7 @@ describes the creation of a minimal Python module. You should be able to extra
this to other languages.
</p>
<H3><a name="Extending_nn32"></a>38.10.1 Execution model</H3>
<H3><a name="Extending_nn32"></a>39.10.1 Execution model</H3>
<p>
@ -2473,7 +2470,7 @@ the parsing of command line options, all aspects of code generation are controll
different methods of the <tt>Language</tt> that must be defined by your module.
</p>
<H3><a name="Extending_starting_out"></a>38.10.2 Starting out</H3>
<H3><a name="Extending_starting_out"></a>39.10.2 Starting out</H3>
<p>
@ -2581,7 +2578,7 @@ that activates your module. For example, <tt>swig -python foo.i</tt>. The
messages from your new module should appear.
</p>
<H3><a name="Extending_nn34"></a>38.10.3 Command line options</H3>
<H3><a name="Extending_nn34"></a>39.10.3 Command line options</H3>
<p>
@ -2640,7 +2637,7 @@ to mark the option as valid. If you forget to do this, SWIG will terminate wit
unrecognized command line option error.
</p>
<H3><a name="Extending_nn35"></a>38.10.4 Configuration and preprocessing</H3>
<H3><a name="Extending_nn35"></a>39.10.4 Configuration and preprocessing</H3>
<p>
@ -2689,7 +2686,7 @@ an implementation file <tt>python.cxx</tt> and a configuration file
<tt>python.swg</tt>.
</p>
<H3><a name="Extending_nn36"></a>38.10.5 Entry point to code generation</H3>
<H3><a name="Extending_nn36"></a>39.10.5 Entry point to code generation</H3>
<p>
@ -2747,7 +2744,7 @@ int Python::top(Node *n) {
</pre>
</div>
<H3><a name="Extending_nn37"></a>38.10.6 Module I/O and wrapper skeleton</H3>
<H3><a name="Extending_nn37"></a>39.10.6 Module I/O and wrapper skeleton</H3>
<!-- please report bugs in this section to mgossage -->
@ -2761,8 +2758,8 @@ Within SWIG wrappers, there are five main sections. These are (in order)
<li>begin: This section is a placeholder for users to put code at the beginning of the C/C++ wrapper file.
<li>runtime: This section has most of the common SWIG runtime code.
<li>header: This section holds declarations and inclusions from the .i file.
<li>wrapper: This section holds all the wrappering code.
<li>init: This section holds the module initalisation function
<li>wrapper: This section holds all the wrapper code.
<li>init: This section holds the module initialisation function
(the entry point for the interpreter).
</ul>
<p>
@ -2832,7 +2829,6 @@ int Python::top(Node *n) {
Delete(f_header);
Delete(f_wrappers);
Delete(f_init);
Close(f_begin);
Delete(f_begin);
return SWIG_OK;
@ -2896,7 +2892,7 @@ functionWrapper : void Shape_y_set(Shape *self,double y)
</pre>
</div>
<H3><a name="Extending_nn38"></a>38.10.7 Low-level code generators</H3>
<H3><a name="Extending_nn38"></a>39.10.7 Low-level code generators</H3>
<!-- please report bugs in this section to mgossage -->
@ -2975,7 +2971,7 @@ There are a lot of issues to address.
<div class="code">
<pre>
virtual int functionWrapper(Node *n) {
/* get useful atributes */
/* get useful attributes */
String *name = Getattr(n,"sym:name");
SwigType *type = Getattr(n,"type");
ParmList *parms = Getattr(n,"parms");
@ -3005,7 +3001,7 @@ virtual int functionWrapper(Node *n) {
/* write typemaps(in) */
....
/* write constriants */
/* write constraints */
....
/* Emit the function call */
@ -3050,7 +3046,7 @@ but without the typemaps, there is still work to do.
</p>
<H3><a name="Extending_configuration_files"></a>38.10.8 Configuration files</H3>
<H3><a name="Extending_configuration_files"></a>39.10.8 Configuration files</H3>
<!-- please report bugs in this section to ttn -->
@ -3101,7 +3097,7 @@ As you can see, most usages are direct.
<dl>
<dt> <b>configure.in</b>
<dt> <b>configure.ac</b>
<dd> This file is processed by
<p>
@ -3194,7 +3190,7 @@ politely displays the ignoring language message.
</dl>
<H3><a name="Extending_nn40"></a>38.10.9 Runtime support</H3>
<H3><a name="Extending_nn40"></a>39.10.9 Runtime support</H3>
<p>
@ -3203,7 +3199,7 @@ Discuss the kinds of functions typically needed for SWIG runtime support (e.g.
the SWIG files that implement those functions.
</p>
<H3><a name="Extending_nn41"></a>38.10.10 Standard library files</H3>
<H3><a name="Extending_nn41"></a>39.10.10 Standard library files</H3>
<p>
@ -3222,7 +3218,7 @@ The following are the minimum that are usually supported:
Please copy these and modify for any new language.
</p>
<H3><a name="Extending_nn42"></a>38.10.11 User examples</H3>
<H3><a name="Extending_nn42"></a>39.10.11 User examples</H3>
<p>
@ -3251,7 +3247,7 @@ during this process, see the section on <a href="#Extending_configuration_files"
files</a>.
</p>
<H3><a name="Extending_test_suite"></a>38.10.12 Test driven development and the test-suite</H3>
<H3><a name="Extending_test_suite"></a>39.10.12 Test driven development and the test-suite</H3>
<p>
@ -3310,7 +3306,7 @@ It is therefore essential that the runtime tests are written in a manner that di
but error/exception out with an error message on stderr on failure.
</p>
<H4><a name="Extending_running_test_suite"></a>38.10.12.1 Running the test-suite</H4>
<H4><a name="Extending_running_test_suite"></a>39.10.12.1 Running the test-suite</H4>
<p>
@ -3350,10 +3346,10 @@ Note that if a runtime test is available, a message "(with run test)" is display
<div class="shell"><pre>
$ make check-python-test-suite
checking python test-suite
checking testcase argcargvtest (with run test) under python
checking testcase python_autodoc under python
checking testcase python_append (with run test) under python
checking testcase callback (with run test) under python
checking python testcase argcargvtest (with run test)
checking python testcase python_autodoc
checking python testcase python_append (with run test)
checking python testcase callback (with run test)
</pre></div>
<p>
@ -3496,7 +3492,13 @@ The syntax for setting environment variables varies from one shell to the next,
make ret_by_value.ctest SWIG_FEATURES="-debug-tmsearch"
</pre></div>
<H3><a name="Extending_nn43"></a>38.10.13 Documentation</H3>
<p>
There is also a special 'errors' test-suite which is a set of regression tests checking SWIG warning and error messages.
It can be run in the same way as the other language test-suites, replacing [lang] with errors, such as <tt>make check-errors-test-suite</tt>.
The test cases used and the way it works is described in <tt>Examples/test-suite/errors/Makefile.in</tt>.
</p>
<H3><a name="Extending_nn43"></a>39.10.13 Documentation</H3>
<p>
@ -3528,7 +3530,7 @@ Some topics that you'll want to be sure to address include:
if available.
</ul>
<H3><a name="Extending_prerequisites"></a>38.10.14 Prerequisites for adding a new language module to the SWIG distribution</H3>
<H3><a name="Extending_prerequisites"></a>39.10.14 Prerequisites for adding a new language module to the SWIG distribution</H3>
<p>
@ -3536,7 +3538,7 @@ If you wish for a new language module to be distributed with SWIG,
which we encourage for all popular languages, there are a few requirements.
While we appreciate that getting all aspects of a new language working
won't happen at the outset, there are a set of minimum requirements before
a module can be committed into the SVN repository for distribution with future
a module can be committed into the official Github repository for distribution with future
versions of SWIG. The following are really a summary of this whole section with
details being outlined earlier on.
</p>
@ -3551,7 +3553,7 @@ details being outlined earlier on.
a runtime test, see for example <tt>Examples/python/class</tt>.
</li>
<li>
Modify <tt>configure.in</tt>, <tt>Makefile.in</tt> and <tt>Examples/Makefile.in</tt> to run
Modify <tt>configure.ac</tt>, <tt>Makefile.in</tt> and <tt>Examples/Makefile.in</tt> to run
these examples. Please make sure that if the new language is not
installed properly on a box, <tt>make -k check</tt> should still work by
skipping the tests and examples for the new language module.
@ -3578,14 +3580,14 @@ details being outlined earlier on.
</ol>
<p>
Once accepted into SVN, development efforts should concentrate on
Once accepted into the official Git repository, development efforts should concentrate on
getting the entire test-suite to work with plenty of runtime tests.
Runtime tests should be for existing testcases and new test cases
should be added should there be an area not already covered by
the existing tests.
</p>
<H3><a name="Extending_coding_style_guidelines"></a>38.10.15 Coding style guidelines</H3>
<H3><a name="Extending_coding_style_guidelines"></a>39.10.15 Coding style guidelines</H3>
<p>
@ -3609,7 +3611,7 @@ The generated C/C++ code should also follow this style as close as possible. How
should be avoided as unlike the SWIG developers, users will never have consistent tab settings.
</p>
<H2><a name="Extending_debugging_options"></a>38.11 Debugging Options</H2>
<H2><a name="Extending_debugging_options"></a>39.11 Debugging Options</H2>
<p>
@ -3636,7 +3638,7 @@ There are various command line options which can aid debugging a SWIG interface
The complete list of command line options for SWIG are available by running <tt>swig -help</tt>.
</p>
<H2><a name="Extending_nn46"></a>38.12 Guide to parse tree nodes</H2>
<H2><a name="Extending_nn46"></a>39.12 Guide to parse tree nodes</H2>
<p>
@ -4044,7 +4046,7 @@ extern "X" { ... } declaration.
</pre>
</div>
<H2><a name="Extending_further_info"></a>38.13 Further Development Information</H2>
<H2><a name="Extending_further_info"></a>39.13 Further Development Information</H2>
<p>

View file

@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body bgcolor="#FFFFFF">
<H1><a name="Go"></a>22 SWIG and Go</H1>
<H1><a name="Go"></a>23 SWIG and Go</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -43,7 +43,7 @@ the Go programming language
see <a href="http://golang.org/">golang.org</a>.
</p>
<H2><a name="Go_overview"></a>22.1 Overview</H2>
<H2><a name="Go_overview"></a>23.1 Overview</H2>
<p>
@ -55,7 +55,7 @@ there is no convenient way to call C++ code. SWIG fills this gap.
<p>
There are (at least) two different Go compilers. One is the gc
compiler, normally invoked under the names 6g, 8g, or 5g. The other
compiler, normally invoked via the go tool. The other
is the gccgo compiler, which is a frontend to the gcc compiler suite.
The interface to C/C++ code is completely different for the two Go
compilers. SWIG supports both, selected by a command line option.
@ -67,7 +67,7 @@ checking and runtime library are not used with Go. This should be
borne in mind when reading the rest of the SWIG documentation.
</p>
<H2><a name="Go_running_swig"></a>22.2 Running SWIG with Go</H2>
<H2><a name="Go_running_swig"></a>23.2 Running SWIG with Go</H2>
<p>
@ -76,11 +76,11 @@ default SWIG will generate code for the gc compilers. To generate
code for gccgo, you should also use the <tt>-gccgo</tt> option.
</p>
<H3><a name="Go_commandline"></a>22.2.1 Additional Commandline Options</H3>
<H3><a name="Go_commandline"></a>23.2.1 Additional Commandline Options</H3>
<p>
These are the command line options for SWIG's GO module. They can
These are the command line options for SWIG's Go module. They can
also be seen by using:
</p>
@ -93,23 +93,22 @@ swig -go -help
<th>Go specific options</th>
</tr>
<tr>
<td>-intgosize &lt;s&gt;</td>
<td>Set the size for the Go type <tt>int</tt>. This controls the size
that the C/C++ code expects to see. The &lt;s&gt; argument should
be 32 or 64. This option is currently required during the
transition from Go 1.0 to Go 1.1, as the size of <tt>int</tt> on
64-bit x86 systems changes between those releases (from 32 bits to
64 bits). In the future the option may become optional, and SWIG
will assume that the size of <tt>int</tt> is the size of a C
pointer.</td>
</tr>
<tr>
<td>-gccgo</td>
<td>Generate code for gccgo. The default is to generate code for
6g/8g/5g.</td>
</tr>
<tr>
<td>-gccgo-46</td>
<td>Generate code for gccgo 4.6. The default is set by the configure
script. This generates code that does not use some facilities
that are only available in gccgo 4.7 and later.</td>
</tr>
<tr>
<td>-no-gccgo-46</td>
<td>Turn off <code>-gccgo-46</code>, whether set by default or earlier
on the command line.
the gc compiler.</td>
</tr>
<tr>
@ -119,30 +118,39 @@ swig -go -help
</tr>
<tr>
<td>-soname %lt;name%gt;</td>
<td>-use-shlib</td>
<td>Tell SWIG to emit code that uses a shared library. This is only
meaningful for the gc compiler, which needs to know at compile time
whether a shared library will be used.</td>
</tr>
<tr>
<td>-soname &lt;name&gt;</td>
<td>Set the runtime name of the shared library that the dynamic linker
should include at runtime. The default is the package name with
".so" appended. This is only used when generating code for
6g/8g/5g; when using gccgo, the equivalent name will be taken from
the <code>-soname</code> option passed to the linker.</td>
the gc compiler; when using gccgo, the equivalent name will be taken from
the <code>-soname</code> option passed to the linker. Using this
option implies the -use-shlib option.</td>
</tr>
<tr>
<td>-go-pkgpath &lt;pkgpath&gt;</td>
<td>When generating code for gccgo, set the pkgpath to use. This
corresponds to the <tt>-fgo-pkgpath</tt> option to gccgo.</td>
</tr>
<tr>
<td>-go-prefix &lt;prefix&gt;</td>
<td>When generating code for gccgo, set the prefix to use. This
corresponds to the <tt>-fgo-prefix</tt> option to gccgo.</td>
</tr>
<tr>
<td>-long-type-size &lt;s&gt;</td>
<td>Set the size for the C/C++ type <tt>long</tt>. This controls
whether <tt>long</tt> is converted to the Go type <tt>int32</tt>
or <tt>int64</tt>. The &lt;s&gt; argument should be 32 or 64.</td>
corresponds to the <tt>-fgo-prefix</tt> option to gccgo.
If <tt>-go-pkgpath</tt> is used, <tt>-go-prefix</tt> will be
ignored.</td>
</tr>
</table>
<H3><a name="Go_outputs"></a>22.2.2 Go Output Files</H3>
<H3><a name="Go_outputs"></a>23.2.2 Go Output Files</H3>
<p> When generating Go code, SWIG will generate the following
@ -166,28 +174,59 @@ may be helpful to include it in your code, compiled with the usual C
or C++ compiler.
<li>
If using the gc compiler, MODULE_gc.c will contain C code which should
be compiled with the C compiler distributed as part of the gc compiler: 6c, 8c,
or 5c. It should then be combined with the compiled MODULE.go using
gopack. This file will not be generated when using gccgo.
be compiled with the C compiler distributed as part of the gc
compiler. It should then be combined with the compiled MODULE.go
using gopack. This file will not be generated when using gccgo.
</ul>
<p>
A typical command sequence would look like this:
Most Go programs are built using the go tool. The go tool has limited
support for SWIG. To use it, put your SWIG interface into a file with
the extension .swig, or, if you are wrapping C++ code, .swigcxx. Put
that file in a GOPATH/src directory as usual for Go sources. Put
other interface code in the same directory with extensions of .c and
.cxx. The go build command and go install commands will automatically
run SWIG for you and will build the interface code.
</p>
<p>
You can also use SWIG directly yourself. When using the gc compiler
version 1.2 or later, or when using gccgo, the code generated by SWIG
can be linked directly into the Go program. A typical command
sequence when using the gc compiler would look like this:
</p>
<div class="code"><pre>
% swig -go example.i
% gcc -c code.c # The C library being wrapped.
% gcc -c example_wrap.c
% go tool 6g example.go
% go tool 6c example_gc.c
% go tool pack grc example.a example.6 example_gc.6 code.o example_wrap.o
% go tool 6g main.go
% go tool 6l main.6
</pre></div>
<p>
You can also put the wrapped code into a shared library, and when
using the gc compiler before version 1.2 this is the only supported
option. A typical command sequence for this approach would look like
this:
</p>
<div class="code"><pre>
% swig -go -use-shlib example.i
% gcc -c -fpic example.c
% gcc -c -fpic example_wrap.c
% gcc -shared example.o example_wrap.o -o example.so
% 6g example.go
% 6c example_gc.c
% gopack grc example.a example.6 example_gc.6
% 6g main.go # your code, not generated by SWIG
% 6l main.6
% go tool 6g example.go
% go tool 6c example_gc.c
% go tool pack grc example.a example.6 example_gc.6
% go tool 6g main.go # your code, not generated by SWIG
% go tool 6l main.6
</pre></div>
<H2><a name="Go_basic_tour"></a>22.3 A tour of basic C/C++ wrapping</H2>
<H2><a name="Go_basic_tour"></a>23.3 A tour of basic C/C++ wrapping</H2>
<p>
@ -197,7 +236,7 @@ modifications have to occur. This section briefly covers the
essential aspects of this wrapping.
</p>
<H3><a name="Go_package"></a>22.3.1 Go Package Name</H3>
<H3><a name="Go_package"></a>23.3.1 Go Package Name</H3>
<p>
@ -207,7 +246,7 @@ directive. You may override this by using SWIG's <tt>-package</tt>
command line option.
</p>
<H3><a name="Go_names"></a>22.3.2 Go Names</H3>
<H3><a name="Go_names"></a>23.3.2 Go Names</H3>
<p>
@ -239,7 +278,7 @@ followed by that name, and the destructor will be
named <tt>Delete</tt> followed by that name.
</p>
<H3><a name="Go_constants"></a>22.3.3 Go Constants</H3>
<H3><a name="Go_constants"></a>23.3.3 Go Constants</H3>
<p>
@ -247,7 +286,7 @@ C/C++ constants created via <tt>#define</tt> or the <tt>%constant</tt>
directive become Go constants, declared with a <tt>const</tt>
declaration.
<H3><a name="Go_enumerations"></a>22.3.4 Go Enumerations</H3>
<H3><a name="Go_enumerations"></a>23.3.4 Go Enumerations</H3>
<p>
@ -257,7 +296,7 @@ usual). The values of the enumeration will become variables in Go;
code should avoid modifying those variables.
</p>
<H3><a name="Go_classes"></a>22.3.5 Go Classes</H3>
<H3><a name="Go_classes"></a>23.3.5 Go Classes</H3>
<p>
@ -335,7 +374,7 @@ 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>22.3.5.1 Go Class Inheritance</H4>
<H4><a name="Go_class_inheritance"></a>23.3.5.1 Go Class Inheritance</H4>
<p>
@ -347,7 +386,7 @@ Doing the reverse will require an explicit type assertion, which will
be checked dynamically.
</p>
<H3><a name="Go_templates"></a>22.3.6 Go Templates</H3>
<H3><a name="Go_templates"></a>23.3.6 Go Templates</H3>
<p>
@ -355,7 +394,7 @@ In order to use C++ templates in Go, you must tell SWIG to create
wrappers for a particular template instantation. To do this, use
the <tt>%template</tt> directive.
<H3><a name="Go_director_classes"></a>22.3.7 Go Director Classes</H3>
<H3><a name="Go_director_classes"></a>23.3.7 Go Director Classes</H3>
<p>
@ -398,7 +437,7 @@ method defined in Go. The Go code may of course call other methods on
itself, and those methods may be defined either in Go or in C++.
</p>
<H3><a name="Go_primitive_type_mappings"></a>22.3.8 Default Go primitive type mappings</H3>
<H3><a name="Go_primitive_type_mappings"></a>23.3.8 Default Go primitive type mappings</H3>
<p>
@ -455,12 +494,12 @@ uses a given C/C++ type.
<tr>
<td>long</td>
<td>int32 or int64, depending on <tt>-long-type-size</tt></td>
<td>int64</td>
</tr>
<tr>
<td>unsigned long</td>
<td>uint32 or uint64, depending on <tt>-long-type-size</tt></td>
<td>uint64</td>
</tr>
<tr>
@ -505,13 +544,13 @@ that typemap, or add new values, to control how C/C++ types are mapped
into Go types.
</p>
<H3><a name="Go_output_arguments"></a>22.3.9 Output arguments</H3>
<H3><a name="Go_output_arguments"></a>23.3.9 Output arguments</H3>
<p>Because of limitations in the way output arguments are processed in swig,
a function with output arguments will not have multiple return values.
Instead, you must pass a pointer into the C++ function to tell it where to
store the ouput value. In go, you supply a slice in the place of the output
store the output value. In go, you supply a slice in the place of the output
argument.</p>
<p>For example, suppose you were trying to wrap the modf() function in the
@ -558,7 +597,7 @@ void f(char *output);
</pre>
</div>
<H3><a name="Go_adding_additional_code"></a>22.3.10 Adding additional go code</H3>
<H3><a name="Go_adding_additional_code"></a>23.3.10 Adding additional go code</H3>
<p>Often the APIs generated by swig are not very natural in go, especially if
@ -627,9 +666,31 @@ func (arg SwigcptrWrapped_MyClass) GetAValue() (int, bool) {
few, then you might as well define your own struct that includes the
swig-wrapped object, instead of adding methods to the swig-generated object.</p>
<p>This only works if your wrappers do not need to import other go modules.
There is at present no way to insert import statements in the correct place
in swig-generated go. If you need to do that, you must put your go code
in a separate file.</p>
<p>If you need to import other go packages, you can do this with
<code>%go_import</code>. For example,</p>
<div class="code">
<pre>
%go_import("fmt", _ "unusedPackage", rp "renamed/package")
%insert(go_wrapper) %{
func foo() {
fmt.Println("Some string:", rp.GetString())
}
// Importing the same package twice is permitted,
// Go code will be generated with only the first instance of the import.
%go_import("fmt")
%insert(go_wrapper) %{
func bar() {
fmt.Println("Hello world!")
}
%}
</pre>
</div>
</body>
</html>

View file

@ -8,12 +8,13 @@
<body bgcolor="#ffffff">
<H1><a name="Guile"></a>23 SWIG and Guile</H1>
<H1><a name="Guile"></a>24 SWIG and Guile</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
<li><a href="#Guile_nn1">Supported Guile Versions</a>
<li><a href="#Guile_nn2">Meaning of "Module"</a>
<li><a href="#Guile_nn3">Using the SCM or GH Guile API</a>
<li><a href="#Guile_nn3">Old GH Guile API</a>
<li><a href="#Guile_nn4">Linkage</a>
<ul>
<li><a href="#Guile_nn5">Simple Linkage</a>
@ -26,8 +27,7 @@
<li><a href="#Guile_nn11">Typemaps</a>
<li><a href="#Guile_nn12">Representation of pointers as smobs</a>
<ul>
<li><a href="#Guile_nn13">GH Smobs</a>
<li><a href="#Guile_nn14">SCM Smobs</a>
<li><a href="#Guile_nn14">Smobs</a>
<li><a href="#Guile_nn15">Garbage Collection</a>
</ul>
<li><a href="#Guile_nn16">Exception Handling</a>
@ -47,7 +47,21 @@
<p>
This section details guile-specific support in SWIG.
<H2><a name="Guile_nn2"></a>23.1 Meaning of "Module"</H2>
<H2><a name="Guile_nn1"></a>24.1 Supported Guile Versions</H2>
<p>
SWIG works with Guile versions 1.8.x and 2.0.x. Support for version
1.6.x has been dropped. The last version of SWIG that still works with
Guile version 1.6.x is SWIG 2.0.9.
<p>
Note that starting with guile 2.0, the guile sources can be compiled for
improved performance. This is currently not tested with swig
so your mileage may vary. To be safe set environment variable
GUILE_AUTO_COMPILE to 0 when using swig generated guile code.
<H2><a name="Guile_nn2"></a>24.2 Meaning of "Module"</H2>
<p>
@ -55,55 +69,18 @@ There are three different concepts of "module" involved, defined
separately for SWIG, Guile, and Libtool. To avoid horrible confusion,
we explicitly prefix the context, e.g., "guile-module".
<H2><a name="Guile_nn3"></a>23.2 Using the SCM or GH Guile API</H2>
<H2><a name="Guile_nn3"></a>24.3 Old GH Guile API</H2>
<p>The guile module can currently export wrapper files that use the guile GH interface or the
SCM interface. This is controlled by an argument passed to swig. The "-gh" argument causes swig
to output GH code, and the "-scm" argument causes swig to output SCM code. Right now the "-scm" argument
is the default. The "-scm" wrapper generation assumes a guile version &gt;= 1.6 and has several advantages over
the "-gh" wrapper generation including garbage collection and GOOPS support.
The "-gh" wrapper generation can be used for older versions of guile.
The guile GH wrapper code generation is depreciated and the
SCM interface is the default. The SCM and GH interface differ greatly in how they store
pointers and have completely different run-time code. See below for more info.
<p>The GH interface to guile is deprecated. Read more about why in the
<p>Guile 1.8 and older could be interfaced using two different api's, the SCM
or the GH API. The GH interface to guile is deprecated. Read more about why in the
<a href="http://www.gnu.org/software/guile/docs/docs-1.6/guile-ref/GH.html#GH">Guile manual</a>.
The idea of the GH interface was to provide a high level API that other languages and projects
could adopt. This was a good idea, but didn't pan out well for general development. But for the
specific, minimal uses that the SWIG typemaps put the GH interface to use is ideal for
using a high level API. So even though the GH interface is depreciated, SWIG will continue to use
the GH interface and provide mappings from the GH interface to whatever API we need.
We can maintain this mapping where guile failed because SWIG uses a small subset of all the GH functions
which map easily. All the guile typemaps like typemaps.i and std_vector.i
will continue to use the GH functions to do things like create lists of values, convert strings to
integers, etc. Then every language module will define a mapping between the GH interface and
whatever custom API the language uses. This is currently implemented by the guile module to use
the SCM guile API rather than the GH guile API.
For example, here are some of the current mapping file for the SCM API</p>
<div class="code"><pre>
<p>Support for the guile GH wrapper code generation has been dropped from SWIG. The last
version of SWIG that can still generate guile GH wrapper code is 2.0.9. Please
use that version if you really need the GH wrapper code.
#define gh_append2(a, b) scm_append(scm_listify(a, b, SCM_UNDEFINED))
#define gh_apply(a, b) scm_apply(a, b, SCM_EOL)
#define gh_bool2scm SCM_BOOL
#define gh_boolean_p SCM_BOOLP
#define gh_car SCM_CAR
#define gh_cdr SCM_CDR
#define gh_cons scm_cons
#define gh_double2scm scm_make_real
...
</pre></div>
<p>This file is parsed by SWIG at wrapper generation time, so every reference to a gh_ function is replaced
by a scm_ function in the wrapper file. Thus the gh_ function calls will never be seen in the wrapper;
the wrapper will look exactly like it was generated
for the specific API. Currently only the guile language module has created a mapping policy from gh_ to scm_,
but there is no reason other languages (like mzscheme or chicken) couldn't also use this.
If that happens, there is A LOT less code duplication in the standard typemaps.</p>
<H2><a name="Guile_nn4"></a>23.3 Linkage</H2>
<H2><a name="Guile_nn4"></a>24.4 Linkage</H2>
<p>
@ -111,7 +88,7 @@ Guile support is complicated by a lack of user community cohesiveness,
which manifests in multiple shared-library usage conventions. A set of
policies implementing a usage convention is called a <b>linkage</b>.
<H3><a name="Guile_nn5"></a>23.3.1 Simple Linkage</H3>
<H3><a name="Guile_nn5"></a>24.4.1 Simple Linkage</H3>
<p>
@ -134,7 +111,7 @@ libraries into Guile.</p>
<div class="targetlang">
<pre>
(define-module (my module))
(define my-so (dynamic-link "./example.so"))
(define my-so (dynamic-link "./libexample.so"))
(dynamic-call "SWIG_init" my-so) ; make SWIG bindings
;; Scheme definitions can go here
</pre>
@ -147,7 +124,17 @@ and <code>dynamic-call</code>:
<div class="targetlang">
<pre>
(load-extension "./example.so" "SWIG_init")
(load-extension "./libexample.so" "SWIG_init")
</pre>
</div>
<p>
A more portable approach would be to drop the shared library extension:
</p>
<div class="targetlang">
<pre>
(load-extension "./libexample" "SWIG_init")
</pre>
</div>
@ -190,7 +177,7 @@ information by including a directive like this in the interface file:
<div class="code">
<pre>
%scheme %{ (load-extension "./example.so" "SWIG_init") %}
%scheme %{ (load-extension "./libexample.so" "SWIG_init") %}
</pre>
</div>
@ -206,7 +193,7 @@ placed between the <code>define-module</code> form and the
<code>SWIG_init</code> via a preprocessor define to avoid symbol
clashes. For this case, however, passive linkage is available.
<H3><a name="Guile_nn6"></a>23.3.2 Passive Linkage</H3>
<H3><a name="Guile_nn6"></a>24.4.2 Passive Linkage</H3>
<p>Passive linkage is just like simple linkage, but it generates an
@ -216,12 +203,12 @@ package name (see below).
<p>You should use passive linkage rather than simple linkage when you
are using multiple modules.
<H3><a name="Guile_nn7"></a>23.3.3 Native Guile Module Linkage</H3>
<H3><a name="Guile_nn7"></a>24.4.3 Native Guile Module Linkage</H3>
<p>SWIG can also generate wrapper code that does all the Guile module
declarations on its own if you pass it the <code>-Linkage
module</code> command-line option. This requires Guile 1.5.0 or later.
module</code> command-line option.
<p>The module name is set with the <code>-package</code> and
<code>-module</code> command-line options. Suppose you want to define
@ -244,7 +231,7 @@ shared libraries into Guile; all bindings are automatically put in
newly created Guile modules.
<div class="targetlang">
<pre>
(define my-so (dynamic-link "./foo.so"))
(define my-so (dynamic-link "./libfoo"))
;; create new module and put bindings there:
(dynamic-call "scm_init_my_modules_foo_module" my-so)
</pre>
@ -252,12 +239,12 @@ newly created Guile modules.
Newer Guile versions have a shorthand procedure for this:
<div class="targetlang">
<pre>
(load-extension "./foo.so" "scm_init_my_modules_foo_module")
(load-extension "./libfoo.so" "scm_init_my_modules_foo_module")
</pre>
</div>
</ul>
<H3><a name="Guile_nn8"></a>23.3.4 Old Auto-Loading Guile Module Linkage</H3>
<H3><a name="Guile_nn8"></a>24.4.4 Old Auto-Loading Guile Module Linkage</H3>
<p>Guile used to support an autoloading facility for object-code
@ -283,7 +270,7 @@ option, SWIG generates an exported module initialization function with
an appropriate name.
<H3><a name="Guile_nn9"></a>23.3.5 Hobbit4D Linkage</H3>
<H3><a name="Guile_nn9"></a>24.4.5 Hobbit4D Linkage</H3>
<p>
@ -308,7 +295,7 @@ my/lib/libfoo.so.X.Y.Z and friends. This scheme is still very
experimental; the (hobbit4d link) conventions are not well understood.
</p>
<H2><a name="Guile_nn10"></a>23.4 Underscore Folding</H2>
<H2><a name="Guile_nn10"></a>24.5 Underscore Folding</H2>
<p>
@ -320,7 +307,7 @@ complained so far.
<code>%rename</code> to specify the Guile name of the wrapped
functions and variables (see CHANGES).
<H2><a name="Guile_nn11"></a>23.5 Typemaps</H2>
<H2><a name="Guile_nn11"></a>24.6 Typemaps</H2>
<p>
@ -412,7 +399,7 @@ constant will appear as a scheme variable. See
<a href="Customization.html#Customization_features">Features and the %feature directive</a>
for info on how to apply the %feature.</p>
<H2><a name="Guile_nn12"></a>23.6 Representation of pointers as smobs</H2>
<H2><a name="Guile_nn12"></a>24.7 Representation of pointers as smobs</H2>
<p>
@ -433,7 +420,7 @@ representing the expected pointer type. See also
If the Scheme object passed was not a SWIG smob representing a compatible
pointer, a <code>wrong-type-arg</code> exception is raised.
<H3><a name="Guile_nn13"></a>23.6.1 GH Smobs</H3>
<H3><a name="Guile_nn14"></a>24.7.1 Smobs</H3>
<p>
@ -444,44 +431,19 @@ mangled type name. As Guile allows registering user types, so-called
implemented now. The details will be discussed in the following.
</p>
<p> A smob is a cons cell where the lower half of the CAR contains the smob type
tag, while the upper half of the CAR and the whole CDR are available. Every
module creates its own smob type in the clientdata field of the module. So the
lower 16 bits of the car of the smob store the tag and the upper 16 bits store
the index this type is in the array. We can then, given a smob, find its
swig_type_info struct by using the tag (lower 16 bits of car) to find which
module this type is in (since each tag is unique for the module). Then we use
the upper 16 bits to index into the array of types attached to this module.
Looking up the module from the tag is worst case O(# of modules) but average
case O(1). This is because the modules are stored in a circularly linked list,
and when we start searching the modules for the tag, we start looking with the
module that the function doing the lookup is in. SWIG_Guile_ConvertPtr() takes
as its first argument the swig_module_info * of the calling function, which is
where we start comparing tags. Most types will be looked up in the same module
that created them, so the first module we check will most likely be correct.
Once we have a swig_type_info structure, we loop through the linked list of
casts, using pointer comparisons.</p>
<H3><a name="Guile_nn14"></a>23.6.2 SCM Smobs</H3>
<p>The SCM interface (using the "-scm" argument to swig) uses swigrun.swg.
The whole type system, when it is first initialized, creates two smobs named "swig" and "collected_swig".
<p>The whole type system, when it is first initialized, creates two smobs named "swig" and "collected_swig".
The swig smob is used for non-garbage collected smobs, while the collected_swig smob is used as described
below. Each smob has the same format, which is a double cell created by SCM_NEWSMOB2()
The first word of data is the pointer to the object and the second word of data is the swig_type_info *
structure describing this type. This is a lot easier than the GH interface above because we can store
a pointer to the type info structure right in the type. With the GH interface, there was not enough
room in the smob to store two whole words of data so we needed to store part of the "swig_type_info address"
in the smob tag. If a generated GOOPS module has been loaded, smobs will be wrapped by the corresponding
GOOPS class.</p>
structure describing this type. If a generated GOOPS module has been loaded, smobs will be wrapped by
the corresponding GOOPS class.</p>
<H3><a name="Guile_nn15"></a>23.6.3 Garbage Collection</H3>
<H3><a name="Guile_nn15"></a>24.7.2 Garbage Collection</H3>
<p>Garbage collection is a feature of the new SCM interface, and it is automatically included
if you pass the "-scm" flag to swig. Thus the swig garbage collection support requires guile &gt;1.6.
<p>Garbage collection is a feature of Guile since version 1.6. As SWIG now requires Guile &gt; 1.8,
it is automatically included.
Garbage collection works like this. Every swig_type_info structure stores in its clientdata field a pointer
to the destructor for this type. The destructor is the generated wrapper around the delete function.
So swig still exports a wrapper for the destructor, it just does not call scm_c_define_gsubr() for
@ -491,7 +453,7 @@ is exactly like described in <a href="Customization.html#Customization_ownership
Object ownership and %newobject</a> in the SWIG manual. All typemaps use an $owner var, and
the guile module replaces $owner with 0 or 1 depending on feature:new.</p>
<H2><a name="Guile_nn16"></a>23.7 Exception Handling</H2>
<H2><a name="Guile_nn16"></a>24.8 Exception Handling</H2>
<p>
@ -517,14 +479,13 @@ mapping:
The default when not specified here is to use "swig-error".
See Lib/exception.i for details.
<H2><a name="Guile_nn17"></a>23.8 Procedure documentation</H2>
<H2><a name="Guile_nn17"></a>24.9 Procedure documentation</H2>
<p>If invoked with the command-line option <code>-procdoc
<var>file</var></code>, SWIG creates documentation strings for the
generated wrapper functions, describing the procedure signature and
return value, and writes them to <var>file</var>. You need Guile 1.4
or later to make use of the documentation files.
return value, and writes them to <var>file</var>.
<p>SWIG can generate documentation strings in three formats, which are
selected via the command-line option <code>-procdocformat
@ -553,7 +514,7 @@ like this:
typemap argument <code>doc</code>. See <code>Lib/guile/typemaps.i</code> for
details.
<H2><a name="Guile_nn18"></a>23.9 Procedures with setters</H2>
<H2><a name="Guile_nn18"></a>24.10 Procedures with setters</H2>
<p>For global variables, SWIG creates a single wrapper procedure
@ -581,7 +542,7 @@ struct members, the procedures <code>(<var>struct</var>-<var>member</var>-get
pointer)</code> and <code>(<var>struct-member</var>-set pointer
value)</code> are <em>not</em> generated.
<H2><a name="Guile_nn19"></a>23.10 GOOPS Proxy Classes</H2>
<H2><a name="Guile_nn19"></a>24.11 GOOPS Proxy Classes</H2>
<p>SWIG can also generate classes and generic functions for use with
@ -589,10 +550,7 @@ Guile's Object-Oriented Programming System (GOOPS). GOOPS is a
sophisticated object system in the spirit of the Common Lisp Object
System (CLOS).
<p>GOOPS support is
only available with the new SCM interface (enabled with the
<code>-scm</code> command-line option of SWIG). To enable GOOPS
support, pass the <code>-proxy</code> argument to
<p>To enable GOOPS support, pass the <code>-proxy</code> argument to
swig. This will export the GOOPS wrapper definitions into the
<code><i>module</i>.scm</code> file in the directory specified by -outdir or the
current directory. GOOPS support requires either passive or module linkage.</p>
@ -730,7 +688,7 @@ Notice that &lt;Foo&gt; is used before it is defined. The fix is to just put th
<code>%import "foo.h"</code> before the <code>%inline</code> block.
</p>
<H3><a name="Guile_nn20"></a>23.10.1 Naming Issues</H3>
<H3><a name="Guile_nn20"></a>24.11.1 Naming Issues</H3>
<p>As you can see in the example above, there are potential naming conflicts. The default exported
@ -767,7 +725,7 @@ guile-modules. For example,</p>
(use-modules ((Test) #:renamer (symbol-prefix-proc 'goops:)))
</pre></div>
<H3><a name="Guile_nn21"></a>23.10.2 Linking</H3>
<H3><a name="Guile_nn21"></a>24.11.2 Linking</H3>
<p>The guile-modules generated above all need to be linked together. GOOPS support requires
@ -787,10 +745,10 @@ and might conflict with names from the GOOPS guile-module (see above). Pass the
argument to solve this problem. If the <code>-exportprimitive</code> option is passed to SWIG the
<code>(export ...)</code> code that would be exported into the scmstub file is exported at the bottom
of the generated GOOPS guile-module.
The <code>%goops</code> directive should contain code to load the .so library.
The <code>%goops</code> directive should contain code to load the shared library.
<div class="code"><pre>
%goops %{ (load-extension "./foo.so" "scm_init_my_modules_foo_module") %}
%goops %{ (load-extension "./libfoo.so" "scm_init_my_modules_foo_module") %}
</pre></div>
<p>
@ -802,7 +760,7 @@ Produces the following code at the top of the generated GOOPS guile-module
(define-module (my modules foo))
;; %goops directive goes here
(load-extension "./foo.so" "scm_init_my_modules_foo_module")
(load-extension "./libfoo.so" "scm_init_my_modules_foo_module")
(use-modules (oop goops) (Swig common))
</pre></div>
@ -810,7 +768,7 @@ Produces the following code at the top of the generated GOOPS guile-module
<li><p><b>Passive Linkage with -scmstub</b>: Here, the name of the scmstub file should be
<code>Module-primitive.scm</code> (with <i>primitive</i> replaced with whatever is given with the <code>-primsuffix</code>
argument. The code to load the <code>.so</code> library should be located in the <code>%scheme</code> directive,
argument. The code to load the shared library should be located in the <code>%scheme</code> directive,
which will then be added to the scmstub file.
SWIG will automatically generate the line <code>(use-modules (<i>Package</i> <i>Module-primitive</i>))</code>
into the GOOPS guile-module. So if <i>Module-primitive.scm</i> is on the autoload path for guile, the
@ -818,7 +776,7 @@ into the GOOPS guile-module. So if <i>Module-primitive.scm</i> is on the autolo
whatever code is needed to load the <i>Module-primitive.scm</i> file into guile.</p>
<div class="targetlang"><pre>
%scheme %{ (load-extension "./foo.so" "scm_init_my_modules_foo_module") %}
%scheme %{ (load-extension "./libfoo.so" "scm_init_my_modules_foo_module") %}
// only include the following definition if (my modules foo) cannot
// be loaded automatically
%goops %{
@ -851,7 +809,7 @@ SWIG will also automatically generate the line <code>(use-modules
directive should contain whatever code is needed to get that module loaded into guile.</p>
<div class="code"><pre>
%goops %{ (load-extension "./foo.so" "scm_init_my_modules_foo_module") %}
%goops %{ (load-extension "./libfoo.so" "scm_init_my_modules_foo_module") %}
</pre></div>
<p>
@ -862,7 +820,7 @@ Produces the following code at the top of the generated GOOPS guile-module
(define-module (my modules foo))
;; %goops directive goes here (if any)
(load-extension "./foo.so" "scm_init_my_modules_foo_module")
(load-extension "./libfoo.so" "scm_init_my_modules_foo_module")
(use-modules (oop goops) (Swig common))
(use-modules ((my modules foo-primitive) :renamer (symbol-prefix-proc

View file

@ -38,7 +38,7 @@
SWIG is a software development tool that simplifies the task of
interfacing different languages to C and C++ programs. In a
nutshell, SWIG is a compiler that takes C/C++ declarations and creates
the wrappers needed to access those declarations from other languages including
the wrappers needed to access those declarations from other languages
including Perl, Python, Tcl, Ruby, Guile, and Java. SWIG normally
requires no modifications to existing code and can often be used to
build a usable interface in only a few minutes. Possible applications
@ -49,7 +49,7 @@ of SWIG include:
<li>Building interpreted interfaces to existing C programs.
<li>Rapid prototyping and application development.
<li>Interactive debugging.
<li>Reengineering or refactoring of legacy software into a scripting language components.
<li>Reengineering or refactoring of legacy software into scripting language components.
<li>Making a graphical user interface (using Tk for example).
<li>Testing of C libraries and programs (using scripts).
<li>Building high performance C modules for scripting languages.
@ -98,7 +98,7 @@ of other libraries).
<li>Testing is time consuming (the compile/debug cycle).
<li>Not easy to reconfigure or customize without recompilation.
<li>Modularization can be tricky.
<li>Security concerns (buffer overflow for instance).
<li>Security concerns (buffer overflows for instance).
</ul>
<p>
To address these limitations, many programmers have arrived at the
@ -345,7 +345,7 @@ not only parses C++, it implements the full C++ type system and it is
able to understand C++ semantics. SWIG generates its wrappers with
full knowledge of this information. As a result, you will find SWIG
to be just as capable of dealing with nasty corner cases as it is in
wrapping simple C++ code. In fact, SWIG is able handle C++ code that
wrapping simple C++ code. In fact, SWIG is able to handle C++ code that
stresses the very limits of many C++ compilers.
@ -388,8 +388,8 @@ There is growing support for SWIG in some build tools, for example <a href="http
is a cross-platform, open-source build manager with built in support for SWIG. CMake can detect the SWIG executable
and many of the target language libraries for linking against.
CMake knows how to build shared libraries and loadable modules on many different operating systems.
This allows easy cross platform SWIG development. It also can generate the custom commands necessary for
driving SWIG from IDE's and makefiles. All of this can be done from a single cross platform input file.
This allows easy cross platform SWIG development. It can also generate the custom commands necessary for
driving SWIG from IDEs and makefiles. All of this can be done from a single cross platform input file.
The following example is a CMake input file for creating a python wrapper for the SWIG interface file, example.i:
</p>
@ -449,7 +449,7 @@ to work with complicated and unusual C/C++ applications.
<p>
Ironically, the freedom that SWIG provides is countered by an
extremely conservative approach to code generation. At it's core, SWIG
extremely conservative approach to code generation. At its core, SWIG
tries to distill even the most advanced C++ code down to a small
well-defined set of interface building techniques based on ANSI C
programming. Because of this, you will find that SWIG interfaces can

File diff suppressed because it is too large Load diff

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Library"></a>8 SWIG library</H1>
<H1><a name="Library"></a>9 SWIG library</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -31,6 +31,7 @@
<li><a href="#Library_std_vector">std::vector</a>
<li><a href="#Library_stl_exceptions">STL exceptions</a>
<li><a href="#Library_std_shared_ptr">shared_ptr smart pointer</a>
<li><a href="#Library_std_auto_ptr">auto_ptr smart pointer</a>
</ul>
<li><a href="#Library_nn16">Utility Libraries</a>
<ul>
@ -58,7 +59,7 @@ Alternative libraries provide similar functionality. Please read this chapter
carefully if you used the old libraries.
</p>
<H2><a name="Library_nn2"></a>8.1 The %include directive and library search path</H2>
<H2><a name="Library_nn2"></a>9.1 The %include directive and library search path</H2>
<p>
@ -66,18 +67,19 @@ Library files are included using the <tt>%include</tt> directive.
When searching for files, directories are searched in the following order:
</p>
<ul>
<ol>
<li>The current directory
<li>Directories specified with the <tt>-I</tt> command line option
<li>.<tt>/swig_lib</tt>
<li>SWIG library install location as reported by <tt>swig -swiglib</tt>, for example <tt>/usr/local/share/swig/1.3.30</tt>
<li>On Windows, a directory <tt>Lib</tt> relative to the location of <tt>swig.exe</tt> is also searched.
</ul>
</ol>
<p>
Within each directory, SWIG first looks for a subdirectory corresponding to a target language (e.g., <tt>python</tt>,
<tt>tcl</tt>, etc.). If found, SWIG will search the language specific directory first. This allows
for language-specific implementations of library files.
Within directories mentioned in points 3-5, SWIG first looks for a subdirectory
corresponding to a target language (e.g., <tt>python</tt>, <tt>tcl</tt>, etc.).
If found, SWIG will search the language specific directory first. This allows
for language-specific implementations of library files.
</p>
<p>
@ -89,7 +91,7 @@ Set the environment variable to hold an alternative library directory.
The directories that are searched are displayed when using <tt>-verbose</tt> commandline option.
</p>
<H2><a name="Library_nn3"></a>8.2 C Arrays and Pointers</H2>
<H2><a name="Library_nn3"></a>9.2 C Arrays and Pointers</H2>
<p>
@ -101,7 +103,7 @@ pointers as class-like objects. Since these functions provide direct access to
memory, their use is potentially unsafe and you should exercise caution.
</p>
<H3><a name="Library_nn4"></a>8.2.1 cpointer.i</H3>
<H3><a name="Library_nn4"></a>9.2.1 cpointer.i</H3>
<p>
@ -317,7 +319,7 @@ In this example, the function <tt>int_to_uint()</tt> would be used to cast type
<b>Note:</b> When working with simple pointers, typemaps can often be used to provide more seamless operation.
</p>
<H3><a name="Library_carrays"></a>8.2.2 carrays.i</H3>
<H3><a name="Library_carrays"></a>9.2.2 carrays.i</H3>
<p>
@ -495,7 +497,7 @@ you should consider using a special array object rather than a bare pointer.
used with types of <tt>char</tt> or <tt>char *</tt>.
</p>
<H3><a name="Library_nn6"></a>8.2.3 cmalloc.i</H3>
<H3><a name="Library_nn6"></a>9.2.3 cmalloc.i</H3>
<p>
@ -656,7 +658,7 @@ Now, in a script:
</pre>
</div>
<H3><a name="Library_nn7"></a>8.2.4 cdata.i</H3>
<H3><a name="Library_nn7"></a>9.2.4 cdata.i</H3>
<p>
@ -758,7 +760,7 @@ char *cdata_<em>name</em>(type* ptr, int nitems)
Clearly they are unsafe.
</p>
<H2><a name="Library_nn8"></a>8.3 C String Handling</H2>
<H2><a name="Library_nn8"></a>9.3 C String Handling</H2>
<p>
@ -778,7 +780,7 @@ morality. The modules in this section provide basic functionality
for manipulating raw C strings.
</p>
<H3><a name="Library_nn9"></a>8.3.1 Default string handling</H3>
<H3><a name="Library_nn9"></a>9.3.1 Default string handling</H3>
<p>
@ -819,7 +821,7 @@ interpreter and lead to a crash). Furthermore, the default behavior does
not work well with binary data. Instead, strings are assumed to be NULL-terminated.
</p>
<H3><a name="Library_nn10"></a>8.3.2 Passing binary data</H3>
<H3><a name="Library_nn10"></a>9.3.2 Passing binary data</H3>
<p>
@ -861,7 +863,7 @@ In the wrapper function, the passed string will be expanded to a pointer and len
The <tt>(char *STRING, int LENGTH)</tt> multi-argument typemap is also available in addition to <tt>(char *STRING, size_t LENGTH)</tt>.
</p>
<H3><a name="Library_nn11"></a>8.3.3 Using %newobject to release memory</H3>
<H3><a name="Library_nn11"></a>9.3.3 Using %newobject to release memory</H3>
<p>
@ -902,7 +904,7 @@ however, you may need to provide your own "newfree" typemap for other types.
See <a href="Customization.html#Customization_ownership">Object ownership and %newobject</a> for more details.
</p>
<H3><a name="Library_nn12"></a>8.3.4 cstring.i</H3>
<H3><a name="Library_nn12"></a>9.3.4 cstring.i</H3>
<p>
@ -1362,7 +1364,7 @@ structure or class instead.
</li>
</ul>
<H2><a name="Library_stl_cpp_library"></a>8.4 STL/C++ Library</H2>
<H2><a name="Library_stl_cpp_library"></a>9.4 STL/C++ Library</H2>
<p>
@ -1382,6 +1384,7 @@ The following table shows which C++ classes are supported and the equivalent SWI
<td><b>SWIG Interface library file</b></td>
</tr>
<tr> <td>std::auto_ptr</td> <td>memory</td> <td>std_auto_ptr.i</td> </tr>
<tr> <td>std::deque</td> <td>deque</td> <td>std_deque.i</td> </tr>
<tr> <td>std::list</td> <td>list</td> <td>std_list.i</td> </tr>
<tr> <td>std::map</td> <td>map</td> <td>std_map.i</td> </tr>
@ -1399,7 +1402,7 @@ Please look for the library files in the appropriate language library directory.
</p>
<H3><a name="Library_std_string"></a>8.4.1 std::string</H3>
<H3><a name="Library_std_string"></a>9.4.1 std::string</H3>
<p>
@ -1483,7 +1486,7 @@ void foo(string s, const String &amp;t); // std_string typemaps still applie
</pre>
</div>
<H3><a name="Library_std_vector"></a>8.4.2 std::vector</H3>
<H3><a name="Library_std_vector"></a>9.4.2 std::vector</H3>
<p>
@ -1662,7 +1665,7 @@ if you want to make their head explode.
details and the public API exposed to the interpreter vary.
</p>
<H3><a name="Library_stl_exceptions"></a>8.4.3 STL exceptions</H3>
<H3><a name="Library_stl_exceptions"></a>9.4.3 STL exceptions</H3>
<p>
@ -1712,13 +1715,28 @@ The <tt>%exception</tt> directive can be used by placing the following code befo
Any thrown STL exceptions will then be gracefully handled instead of causing a crash.
</p>
<H3><a name="Library_std_shared_ptr"></a>8.4.4 shared_ptr smart pointer</H3>
<H3><a name="Library_std_shared_ptr"></a>9.4.4 shared_ptr smart pointer</H3>
<p>
Some target languages have support for handling the widely used <tt>boost::shared_ptr</tt> smart pointer.
This smart pointer is also available as <tt>std::tr1::shared_ptr</tt> before it becomes fully standardized as <tt>std::shared_ptr</tt>.
The <tt>boost_shared_ptr.i</tt> library provides support for <tt>boost::shared_ptr</tt> and <tt>std_shared_ptr.i</tt> provides support for <tt>std::shared_ptr</tt>, but if the following macro is defined as shown, it can be used for <tt>std::tr1::shared_ptr</tt>:
Some target languages have support for handling the shared_ptr reference counted smart pointer.
This smart pointer is available in the standard C++11 library as <tt>std::shared_ptr</tt>.
It was also in TR1 as <tt>std::tr1::shared_ptr</tt> before it was fully standardized.
Support for the widely used <tt>boost::shared_ptr</tt> is also available.
</p>
<p>
In order to use <tt>std::shared_ptr</tt>, the <tt>std_shared_ptr.i</tt> library file should be included:
</p>
<div class="code">
<pre>
%include &lt;std_shared_ptr.i&gt;
</pre>
</div>
<p>
The pre-standard <tt>std::tr1::shared_ptr</tt> can be used by including the following macro before including the <tt>std_shared_ptr.i</tt> library file:
</p>
<div class="code">
@ -1728,6 +1746,16 @@ The <tt>boost_shared_ptr.i</tt> library provides support for <tt>boost::shared_p
</pre>
</div>
<p>
In order to use <tt>boost::shared_ptr</tt>, the <tt>boost_shared_ptr.i</tt> library file should be included:
</p>
<div class="code">
<pre>
%include &lt;boost_shared_ptr.i&gt;
</pre>
</div>
<p>
You can only use one of these variants of shared_ptr in your interface file at a time.
and all three variants must be used in conjunction with the <tt>%shared_ptr(T)</tt> macro,
@ -1871,10 +1899,64 @@ Adding the missing <tt>%shared_ptr</tt> macros will fix this:
</pre>
</div>
<H2><a name="Library_nn16"></a>8.5 Utility Libraries</H2>
<p>
<b>Note:</b> There is currently no support for <tt>%shared_ptr</tt> and the director feature.
</p>
<H3><a name="Library_nn17"></a>8.5.1 exception.i</H3>
<H3><a name="Library_std_auto_ptr"></a>9.4.5 auto_ptr smart pointer</H3>
<p>
While <tt>std::auto_ptr</tt> is deprecated in C++11, some existing code may
still be using it, so SWIG provides limited support for this class:
<tt>std_auto_ptr.i</tt> defines the typemaps which apply to the functions
returning objects of this type. Any other use of <tt>std_auto_ptr.i</tt> is not
directly supported.
</p>
<p>
A typical example of use would be
</p>
<div class="code">
<pre>
%include &lt;std_auto_ptr.i&gt;
%auto_ptr(Klass)
%inline %{
class Klass {
public:
// Factory function creating objects of this class:
static std::auto_ptr&lt;Klass&gt; Create(int value) {
return std::auto_ptr&lt;Klass&gt;(new Klass(value));
}
int getValue() const { return m_value; }
private:
DerivedIntValue(int value) : m_value(value) {}
int m_value;
};
%}
</pre>
</div>
<p>
The returned objects can be used naturally from the target language, e.g. from
C#:
</p>
<div class="targetlang">
<pre>
Klass k = Klass.Create(17);
int value = k.getValue();
</pre>
</div>
<H2><a name="Library_nn16"></a>9.5 Utility Libraries</H2>
<H3><a name="Library_nn17"></a>9.5.1 exception.i</H3>
<p>

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Lisp"></a>25 SWIG and Common Lisp</H1>
<H1><a name="Lisp"></a>26 SWIG and Common Lisp</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -41,7 +41,7 @@
Lisp, Common Foreign Function Interface(CFFI), CLisp and UFFI
foreign function interfaces.
</p>
<H2><a name="Lisp_nn2"></a>25.1 Allegro Common Lisp</H2>
<H2><a name="Lisp_nn2"></a>26.1 Allegro Common Lisp</H2>
<p>
@ -50,7 +50,7 @@
<a href="Allegrocl.html#Allegrocl">here</a>
</p>
<H2><a name="Lisp_nn3"></a>25.2 Common Foreign Function Interface(CFFI)</H2>
<H2><a name="Lisp_nn3"></a>26.2 Common Foreign Function Interface(CFFI)</H2>
<p>
@ -77,7 +77,7 @@ swig -cffi -module <i>module-name</i> <i>file-name</i>
files and the various things which you can do with them.
</p>
<H3><a name="Lisp_nn4"></a>25.2.1 Additional Commandline Options </H3>
<H3><a name="Lisp_nn4"></a>26.2.1 Additional Commandline Options </H3>
<p>
@ -118,11 +118,11 @@ swig -cffi -help
</table>
<H3><a name="Lisp_nn5"></a>25.2.2 Generating CFFI bindings</H3>
<H3><a name="Lisp_nn5"></a>26.2.2 Generating CFFI bindings</H3>
As we mentioned earlier the ideal way to use SWIG is to use interface
files. To illustrate the use of it, lets assume that we have a
files. To illustrate the use of it, let's assume that we have a
file named <i>test.h</i> with the following C code:
<div class="code"><pre>
@ -392,7 +392,7 @@ The feature <i>intern_function</i> ensures that all C names are
</pre></div>
<H3><a name="Lisp_nn6"></a>25.2.3 Generating CFFI bindings for C++ code</H3>
<H3><a name="Lisp_nn6"></a>26.2.3 Generating CFFI bindings for C++ code</H3>
<p>This feature to SWIG (for CFFI) is very new and still far from
@ -568,7 +568,7 @@ If you have any questions, suggestions, patches, etc., related to CFFI
module feel free to contact us on the SWIG mailing list, and
also please add a "[CFFI]" tag in the subject line.
<H3><a name="Lisp_nn7"></a>25.2.4 Inserting user code into generated files</H3>
<H3><a name="Lisp_nn7"></a>26.2.4 Inserting user code into generated files</H3>
<p>
@ -608,7 +608,7 @@ Note that the block <tt>%{ ... %}</tt> is effectively a shortcut for
</p>
<H2><a name="Lisp_nn8"></a>25.3 CLISP</H2>
<H2><a name="Lisp_nn8"></a>26.3 CLISP</H2>
<p>
@ -638,7 +638,7 @@ swig -clisp -module <i>module-name</i> <i>file-name</i>
interface file for the CLISP module. The CLISP module tries to
produce code which is both human readable and easily modifyable.
</p>
<H3><a name="Lisp_nn9"></a>25.3.1 Additional Commandline Options </H3>
<H3><a name="Lisp_nn9"></a>26.3.1 Additional Commandline Options </H3>
<p>
@ -671,7 +671,7 @@ and global variables will be created otherwise only definitions for<br/>
</table>
<H3><a name="Lisp_nn10"></a>25.3.2 Details on CLISP bindings</H3>
<H3><a name="Lisp_nn10"></a>26.3.2 Details on CLISP bindings</H3>
<p>
@ -795,7 +795,7 @@ struct bar {
</pre></div>
<H2><a name="Lisp_nn11"></a>25.4 UFFI </H2>
<H2><a name="Lisp_nn11"></a>26.4 UFFI </H2>
</body>

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Lua"></a>26 SWIG and Lua</H1>
<H1><a name="Lua"></a>27 SWIG and Lua</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -24,8 +24,11 @@
<li><a href="#Lua_nn9">Functions</a>
<li><a href="#Lua_nn10">Global variables</a>
<li><a href="#Lua_nn11">Constants and enums</a>
<ul>
<li><a href="#Lua_nn13">Constants/enums and classes/structures</a>
</ul>
<li><a href="#Lua_nn12">Pointers</a>
<li><a href="#Lua_nn13">Structures</a>
<li><a href="#Lua_structures">Structures</a>
<li><a href="#Lua_nn14">C++ classes</a>
<li><a href="#Lua_nn15">C++ inheritance</a>
<li><a href="#Lua_nn16">Pointers, references, values, and arrays</a>
@ -36,17 +39,23 @@
<li><a href="#Lua_nn21">C++ templates</a>
<li><a href="#Lua_nn22">C++ Smart Pointers</a>
<li><a href="#Lua_nn23">C++ Exceptions</a>
<li><a href="#Lua_namespaces">Namespaces </a>
<ul>
<li><a href="#Lua_nn27">Compatibility Note </a>
<li><a href="#Lua_nn29">Names </a>
<li><a href="#Lua_nn30">Inheritance </a>
</ul>
</ul>
<li><a href="#Lua_nn24">Typemaps</a>
<ul>
<li><a href="#Lua_nn25">What is a typemap?</a>
<li><a href="#Lua_nn26">Using typemaps</a>
<li><a href="#Lua_nn27">Typemaps and arrays</a>
<li><a href="#Lua_nn28">Typemaps and pointer-pointer functions</a>
<li><a href="#Lua_typemap_arrays">Typemaps and arrays</a>
<li><a href="#Lua_typemaps_ptr_ptr_functions">Typemaps and pointer-pointer functions</a>
</ul>
<li><a href="#Lua_nn29">Writing typemaps</a>
<li><a href="#Lua_writing_typemaps">Writing typemaps</a>
<ul>
<li><a href="#Lua_nn30">Typemaps you can write</a>
<li><a href="#Lua_typemaps_write">Typemaps you can write</a>
<li><a href="#Lua_nn31">SWIG's Lua-C API</a>
</ul>
<li><a href="#Lua_nn32">Customization of your Bindings</a>
@ -73,14 +82,14 @@ Lua is an extension programming language designed to support general procedural
eLua stands for Embedded Lua (can be thought of as a flavor of Lua) and offers the full implementation of the Lua programming language to the embedded world, extending it with specific features for efficient and portable software embedded development. eLua runs on smaller devices like microcontrollers and provides the full features of the regular Lua desktop version. More information on eLua can be found here: <a href="http://www.eluaproject.net">http://www.eluaproject.net</a>
</p>
<H2><a name="Lua_nn2"></a>26.1 Preliminaries</H2>
<H2><a name="Lua_nn2"></a>27.1 Preliminaries</H2>
<p>
The current SWIG implementation is designed to work with Lua 5.0.x, 5.1.x and 5.2.x. It should work with later versions of Lua, but certainly not with Lua 4.0 due to substantial API changes. It is possible to either static link or dynamic link a Lua module into the interpreter (normally Lua static links its libraries, as dynamic linking is not available on all platforms). SWIG also supports eLua and works with eLua 0.8. SWIG generated code for eLua has been tested on Stellaris ARM Cortex-M3 LM3S and Infineon TriCore.
The current SWIG implementation is designed to work with Lua 5.0.x, 5.1.x and 5.2.x. It should work with later versions of Lua, but certainly not with Lua 4.0 due to substantial API changes. It is possible to either static link or dynamic link a Lua module into the interpreter (normally Lua static links its libraries, as dynamic linking is not available on all platforms). SWIG also has support for eLua starting from eLua 0.8. Due to substantial changes between SWIG 2.x and SWIG 3.0 and unavailability of testing platform, eLua status was downgraded to 'experimental'.
</p>
<H2><a name="Lua_nn3"></a>26.2 Running SWIG</H2>
<H2><a name="Lua_nn3"></a>27.2 Running SWIG</H2>
<p>
@ -128,7 +137,7 @@ $ swig -lua -eluac example.i
The <tt>-elua</tt> option puts all the C function wrappers and variable get/set wrappers in rotables. It also generates a metatable which will control the access to these variables from eLua. It also offers a significant amount of module size compression. On the other hand, the <tt>-eluac</tt> option puts all the wrappers in a single rotable. With this option, no matter how huge the module, it will consume no additional microcontroller SRAM (crass compression). There is a catch though: Metatables are not generated with <tt>-eluac</tt>. To access any value from eLua, one must directly call the wrapper function associated with that value.
</p>
<H3><a name="Lua_commandline"></a>26.2.1 Additional command line options</H3>
<H3><a name="Lua_commandline"></a>27.2.1 Additional command line options</H3>
<p>
@ -159,9 +168,17 @@ swig -lua -help
<td>Do not register the module name as a global variable but return the module table from calls to require.</td>
</tr>
<tr>
<td>-no-old-metatable-bindings</td>
<td>Disable backward compatibility: old-style binding names generations and a few other things. Explanations are included in appropriate later sections.</td>
</tr>
<tr>
<td>-squash-bases</td>
<td>Squashes symbols from all inheritance tree of a given class into itself. Emulates pre-SWIG3.0 inheritance. Insignificantly speeds things up, but increases memory consumption.</td>
</tr>
</table>
<H3><a name="Lua_nn4"></a>26.2.2 Compiling and Linking and Interpreter</H3>
<H3><a name="Lua_nn4"></a>27.2.2 Compiling and Linking and Interpreter</H3>
<p>
@ -232,16 +249,16 @@ LUALIB_API int ( luaopen_mod )(lua_State *L );
More information on building and configuring eLua can be found here: <a href="http://www.eluaproject.net/doc/v0.8/en_building.html">http://www.eluaproject.net/doc/v0.8/en_building.html</a>
</p>
<H3><a name="Lua_nn5"></a>26.2.3 Compiling a dynamic module</H3>
<H3><a name="Lua_nn5"></a>27.2.3 Compiling a dynamic module</H3>
<p>
Most, but not all platforms support the dynamic loading of modules (Windows &amp; Linux do). Refer to the Lua manual to determine if your platform supports it. For compiling a dynamically loaded module the same wrapper can be used. The commands will be something like this:
Most, but not all platforms support the dynamic loading of modules (Windows &amp; Linux do). Refer to the Lua manual to determine if your platform supports it. For compiling a dynamically loaded module the same wrapper can be used. Assuming you have code you need to link to in a file called <tt>example.c</tt>, the commands will be something like this:
</p>
<div class="shell"><pre>
$ swig -lua example.i -o example_wrap.c
$ gcc -I/usr/include/lua -c example_wrap.c -o example_wrap.o
$ gcc -c example.c -o example.o
$ gcc -fPIC -I/usr/include/lua -c example_wrap.c -o example_wrap.o
$ gcc -fPIC -c example.c -o example.o
$ gcc -shared -I/usr/include/lua -L/usr/lib/lua example_wrap.o example.o -o example.so
</pre></div>
<p>
@ -300,7 +317,7 @@ Is quite obvious (Go back and consult the Lua documents on how to enable loadlib
<H3><a name="Lua_nn6"></a>26.2.4 Using your module</H3>
<H3><a name="Lua_nn6"></a>27.2.4 Using your module</H3>
<p>
@ -318,19 +335,19 @@ $ ./my_lua
&gt;
</pre></div>
<H2><a name="Lua_nn7"></a>26.3 A tour of basic C/C++ wrapping</H2>
<H2><a name="Lua_nn7"></a>27.3 A tour of basic C/C++ wrapping</H2>
<p>
By default, SWIG tries to build a very natural Lua interface to your C/C++ code. This section briefly covers the essential aspects of this wrapping.
</p>
<H3><a name="Lua_nn8"></a>26.3.1 Modules</H3>
<H3><a name="Lua_nn8"></a>27.3.1 Modules</H3>
<p>
The SWIG module directive specifies the name of the Lua module. If you specify `module example', then everything is wrapped into a Lua table 'example' containing all the functions and variables. When choosing a module name, make sure you don't use the same name as a built-in Lua command or standard module name.
</p>
<H3><a name="Lua_nn9"></a>26.3.2 Functions</H3>
<H3><a name="Lua_nn9"></a>27.3.2 Functions</H3>
<p>
@ -349,7 +366,10 @@ creates a built-in function <tt>example.fact(n)</tt> that works exactly like you
&gt;
</pre></div>
<p>
To avoid name collisions, SWIG create a Lua table which it keeps all the functions and global variables in. It is possible to copy the functions out of this and into the global environment with the following code. This can easily overwrite existing functions, so this must be used with care.
To avoid name collisions, SWIG create a Lua table which keeps all the functions, constants, classes and global variables in.
It is possible to copy the functions, constants and classes (but not variables) out of this and into the global environment with the following code.
This can easily overwrite existing functions, so this must be used with care.
This option is considered deprecated and will be removed in the near future.
</p>
<div class="targetlang"><pre>
&gt; for k,v in pairs(example) do _G[k]=v end
@ -368,7 +388,7 @@ It is also possible to rename the module with an assignment.
24
</pre></div>
<H3><a name="Lua_nn10"></a>26.3.3 Global variables</H3>
<H3><a name="Lua_nn10"></a>27.3.3 Global variables</H3>
<p>
@ -456,7 +476,7 @@ If you have used the <tt>-eluac</tt> option for your eLua module, you will have
In general, functions of the form <tt>"variable_get()"</tt> and <tt>"variable_set()"</tt> are automatically generated by SWIG for use with <tt>-eluac</tt>.
</p>
<H3><a name="Lua_nn11"></a>26.3.4 Constants and enums</H3>
<H3><a name="Lua_nn11"></a>27.3.4 Constants and enums</H3>
<p>
@ -490,7 +510,64 @@ If you're using eLua and have used <tt>-elua</tt> or <tt>-eluac</tt> to generate
&gt; print(example.const.SCONST)
Hello World
</pre></div>
<H3><a name="Lua_nn12"></a>26.3.5 Pointers</H3>
<H4><a name="Lua_nn13"></a>27.3.4.1 Constants/enums and classes/structures</H4>
<p>
Enums are exported into a class table. For example, given some enums:
</p>
<div class="code"><pre>%module example
enum Days { SUNDAY = 0, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY };
struct Test {
enum { TEST1 = 10, TEST2 = 20 };
#ifdef __cplusplus // There are no static members in C
static const int ICONST = 12;
#endif
};
</pre></div>
<p>
There is a slight difference in behaviour wrapping C and C++ code due to the different scoping rules of C and C++.
The wrapped C++ code is used as follows from Lua code:
</p>
<div class="targetlang"><pre>
&gt; print(example.SUNDAY)
0
&gt; print(example.Test.TEST1)
10
&gt; print(example.Test.ICONST)
12
</pre></div>
<p>Enums within a C struct are in the global namespace and are used as follows from Lua</p>
<div class="targetlang"><pre>
&gt; print(example.SUNDAY)
0
&gt; -- See the difference here
&gt; print(example.TEST1)
10
</pre></div>
<p>
<b>Compatibility Note:</b> Versions of SWIG prior to SWIG-3.0.0 did not generate the class table members above.
There is no change in the C wrappers, but
the following code was the only way to access these constants/enums when wrapping C++ member constants:
</p>
<div class="targetlang"><pre>
&gt; print(example.Test_TEST1)
10
&gt; print(example.Test_ICONST)
12
</pre></div>
<p>
The old-style bindings are still generated in addition to the new ones.
If the <tt>-no-old-metatable-bindings</tt> option is used, then these old-style bindings are not generated.
</p>
<p>
It is worth mentioning, that <tt>example.Test.TEST1</tt> and <tt>example.Test_TEST1</tt> are different entities and changing one does not change the other.
Given the fact that these are constantes and they are not supposed to be changed, it is up to you to avoid such issues.
</p>
<H3><a name="Lua_nn12"></a>27.3.5 Pointers</H3>
<p>
@ -528,7 +605,7 @@ Lua enforces the integrity of its userdata, so it is virtually impossible to cor
nil
</pre></div>
<H3><a name="Lua_nn13"></a>26.3.6 Structures</H3>
<H3><a name="Lua_structures"></a>27.3.6 Structures</H3>
<p>
@ -551,7 +628,7 @@ is used as follows:
</pre></div>
<p>
Similar access is provided for unions and the data members of C++ classes.<br>
C structures are created using a function <tt>new_Point()</tt>, but for C++ classes are created using just the name <tt>Point()</tt>.
C structures can be created using a function <tt>new_Point()</tt>, and both C structures and C++ classes can be created using just the name <tt>Point()</tt>.
</p>
<p>
If you print out the value of p in the above example, you will see something like this:
@ -632,7 +709,7 @@ For eLua with the <tt>-eluac</tt> option, structure manipulation has to be perfo
In general, functions of the form <tt>"new_struct()"</tt>, <tt>"struct_member_get()"</tt>, <tt>"struct_member_set()"</tt> and <tt>"free_struct()"</tt> are automatically generated by SWIG for each structure defined in C. (Please note: This doesn't apply for modules generated with the <tt>-elua</tt> option)
</p>
<H3><a name="Lua_nn14"></a>26.3.7 C++ classes</H3>
<H3><a name="Lua_nn14"></a>27.3.7 C++ classes</H3>
<p>
@ -676,12 +753,12 @@ public:
};
</pre></div>
<p>
In Lua, the static members can be accessed as follows:
In Lua, C++ static members can be accessed as follows:
</p>
<div class="code"><pre>
&gt; example.Spam_foo() -- calling Spam::foo()
&gt; a=example.Spam_bar -- reading Spam::bar
&gt; example.Spam_bar=b -- writing to Spam::bar
&gt; example.Spam.foo() -- calling Spam::foo()
&gt; a=example.Spam.bar -- reading Spam::bar
&gt; example.Spam.bar=b -- writing to Spam::bar
</pre></div>
<p>
It is not (currently) possible to access static members of an instance:
@ -692,7 +769,22 @@ It is not (currently) possible to access static members of an instance:
-- does NOT work
</pre></div>
<H3><a name="Lua_nn15"></a>26.3.8 C++ inheritance</H3>
<p>
<b>Compatibility Note:</b> In versions prior to SWIG-3.0.0 only the following names would work:
</p>
<div class="code"><pre>
&gt; example.Spam_foo() -- calling Spam::foo()
&gt; a=example.Spam_bar -- reading Spam::bar
&gt; example.Spam_bar=b -- writing to Spam::bar
</pre></div>
<p>
Both style names are generated by default now.
However, if the <tt>-no-old-metatable-bindings</tt> option is used, then the backward compatible names are not generated in addition to ordinary ones.
</p>
<H3><a name="Lua_nn15"></a>27.3.8 C++ inheritance</H3>
<p>
@ -717,7 +809,7 @@ then the function <tt>spam()</tt> accepts a Foo pointer or a pointer to any clas
<p>
It is safe to use multiple inheritance with SWIG.
</p>
<H3><a name="Lua_nn16"></a>26.3.9 Pointers, references, values, and arrays</H3>
<H3><a name="Lua_nn16"></a>27.3.9 Pointers, references, values, and arrays</H3>
<p>
@ -748,7 +840,7 @@ Foo spam7();
<p>
then all three functions will return a pointer to some Foo object. Since the third function (spam7) returns a value, newly allocated memory is used to hold the result and a pointer is returned (Lua will release this memory when the return value is garbage collected). The other two are pointers which are assumed to be managed by the C code and so will not be garbage collected.
</p>
<H3><a name="Lua_nn17"></a>26.3.10 C++ overloaded functions</H3>
<H3><a name="Lua_nn17"></a>27.3.10 C++ overloaded functions</H3>
<p>
@ -834,7 +926,7 @@ Please refer to the "SWIG and C++" chapter for more information about overloadin
<p>
Dealing with the Lua coercion mechanism, the priority is roughly (integers, floats, strings, userdata). But it is better to rename the functions rather than rely upon the ordering.
</p>
<H3><a name="Lua_nn18"></a>26.3.11 C++ operators</H3>
<H3><a name="Lua_nn18"></a>27.3.11 C++ operators</H3>
<p>
@ -898,7 +990,7 @@ The current list of operators which can be overloaded (and the alternative funct
<li><tt>__sub__</tt> operator-
<li><tt>__mul__</tt> operator *
<li><tt>__div__</tt> operator/
<li><tt>__neg__</tt> unary minus
<li><tt>__unm__</tt> unary minus
<li><tt>__call__</tt> operator<tt>()</tt> (often used in functor classes)
<li><tt>__pow__</tt> the exponential fn (no C++ equivalent, Lua uses <tt>^</tt>)
<li><tt>__concat__</tt> the concatenation operator (SWIG maps C++'s <tt>~</tt> to Lua's <tt>..</tt>)
@ -945,8 +1037,30 @@ It is also possible to overload the operator<tt>[]</tt>, but currently this cann
void __setitem__(int i,double d); // i is the index, d is the data
};
</pre></div>
<H3><a name="Lua_nn19"></a>26.3.12 Class extension with %extend</H3>
<p>
C++ operators are mapped to Lua predefined metafunctions. Class inherits from its bases the following list of metafunctions ( thus inheriting the folloging
operators and pseudo-operators):</p>
<ul>
<li><tt>__add__</tt>
<li><tt>__sub__</tt>
<li><tt>__mul__</tt>
<li><tt>__div__</tt>
<li><tt>__unm__</tt>
<li><tt>__mod__</tt>
<li><tt>__call__</tt>
<li><tt>__pow__</tt>
<li><tt>__concat__</tt>
<li><tt>__eq__</tt>
<li><tt>__lt__</tt>
<li><tt>__le__</tt>
<li><tt>__len__</tt>
<li><tt>__getitem__</tt>
<li><tt>__setitem__</tt>
<li><tt>__tostring</tt> used internally by Lua for tostring() function. __str__ is mapped to this function
</ul>
<p>No other lua metafunction is inherited. For example, __gc is not inherited and must be redefined in every class. <tt>__tostring</tt> is subject to a special handling. If absent in class and in class bases, a default one will be provided by SWIG</p>
</p>
<H3><a name="Lua_nn19"></a>27.3.12 Class extension with %extend</H3>
<p>
@ -981,7 +1095,7 @@ Now we extend it with some new code
return tmp;
}
bool operator==(const Complex&amp; c)
{ return ($self-&gt;re()==c.re() &amp;&amp; $self-&gt;im()==c.im();}
{ return ($self-&gt;re()==c.re() &amp;&amp; $self-&gt;im()==c.im());}
};
</pre></div>
<p>
@ -1002,7 +1116,7 @@ true
Extend works with both C and C++ code, on classes and structs. It does not modify the underlying object in any way---the extensions only show up in the Lua interface. The only item to take note of is the code has to use the '$self' instead of 'this', and that you cannot access protected/private members of the code (as you are not officially part of the class).
</p>
<H3><a name="Lua_nn20"></a>26.3.13 Using %newobject to release memory</H3>
<H3><a name="Lua_nn20"></a>27.3.13 Using %newobject to release memory</H3>
<p> If you have a function that allocates memory like this,</p>
@ -1026,7 +1140,7 @@ char *foo();
</div>
<p> This will release the allocated memory.</p>
<H3><a name="Lua_nn21"></a>26.3.14 C++ templates</H3>
<H3><a name="Lua_nn21"></a>27.3.14 C++ templates</H3>
<p>
@ -1061,7 +1175,7 @@ In Lua:
<p>
Obviously, there is more to template wrapping than shown in this example. More details can be found in the SWIG and C++ chapter. Some more complicated examples will appear later.
</p>
<H3><a name="Lua_nn22"></a>26.3.15 C++ Smart Pointers</H3>
<H3><a name="Lua_nn22"></a>27.3.15 C++ Smart Pointers</H3>
<p>
@ -1113,7 +1227,7 @@ If you ever need to access the underlying pointer returned by <tt>operator-&gt;(
&gt; f = p:__deref__() -- Returns underlying Foo *
</pre></div>
<H3><a name="Lua_nn23"></a>26.3.16 C++ Exceptions</H3>
<H3><a name="Lua_nn23"></a>27.3.16 C++ Exceptions</H3>
<p>
@ -1256,13 +1370,164 @@ and the "<a href="Customization.html#Customization_exception">Exception handling
add exception specification to functions or globally (respectively).
</p>
<H3><a name="Lua_namespaces"></a>27.3.17 Namespaces </H3>
<H2><a name="Lua_nn24"></a>26.4 Typemaps</H2>
<p>
Since SWIG-3.0.0 C++ namespaces are supported via the %nspace feature.
</p>
<p> Namespaces are mapped into Lua tables. Each of those tables contains names that were defined within appropriate namespace. Namespaces structure (a.k.a nested namespaces) is preserved. Consider the following C++ code:
</p>
<div class="code"><pre>%module example
%nspace MyWorld::Nested::Dweller;
%nspace MyWorld::World;
int module_function() { return 7; }
int module_variable = 9;
namespace MyWorld {
class World {
public:
World() : world_max_count(9) {}
int create_world() { return 17; }
const int world_max_count; // = 9
};
namespace Nested {
class Dweller {
public:
enum Gender { MALE = 0, FEMALE = 1 };
static int count() { return 19; }
};
}
}
</pre></div>
<p>
Now, from Lua usage is as follows:
</p>
<div class="targetlang"><pre>
&gt; print(example.module_function())
7
&gt; print(example.module_variable)
9
&gt; print(example.MyWorld.World():create_world())
17
&gt; print(example.MyWorld.World.world_max_count)
9
&gt; print(example.MyWorld.Nested.Dweller.MALE)
0
&gt; print(example.MyWorld.Nested.Dweller.count())
19
&gt;
</pre></div>
<H4><a name="Lua_nn27"></a>27.3.17.1 Compatibility Note </H4>
<p>
If SWIG is running in a backwards compatible way, i.e. without the <tt>-no-old-metatable-bindings</tt> option, then additional old-style names are generated (notice the underscore):
</p>
<div class="targetlang"><pre>
9
&gt; print(example.MyWorld.Nested.Dweller_MALE)
0
&gt; print(example.MyWorld.Nested.Dweller_count())
11
&gt;
</pre></div>
<H4><a name="Lua_nn29"></a>27.3.17.2 Names </H4>
<p> If SWIG is launched without <tt>-no-old-metatable-bindings</tt> option, then it enters backward-compatible mode. While in this mode, it tries
to generate additional names for static functions, class static constants and class enums.
Those names are in a form <tt>$classname_$symbolname</tt> and are added to the scope surrounding the class.
If %nspace is enabled, then class namespace is taken as scope. If there is no namespace, or %nspace is disabled,
then module is considered a class namespace.</p>
<p> Consider the following C++ code </p>
<div class="code"><pre>%module example
%nspace MyWorld::Test;
namespace MyWorld {
class Test {
public:
enum { TEST1 = 10, TEST2 }
static const int ICONST = 12;
};
class Test2 {
public:
enum { TEST3 = 20, TEST4 }
static const int ICONST2 = 23;
}
</pre></div>
<p> When in backward compatible mode, in addition to the usual names, the following ones will be generated (notice the underscore):</p>
<div class="targetlang"><pre>
9
&gt; print(example.MyWorld.Test_TEST1) -- Test has %nspace enabled
10
&gt; print(example.MyWorld.Test_ICONST) -- Test has %nspace enabled
12
&gt; print(example.Test2_TEST3) -- Test2 doesn't have %nspace enabled
20
&gt; print(example.Test2_ICONST2) -- Test2 doesn't have %nspace enabled
23
&gt;
</pre></div>
<p> There is a slight difference with enums when in C mode. As per C standard, enums from C structures are exported to
surrounding scope without any prefixing. Pretending that Test2 is a struct, not class, that would be:</p>
<div class="targetlang"><pre>
&gt; print(example.TEST3) -- NOT Test2_TEST3
20
&gt;
</pre></div>
<H4><a name="Lua_nn30"></a>27.3.17.3 Inheritance </H4>
<p> The internal organization of inheritance has changed.
Consider the following C++ code:</p>
<div class="code"><pre>%module example
class Base {
public:
int base_func()
};
class Derived : public Base {
public:
int derived_func()
}
</pre></div>
<p>Lets assume for a moment that class member functions are stored in <tt>.fn</tt> table. Previously, when classes
were exported to Lua during module initialization, for every derived class all service tables <tt>ST(i.e. ".fn")</tt>
were squashed and added to corresponding derived class <tt>ST</tt>: Everything from <tt>.fn</tt> table of class Base
was copied to <tt>.fn</tt> table of class Derived and so on. This was a recursive procedure, so in the end the whole
inheritance tree of derived class was squashed into derived class. </p>
<p> That means that any changes done to class Base after module initialization wouldn't affect class Derived:</p>
<div class="targetlang"><pre>
base = example.Base()
der = example.Derived()
&gt; print(base.base_func)
function: 0x1367940
&gt; getmetatable(base)[".fn"].new_func = function (x) return x -- Adding new function to class Base (to class, not to an instance!)
&gt; print(base.new_func) -- Checking this function
function
&gt; print(der.new_func) -- Wouldn't work. Derived doesn't check Base any more.
nil
&gt;
</pre></div>
<p> This behaviour was changed. Now unless -squash-bases option is provided, Derived store a list of it's bases and if some symbol is not found in it's own service tables
then its bases are searched for it. Option -squash-bases will effectively return old behaviour.
<div class="targetlang"><pre>
&gt; print(der.new_func) -- Now it works
function
&gt;
</pre></div>
<H2><a name="Lua_nn24"></a>27.4 Typemaps</H2>
<p>This section explains what typemaps are and how to use them. The default wrapping behaviour of SWIG is enough in most cases. However sometimes SWIG may need a little additional assistance to know which typemap to apply to provide the best wrapping. This section will be explaining how to use typemaps to best effect</p>
<H3><a name="Lua_nn25"></a>26.4.1 What is a typemap?</H3>
<H3><a name="Lua_nn25"></a>27.4.1 What is a typemap?</H3>
<p>A typemap is nothing more than a code generation rule that is attached to a specific C datatype. For example, to convert integers from Lua to C, you might define a typemap like this:</p>
@ -1290,7 +1555,7 @@ Received an integer : 6
720
</pre></div>
<H3><a name="Lua_nn26"></a>26.4.2 Using typemaps</H3>
<H3><a name="Lua_nn26"></a>27.4.2 Using typemaps</H3>
<p>There are many ready written typemaps built into SWIG for all common types (int, float, short, long, char*, enum and more), which SWIG uses automatically, with no effort required on your part.</p>
@ -1343,7 +1608,7 @@ void swap(int *sx, int *sy);
<p>Note: C++ references must be handled exactly the same way. However SWIG will automatically wrap a <tt>const int&amp;</tt> as an input parameter (since that it obviously input).</p>
<H3><a name="Lua_nn27"></a>26.4.3 Typemaps and arrays</H3>
<H3><a name="Lua_typemap_arrays"></a>27.4.3 Typemaps and arrays</H3>
<p>Arrays present a challenge for SWIG, because like pointers SWIG does not know whether these are input or output values, nor
@ -1359,7 +1624,7 @@ extern void sort_double(double* arr, int len);
to create an array in C/C++ then this can be filled within Lua and passed into the function. It works, but it's a bit tedious.
More details can be found in the <a href="Library.html#Library_carrays">carrays.i</a> documentation.</p>
<p>The second and more intuitive way, would be to pass a Lua table directly into the function, and have SWIG automatically convert between Lua-table and C-array. Within the <tt>&lt;typemaps.i&gt;</tt> file there are typemaps ready written to perform this task. To use them is again a matter of using %appy in the correct manner.</p>
<p>The second and more intuitive way, would be to pass a Lua table directly into the function, and have SWIG automatically convert between Lua-table and C-array. Within the <tt>&lt;typemaps.i&gt;</tt> file there are typemaps ready written to perform this task. To use them is again a matter of using %apply in the correct manner.</p>
<p>The wrapper file below, shows both the use of carrays as well as the use of the typemap to wrap arrays. </p>
@ -1407,7 +1672,7 @@ and Lua tables to be 1..N, (the indexing follows the norm for the language). In
<p>Note: SWIG also can support arrays of pointers in a similar manner.</p>
<H3><a name="Lua_nn28"></a>26.4.4 Typemaps and pointer-pointer functions</H3>
<H3><a name="Lua_typemaps_ptr_ptr_functions"></a>27.4.4 Typemaps and pointer-pointer functions</H3>
<p>Several C++ libraries use a pointer-pointer functions to create its objects. These functions require a pointer to a pointer which is then filled with the pointer to the new object. Microsoft's COM and DirectX as well as many other libraries have this kind of function. An example is given below:</p>
@ -1441,7 +1706,7 @@ int Create_Math(iMath** pptr); // its creator (assume it mallocs)
ptr=nil -- the iMath* will be GC'ed as normal
</pre></div>
<H2><a name="Lua_nn29"></a>26.5 Writing typemaps</H2>
<H2><a name="Lua_writing_typemaps"></a>27.5 Writing typemaps</H2>
<p>This section describes how you can modify SWIG's default wrapping behavior for various C/C++ datatypes using the <tt>%typemap</tt> directive. This is an advanced topic that assumes familiarity with the Lua C API as well as the material in the "<a href="Typemaps.html#Typemaps">Typemaps</a>" chapter.</p>
@ -1450,7 +1715,7 @@ ptr=nil -- the iMath* will be GC'ed as normal
<p>Before proceeding, you should read the previous section on using typemaps, and look at the existing typemaps found in luatypemaps.swg and typemaps.i. These are both well documented and fairly easy to read. You should not attempt to write your own typemaps until you have read and can understand both of these files (they may well also give you an idea to base your work on).</p>
<H3><a name="Lua_nn30"></a>26.5.1 Typemaps you can write</H3>
<H3><a name="Lua_typemaps_write"></a>27.5.1 Typemaps you can write</H3>
<p>There are many different types of typemap that can be written, the full list can be found in the "<a href="Typemaps.html#Typemaps">Typemaps</a>" chapter. However the following are the most commonly used ones.</p>
@ -1463,7 +1728,7 @@ ptr=nil -- the iMath* will be GC'ed as normal
(the syntax for the typecheck is different from the typemap, see typemaps for details).</li>
</ul>
<H3><a name="Lua_nn31"></a>26.5.2 SWIG's Lua-C API</H3>
<H3><a name="Lua_nn31"></a>27.5.2 SWIG's Lua-C API</H3>
<p>This section explains the SWIG specific Lua-C API. It does not cover the main Lua-C api, as this is well documented and not worth covering.</p>
@ -1512,7 +1777,7 @@ This macro, when called within the context of a SWIG wrapped function, will disp
<div class="indent">
Similar to SWIG_fail_arg, except that it will display the swig_type_info information instead.</div>
<H2><a name="Lua_nn32"></a>26.6 Customization of your Bindings</H2>
<H2><a name="Lua_nn32"></a>27.6 Customization of your Bindings</H2>
<p>
@ -1521,7 +1786,7 @@ This section covers adding of some small extra bits to your module to add the la
<H3><a name="Lua_nn33"></a>26.6.1 Writing your own custom wrappers</H3>
<H3><a name="Lua_nn33"></a>27.6.1 Writing your own custom wrappers</H3>
<p>
@ -1540,7 +1805,7 @@ int native_function(lua_State*L) // my native code
The <tt>%native</tt> directive in the above example, tells SWIG that there is a function <tt>int native_function(lua_State*L);</tt> which is to be added into the module under the name '<tt>my_func</tt>'. SWIG will not add any wrapper for this function, beyond adding it into the function table. How you write your code is entirely up to you.
</p>
<H3><a name="Lua_nn34"></a>26.6.2 Adding additional Lua code</H3>
<H3><a name="Lua_nn34"></a>27.6.2 Adding additional Lua code</H3>
<p>
@ -1578,7 +1843,7 @@ Good uses for this feature is adding of new code, or writing helper functions to
See Examples/lua/arrays for an example of this code.
</p>
<H2><a name="Lua_nn35"></a>26.7 Details on the Lua binding</H2>
<H2><a name="Lua_nn35"></a>27.7 Details on the Lua binding</H2>
<p>
@ -1589,7 +1854,7 @@ See Examples/lua/arrays for an example of this code.
</i>
</p>
<H3><a name="Lua_nn36"></a>26.7.1 Binding global data into the module.</H3>
<H3><a name="Lua_nn36"></a>27.7.1 Binding global data into the module.</H3>
<p>
@ -1649,7 +1914,7 @@ end
<p>
That way when you call '<tt>a=example.Foo</tt>', the interpreter looks at the table 'example' sees that there is no field 'Foo' and calls __index. This will in turn check in '.get' table and find the existence of 'Foo' and then return the value of the C function call 'Foo_get()'. Similarly for the code '<tt>example.Foo=10</tt>', the interpreter will check the table, then call the __newindex which will then check the '.set' table and call the C function 'Foo_set(10)'.
</p>
<H3><a name="Lua_nn37"></a>26.7.2 Userdata and Metatables</H3>
<H3><a name="Lua_nn37"></a>27.7.2 Userdata and Metatables</H3>
<p>
@ -1729,7 +1994,7 @@ Note: Both the opaque structures (like the FILE*) and normal wrapped classes/str
<p>
Note: Operator overloads are basically done in the same way, by adding functions such as '__add' &amp; '__call' to the class' metatable. The current implementation is a bit rough as it will add any member function beginning with '__' into the metatable too, assuming its an operator overload.
</p>
<H3><a name="Lua_nn38"></a>26.7.3 Memory management</H3>
<H3><a name="Lua_nn38"></a>27.7.3 Memory management</H3>
<p>

View file

@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body bgcolor="#FFFFFF">
<H1><a name="Modula3"></a>27 SWIG and Modula-3</H1>
<H1><a name="Modula3"></a>28 SWIG and Modula-3</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -45,7 +45,7 @@
<p>
This chapter describes SWIG's support of
This chapter describes SWIG's support for
<a href="http://modula3.org/">Modula-3</a>.
You should be familiar with the
<a href="SWIG.html#SWIG">basics</a>
@ -54,7 +54,7 @@ especially
<a href="Typemaps.html#Typemaps">typemaps</a>.
</p>
<H2><a name="Modula3_modula3_overview"></a>27.1 Overview</H2>
<H2><a name="Modula3_modula3_overview"></a>28.1 Overview</H2>
<p>
@ -84,7 +84,7 @@ FFTW
</li>
</ol>
<H3><a name="Modula3_motivation"></a>27.1.1 Motivation</H3>
<H3><a name="Modula3_motivation"></a>28.1.1 Motivation</H3>
<p>
@ -109,7 +109,7 @@ into exceptions.
<p>
If the library API is ill designed
writing appropriate typemaps can be still time-consuming.
writing appropriate typemaps can still be time-consuming.
E.g. C programmers are very creative to work-around
missing data types like (real) enumerations and sets.
You should turn such work-arounds back to the Modula-3 way
@ -120,21 +120,21 @@ otherwise you lose static safety and consistency.
Without SWIG you would probably never consider trying to call C++ libraries
from Modula-3, but with SWIG this is becomes feasible.
SWIG can generate C wrappers to C++ functions and object methods
that may throw exceptions, and then wrap these C wrappers for Module-3.
that may throw exceptions, and then wrap these C wrappers for Modula-3.
To make it complete you can then hide the C interface with Modula-3 classes and
exceptions.
</p>
<p>
SWIG allows you to call C and C++ libraries from Modula-3 (even with call back
functions), but it doesn't allow you to easily integrate a Module-3 module into
functions), but it doesn't allow you to easily integrate a Modula-3 module into
a C/C++ project.
</p>
<H2><a name="Modula3_conception"></a>27.2 Conception</H2>
<H2><a name="Modula3_conception"></a>28.2 Conception</H2>
<H3><a name="Modula3_cinterface"></a>27.2.1 Interfaces to C libraries</H3>
<H3><a name="Modula3_cinterface"></a>28.2.1 Interfaces to C libraries</H3>
<p>
@ -283,7 +283,7 @@ and the principal type must be renamed (<tt>%typemap</tt>).
</p>
<H3><a name="Modula3_cppinterface"></a>27.2.2 Interfaces to C++ libraries</H3>
<H3><a name="Modula3_cppinterface"></a>28.2.2 Interfaces to C++ libraries</H3>
<p>
@ -384,10 +384,10 @@ There is no C++ library I wrote a SWIG interface for,
so I'm not sure if this is possible or sensible, yet.
</p>
<H2><a name="Modula3_preliminaries"></a>27.3 Preliminaries</H2>
<H2><a name="Modula3_preliminaries"></a>28.3 Preliminaries</H2>
<H3><a name="Modula3_compilers"></a>27.3.1 Compilers</H3>
<H3><a name="Modula3_compilers"></a>28.3.1 Compilers</H3>
<p>
@ -400,7 +400,7 @@ For testing examples I use Critical Mass cm3.
</p>
<H3><a name="Modula3_commandline"></a>27.3.2 Additional Commandline Options</H3>
<H3><a name="Modula3_commandline"></a>28.3.2 Additional Commandline Options</H3>
<p>
@ -477,10 +477,10 @@ Instead generate templates for some basic typemaps.
</tr>
</table>
<H2><a name="Modula3_typemaps"></a>27.4 Modula-3 typemaps</H2>
<H2><a name="Modula3_typemaps"></a>28.4 Modula-3 typemaps</H2>
<H3><a name="Modula3_inoutparam"></a>27.4.1 Inputs and outputs</H3>
<H3><a name="Modula3_inoutparam"></a>28.4.1 Inputs and outputs</H3>
<p>
@ -694,7 +694,7 @@ consist of the following parts:
</table>
<H3><a name="Modula3_ordinals"></a>27.4.2 Subranges, Enumerations, Sets</H3>
<H3><a name="Modula3_ordinals"></a>28.4.2 Subranges, Enumerations, Sets</H3>
<p>
@ -746,7 +746,7 @@ that I'd like to automate.
</p>
<H3><a name="Modula3_class"></a>27.4.3 Objects</H3>
<H3><a name="Modula3_class"></a>28.4.3 Objects</H3>
<p>
@ -759,7 +759,7 @@ is not really useful, yet.
</p>
<H3><a name="Modula3_imports"></a>27.4.4 Imports</H3>
<H3><a name="Modula3_imports"></a>28.4.4 Imports</H3>
<p>
@ -792,7 +792,7 @@ IMPORT M3toC;
</pre></div>
<H3><a name="Modula3_exceptions"></a>27.4.5 Exceptions</H3>
<H3><a name="Modula3_exceptions"></a>28.4.5 Exceptions</H3>
<p>
@ -816,7 +816,7 @@ you should declare
<tt>%typemap("m3wrapinconv:throws") blah * %{OSError.E%}</tt>.
</p>
<H3><a name="Modula3_typemap_example"></a>27.4.6 Example</H3>
<H3><a name="Modula3_typemap_example"></a>28.4.6 Example</H3>
<p>
@ -863,10 +863,10 @@ where almost everything is generated by a typemap:
</pre></div>
<H2><a name="Modula3_hints"></a>27.5 More hints to the generator</H2>
<H2><a name="Modula3_hints"></a>28.5 More hints to the generator</H2>
<H3><a name="Modula3_features"></a>27.5.1 Features</H3>
<H3><a name="Modula3_features"></a>28.5.1 Features</H3>
<table border summary="Modula-3 features">
@ -903,7 +903,7 @@ where almost everything is generated by a typemap:
</tr>
</table>
<H3><a name="Modula3_pragmas"></a>27.5.2 Pragmas</H3>
<H3><a name="Modula3_pragmas"></a>28.5.2 Pragmas</H3>
<table border summary="Modula-3 pragmas">
@ -926,7 +926,7 @@ where almost everything is generated by a typemap:
</tr>
</table>
<H2><a name="Modula3_remarks"></a>27.6 Remarks</H2>
<H2><a name="Modula3_remarks"></a>28.6 Remarks</H2>
<ul>

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Modules"></a>15 Working with Modules</H1>
<H1><a name="Modules"></a>16 Working with Modules</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -23,7 +23,7 @@
<H2><a name="Modules_introduction"></a>15.1 Modules Introduction</H2>
<H2><a name="Modules_introduction"></a>16.1 Modules Introduction</H2>
<p>
@ -77,7 +77,7 @@ where you want to create a collection of modules.
Each module in the collection is created via separate invocations of SWIG.
</p>
<H2><a name="Modules_nn1"></a>15.2 Basics</H2>
<H2><a name="Modules_nn1"></a>16.2 Basics</H2>
<p>
@ -130,7 +130,7 @@ public:
<p>To create the wrapper properly, module <tt>derived_module</tt> needs to know about the
<tt>base</tt> class and that its interface is covered in another module. The
line <tt>%import "base_module.i"</tt> lets SWIG know exactly that. Oftentimes
line <tt>%import "base_module.i"</tt> lets SWIG know exactly that. Often
the <tt>.h</tt> file is passed to <tt>%import</tt> instead of the <tt>.i</tt>,
which unfortunately doesn't work for all language modules. For example, Python requires the
name of module that the base class exists in so that the proxy classes can fully inherit the
@ -176,7 +176,7 @@ in parallel from multiple threads as SWIG provides no locking - for more on that
issue, read on.
</p>
<H2><a name="Modules_nn2"></a>15.3 The SWIG runtime code</H2>
<H2><a name="Modules_nn2"></a>16.3 The SWIG runtime code</H2>
<p>
@ -242,7 +242,7 @@ can peacefully coexist. So the type structures are separated by the
is empty. Only modules compiled with the same pair will share type information.
</p>
<H2><a name="Modules_external_run_time"></a>15.4 External access to the runtime</H2>
<H2><a name="Modules_external_run_time"></a>16.4 External access to the runtime</H2>
<p>As described in <a href="Typemaps.html#Typemaps_runtime_type_checker">The run-time type checker</a>,
@ -279,7 +279,7 @@ SWIG_TYPE_TABLE to be the same as the module whose types you are trying to
access.
</p>
<H2><a name="Modules_nn4"></a>15.5 A word of caution about static libraries</H2>
<H2><a name="Modules_nn4"></a>16.5 A word of caution about static libraries</H2>
<p>
@ -290,7 +290,7 @@ into it. This is very often <b>NOT</b> what you want and it can lead to unexpect
behavior. When working with dynamically loadable modules, you should try to work exclusively with shared libraries.
</p>
<H2><a name="Modules_nn5"></a>15.6 References</H2>
<H2><a name="Modules_nn5"></a>16.6 References</H2>
<p>
@ -298,7 +298,7 @@ Due to the complexity of working with shared libraries and multiple modules, it
an outside reference. John Levine's "Linkers and Loaders" is highly recommended.
</p>
<H2><a name="Modules_nn6"></a>15.7 Reducing the wrapper file size</H2>
<H2><a name="Modules_nn6"></a>16.7 Reducing the wrapper file size</H2>
<p>

View file

@ -8,7 +8,7 @@
<body bgcolor="#ffffff">
<H1><a name="Mzscheme"></a>28 SWIG and MzScheme/Racket</H1>
<H1><a name="Mzscheme"></a>29 SWIG and MzScheme/Racket</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -24,7 +24,7 @@
<p>
This section contains information on SWIG's support of Racket, formally known as MzScheme.
<H2><a name="MzScheme_nn2"></a>28.1 Creating native structures</H2>
<H2><a name="MzScheme_nn2"></a>29.1 Creating native structures</H2>
<p>
@ -65,7 +65,7 @@ Then in scheme, you can use regular struct access procedures like
</pre>
</div>
<H2><a name="MzScheme_simple"></a>28.2 Simple example</H2>
<H2><a name="MzScheme_simple"></a>29.2 Simple example</H2>
<p>
@ -166,7 +166,7 @@ Some points of interest:
<li> The above requests mzc to create an extension using the CGC garbage-collector. The alternative -- the 3m collector -- has generally better performance, but work is still required for SWIG to emit code which is compatible with it.
</ul>
<H2><a name="MzScheme_external_docs"></a>28.3 External documentation</H2>
<H2><a name="MzScheme_external_docs"></a>29.3 External documentation</H2>
<p>

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<a name="n1"></a>
<H1><a name="Ocaml"></a>29 SWIG and Ocaml</H1>
<H1><a name="Ocaml"></a>30 SWIG and Ocaml</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -80,7 +80,7 @@ If you're not familiar with the Objective Caml language, you can visit
<a href="http://www.ocaml.org/">The Ocaml Website</a>.
</p>
<H2><a name="Ocaml_nn2"></a>29.1 Preliminaries</H2>
<H2><a name="Ocaml_nn2"></a>30.1 Preliminaries</H2>
<p>
@ -99,7 +99,7 @@ file Examples/Makefile illustrate how to compile and link SWIG modules that
will be loaded dynamically. This has only been tested on Linux so far.
</p>
<H3><a name="Ocaml_nn3"></a>29.1.1 Running SWIG</H3>
<H3><a name="Ocaml_nn3"></a>30.1.1 Running SWIG</H3>
<p>
@ -122,11 +122,11 @@ you will compile the file <tt>example_wrap.c</tt> with <tt>ocamlc</tt> or
the resulting .ml and .mli files as well, and do the final link with -custom
(not needed for native link). </p>
<H3><a name="Ocaml_nn4"></a>29.1.2 Compiling the code</H3>
<H3><a name="Ocaml_nn4"></a>30.1.2 Compiling the code</H3>
<p>
The O'Caml SWIG module now requires you to compile a module (<tt>Swig</tt>)
The OCaml SWIG module now requires you to compile a module (<tt>Swig</tt>)
separately. In addition to aggregating common SWIG functionality, the Swig
module contains the data structure that represents C/C++ values. This allows
easier data sharing between modules if two or more are combined, because
@ -158,12 +158,12 @@ the user more freedom with respect to custom typing.
</pre>
</div>
<H3><a name="Ocaml_nn5"></a>29.1.3 The camlp4 module</H3>
<H3><a name="Ocaml_nn5"></a>30.1.3 The camlp4 module</H3>
<p>
The camlp4 module (swigp4.ml -&gt; swigp4.cmo) contains a simple rewriter which
makes C++ code blend more seamlessly with objective caml code. It's use is
makes C++ code blend more seamlessly with objective caml code. Its use is
optional, but encouraged. The source file is included in the Lib/ocaml
directory of the SWIG source distribution. You can checkout this file with
<tt>"swig -ocaml -co swigp4.ml"</tt>. You should compile the file with
@ -234,7 +234,7 @@ let b = C_string (getenv "PATH")
</td></tr>
</table>
<H3><a name="Ocaml_nn6"></a>29.1.4 Using your module</H3>
<H3><a name="Ocaml_nn6"></a>30.1.4 Using your module</H3>
<p>
@ -248,7 +248,7 @@ When linking any ocaml bytecode with your module, use the -custom
option is not needed when you build native code.
</p>
<H3><a name="Ocaml_nn7"></a>29.1.5 Compilation problems and compiling with C++</H3>
<H3><a name="Ocaml_nn7"></a>30.1.5 Compilation problems and compiling with C++</H3>
<p>
@ -259,7 +259,7 @@ liberal with pointer types may not compile under the C++ compiler.
Most code meant to be compiled as C++ will not have problems.
</p>
<H2><a name="Ocaml_nn8"></a>29.2 The low-level Ocaml/C interface</H2>
<H2><a name="Ocaml_nn8"></a>30.2 The low-level Ocaml/C interface</H2>
<p>
@ -310,7 +310,7 @@ type c_obj =
</li>
<li>caml_val_ptr receives a void * and returns a c_obj.</li>
<li>caml_val_bool receives a C int and returns a c_obj representing
it's bool value.</li>
its bool value.</li>
<li>caml_val_(u)?(char|short|int|long|float|double) receives an
appropriate C value and returns a c_obj representing it.</li>
<li>caml_val_string receives a char * and returns a string value.</li>
@ -360,7 +360,7 @@ is that you must append them to the return list with swig_result = caml_list_a
signature for a function that uses value in this way.
</p>
<H3><a name="Ocaml_nn9"></a>29.2.1 The generated module</H3>
<H3><a name="Ocaml_nn9"></a>30.2.1 The generated module</H3>
<p>
@ -394,7 +394,7 @@ it describes the output SWIG will generate for class definitions.
</td></tr>
</table>
<H3><a name="Ocaml_nn10"></a>29.2.2 Enums</H3>
<H3><a name="Ocaml_nn10"></a>30.2.2 Enums</H3>
<p>
@ -457,7 +457,7 @@ val x : Enum_test.c_obj = C_enum `a
</pre>
</div>
<H4><a name="Ocaml_nn11"></a>29.2.2.1 Enum typing in Ocaml</H4>
<H4><a name="Ocaml_nn11"></a>30.2.2.1 Enum typing in Ocaml</H4>
<p>
@ -470,10 +470,10 @@ functions imported from different modules. You must convert values to master
values using the swig_val function before sharing them with another module.
</p>
<H3><a name="Ocaml_nn12"></a>29.2.3 Arrays</H3>
<H3><a name="Ocaml_nn12"></a>30.2.3 Arrays</H3>
<H4><a name="Ocaml_nn13"></a>29.2.3.1 Simple types of bounded arrays</H4>
<H4><a name="Ocaml_nn13"></a>30.2.3.1 Simple types of bounded arrays</H4>
<p>
@ -494,7 +494,7 @@ arrays of simple types with known bounds in your code, but this only works
for arrays whose bounds are completely specified.
</p>
<H4><a name="Ocaml_nn14"></a>29.2.3.2 Complex and unbounded arrays</H4>
<H4><a name="Ocaml_nn14"></a>30.2.3.2 Complex and unbounded arrays</H4>
<p>
@ -507,7 +507,7 @@ SWIG can't predict which of these methods will be used in the array,
so you have to specify it for yourself in the form of a typemap.
</p>
<H4><a name="Ocaml_nn15"></a>29.2.3.3 Using an object</H4>
<H4><a name="Ocaml_nn15"></a>30.2.3.3 Using an object</H4>
<p>
@ -521,7 +521,7 @@ Consider writing an object when the ending condition of your array is complex,
such as using a required sentinel, etc.
</p>
<H4><a name="Ocaml_nn16"></a>29.2.3.4 Example typemap for a function taking float * and int</H4>
<H4><a name="Ocaml_nn16"></a>30.2.3.4 Example typemap for a function taking float * and int</H4>
<p>
@ -572,7 +572,7 @@ void printfloats( float *tab, int len );
</pre></td></tr></table>
<H3><a name="Ocaml_nn17"></a>29.2.4 C++ Classes</H3>
<H3><a name="Ocaml_nn17"></a>30.2.4 C++ Classes</H3>
<p>
@ -615,7 +615,7 @@ the underlying pointer, so using create_[x]_from_ptr alters the
returned value for the same object.
</p>
<H4><a name="Ocaml_nn18"></a>29.2.4.1 STL vector and string Example</H4>
<H4><a name="Ocaml_nn18"></a>30.2.4.1 STL vector and string Example</H4>
<p>
@ -695,7 +695,7 @@ baz
#
</pre></div>
<H4><a name="Ocaml_nn19"></a>29.2.4.2 C++ Class Example</H4>
<H4><a name="Ocaml_nn19"></a>30.2.4.2 C++ Class Example</H4>
<p>
@ -725,7 +725,7 @@ public:
};
</pre></td></tr></table>
<H4><a name="Ocaml_nn20"></a>29.2.4.3 Compiling the example</H4>
<H4><a name="Ocaml_nn20"></a>30.2.4.3 Compiling the example</H4>
<div class="code"><pre>
@ -743,7 +743,7 @@ bash-2.05a$ ocamlmktop -custom swig.cmo -I `camlp4 -where` \
-L$QTPATH/lib -cclib -lqt
</pre></div>
<H4><a name="Ocaml_nn21"></a>29.2.4.4 Sample Session</H4>
<H4><a name="Ocaml_nn21"></a>30.2.4.4 Sample Session</H4>
<div class="code"><pre>
@ -770,10 +770,10 @@ Assuming you have a working installation of QT, you will see a window
containing the string "hi" in a button.
</p>
<H3><a name="Ocaml_nn22"></a>29.2.5 Director Classes</H3>
<H3><a name="Ocaml_nn22"></a>30.2.5 Director Classes</H3>
<H4><a name="Ocaml_nn23"></a>29.2.5.1 Director Introduction</H4>
<H4><a name="Ocaml_nn23"></a>30.2.5.1 Director Introduction</H4>
<p>
@ -800,7 +800,7 @@ class foo {
};
</pre></div>
<H4><a name="Ocaml_nn24"></a>29.2.5.2 Overriding Methods in Ocaml</H4>
<H4><a name="Ocaml_nn24"></a>30.2.5.2 Overriding Methods in Ocaml</H4>
<p>
@ -828,7 +828,7 @@ In this example, I'll examine the objective caml code involved in providing
an overloaded class. This example is contained in Examples/ocaml/shapes.
</p>
<H4><a name="Ocaml_nn25"></a>29.2.5.3 Director Usage Example</H4>
<H4><a name="Ocaml_nn25"></a>30.2.5.3 Director Usage Example</H4>
<table border="1" bgcolor="#dddddd" summary="Director usage example">
@ -887,7 +887,7 @@ in a more effortless style in ocaml, while leaving the "engine" part of the
program in C++.
</p>
<H4><a name="Ocaml_nn26"></a>29.2.5.4 Creating director objects</H4>
<H4><a name="Ocaml_nn26"></a>30.2.5.4 Creating director objects</H4>
<p>
@ -928,7 +928,7 @@ object from causing a core dump, as long as the object is destroyed
properly.
</p>
<H4><a name="Ocaml_nn27"></a>29.2.5.5 Typemaps for directors, <tt>directorin, directorout, directorargout</tt></H4>
<H4><a name="Ocaml_nn27"></a>30.2.5.5 Typemaps for directors, <tt>directorin, directorout, directorargout</tt></H4>
<p>
@ -939,7 +939,7 @@ well as a function return value in the same way you provide function arguments,
and to receive arguments the same way you normally receive function returns.
</p>
<H4><a name="Ocaml_nn28"></a>29.2.5.6 <tt>directorin</tt> typemap</H4>
<H4><a name="Ocaml_nn28"></a>30.2.5.6 <tt>directorin</tt> typemap</H4>
<p>
@ -950,7 +950,7 @@ code receives when you are called. In general, a simple <tt>directorin</tt> typ
can use the same body as a simple <tt>out</tt> typemap.
</p>
<H4><a name="Ocaml_nn29"></a>29.2.5.7 <tt>directorout</tt> typemap</H4>
<H4><a name="Ocaml_nn29"></a>30.2.5.7 <tt>directorout</tt> typemap</H4>
<p>
@ -961,7 +961,7 @@ for the same type, except when there are special requirements for object
ownership, etc.
</p>
<H4><a name="Ocaml_nn30"></a>29.2.5.8 <tt>directorargout</tt> typemap</H4>
<H4><a name="Ocaml_nn30"></a>30.2.5.8 <tt>directorargout</tt> typemap</H4>
<p>
@ -978,7 +978,7 @@ In the event that you don't specify all of the necessary values, integral
values will read zero, and struct or object returns have undefined results.
</p>
<H3><a name="Ocaml_nn31"></a>29.2.6 Exceptions</H3>
<H3><a name="Ocaml_nn31"></a>30.2.6 Exceptions</H3>
<p>

View file

@ -8,7 +8,7 @@
<body bgcolor="#ffffff">
<H1><a name="Octave"></a>30 SWIG and Octave</H1>
<H1><a name="Octave"></a>31 SWIG and Octave</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -55,18 +55,15 @@ More information can be found at <a href="http://www.gnu.org/software/octave/">O
Also, there are a dozen or so examples in the Examples/octave directory, and hundreds in the test suite (Examples/test-suite and Examples/test-suite/octave).
</p>
<H2><a name="Octave_nn2"></a>30.1 Preliminaries</H2>
<H2><a name="Octave_nn2"></a>31.1 Preliminaries</H2>
<p>
The SWIG implemention was first based on Octave 2.9.12, so this is the minimum version required. Testing has only been done on Linux.
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.
</p>
<p>
As of SWIG 2.0.5, the Octave module should work with Octave versions 3.0.5, 3.2.4, and 3.4.0.
</p>
<H2><a name="Octave_nn3"></a>30.2 Running SWIG</H2>
<H2><a name="Octave_nn3"></a>31.2 Running SWIG</H2>
<p>
@ -74,7 +71,7 @@ Let's start with a very simple SWIG interface file, example.i:
</p>
<div class="code"><pre>
%module example
%module swigexample
%{
#include "example.h"
%}
@ -95,10 +92,10 @@ The <tt>-c++</tt> option is also required when wrapping C++ code:
<div class="shell"><pre>$ swig -octave -c++ -o example_wrap.cpp example.i </pre></div>
<p>
This creates a C++ source file <tt>example_wrap.cpp</tt>. A C++ file is generated even when wrapping C code as Octave is itself written in C++ and requires wrapper code to be in the same language. 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 (in this case, the gcd implementation) to create an extension module.
This creates a C++ source file "example_wrap.cpp". A C++ file is generated even when wrapping C code as Octave is itself written in C++ and requires wrapper code to be in the same language. 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 (in this case, the gcd implementation) to create an extension module.
</p>
<H3><a name="Octave_nn4"></a>30.2.1 Command-line options</H3>
<H3><a name="Octave_nn4"></a>31.2.1 Command-line options</H3>
<p>
@ -110,21 +107,18 @@ Options specific to the Octave module are:
<pre>$ swig -octave -help
...
Octave Options (available with -octave)
-global - Load all symbols into the global namespace [default]
-globals <em>name</em> - Set <em>name</em> used to access C global variables [default: 'cvar']
- Use '.' to load C global variables into module namespace
-noglobal - Do not load all symbols into the global namespace
Use '.' to load C global variables into module namespace
-opprefix <em>str</em> - Prefix <em>str</em> for global operator functions [default: 'op_']
</pre></div>
<p>
The <em>-global</em> and <em>-noglobal</em> options determine whether the Octave module will load all symbols into the global namespace in addition to the global namespace.
The <em>-globals</em> option sets the name of the variable which is the namespace for C global variables exported by the module.
The special name "." loads C global variables into the module namespace, i.e. alongside C functions and structs exported by the module.
The <em>-opprefix</em> options sets the prefix of the names of global/friend <a href="#Octave_nn18">operator</a> functions.
</p>
<H3><a name="Octave_nn5"></a>30.2.2 Compiling a dynamic module</H3>
<H3><a name="Octave_nn5"></a>31.2.2 Compiling a dynamic module</H3>
<p>
@ -138,7 +132,7 @@ $ mkoctfile example_wrap.cpp example.c
</pre></div>
<p>
where example.c is the file containing the gcd() implementation.
where "example.c" is the file containing the gcd() implementation.
</p>
<p>
@ -146,12 +140,12 @@ $ mkoctfile example_wrap.cpp example.c
</p>
<p>
mkoctfile will produce example.oct, which contains the compiled extension module. Loading it into Octave is then a matter of invoking
mkoctfile will produce "swigexample.oct", which contains the compiled extension module. Loading it into Octave is then a matter of invoking
</p>
<div class="targetlang"><pre>octave:1&gt; example</pre></div>
<div class="targetlang"><pre>octave:1&gt; swigexample</pre></div>
<H3><a name="Octave_nn6"></a>30.2.3 Using your module</H3>
<H3><a name="Octave_nn6"></a>31.2.3 Using your module</H3>
<p>
@ -160,75 +154,42 @@ Assuming all goes well, you will be able to do this:
</p>
<div class="targetlang"><pre>$ octave -q
octave:1&gt; example
octave:2&gt; example.gcd(4,6)
octave:1&gt; swigexample
octave:2&gt; swigexample.gcd(4,6)
ans = 2
octave:3&gt; example.cvar.Foo
octave:3&gt; swigexample.cvar.Foo
ans = 3
octave:4&gt; example.cvar.Foo=4;
octave:5&gt; example.cvar.Foo
octave:4&gt; swigexample.cvar.Foo=4;
octave:5&gt; swigexample.cvar.Foo
ans = 4 </pre></div>
<H2><a name="Octave_nn7"></a>30.3 A tour of basic C/C++ wrapping</H2>
<H2><a name="Octave_nn7"></a>31.3 A tour of basic C/C++ wrapping</H2>
<H3><a name="Octave_nn8"></a>30.3.1 Modules</H3>
<H3><a name="Octave_nn8"></a>31.3.1 Modules</H3>
<p>
The SWIG module directive specifies the name of the Octave module. If you specify `module example', then in Octave everything in the module will be accessible under "example", as in the above example. When choosing a module name, make sure you don't use the same name as a built-in Octave command or standard module name.
The SWIG module directive specifies the name of the Octave module. If you specify "module swigexample", then in Octave everything in the module will be accessible under "swigexample", as in the above example. When choosing a module name, make sure you don't use the same name as a built-in Octave command or standard module name.
</p>
<p>
When Octave is asked to invoke <tt>example</tt>, it will try to find the .m or .oct file that defines the function "example". It will thusly find example.oct, that upon loading will register all of the module's symbols.
When Octave is asked to invoke <tt>swigexample</tt>, it will try to find the ".m" or ".oct" file that defines the function "swigexample". You therefore need to make sure that "swigexample.oct" is in Octave's search path, which can be specified with the environment variable "OCTAVE_PATH".
</p>
<p>
An Octave module takes three options, <em>-global</em>, <em>-noglobal</em>, and <em>-globals</em>, which behave the same as the corresponding swig <a href="#Octave_nn4">command-line options</a>.
Here are some example usages:
To load an Octave module, simply type its name:
</p>
<div class="targetlang"><pre>
octave:1&gt; example -help
usage: example [-global|-noglobal] [-globals &lt;name&gt;]
octave:2&gt; example -global
octave:3&gt; gcd(4,6)
<div class="targetlang"><pre>
octave:1&gt; swigexample;
octave:2&gt; gcd(4,6)
ans = 2
octave:4&gt; cvar.Foo
ans = 3
octave:5&gt; cvar.Foo=4;
octave:6&gt; cvar.Foo
ans = 4
</pre></div>
<br>
<div class="targetlang"><pre>
octave:1&gt; example -noglobal
octave:2&gt; gcd(6,9)
ans = 3
octave:3&gt; cvar.Foo
error: `cvar' undefined near line 3 column 1
octave:3&gt; example.cvar.Foo
ans = 3
</pre></div>
<br>
<div class="targetlang"><pre>
octave:1&gt; example -globals mycvar
octave:2&gt; cvar.Foo
error: `cvar' undefined near line 2 column 1
octave:2&gt; mycvar.Foo
ans = 3
</pre></div>
<p>
It is also possible to rename the module / global variables namespaces with an assignment, as in: <br>
<div class="targetlang"><pre>
octave:1&gt; example
octave:2&gt; c=example;
octave:3&gt; c.gcd(10,4)
ans = 2
octave:4&gt; some_vars = cvar;
octave:5&gt; some_vars.Foo
ans = 3
octave:4&gt; cvar.Foo=4;
octave:5&gt; cvar.Foo
ans = 4
</pre></div>
<p>
@ -238,64 +199,64 @@ If the module is also used in the base context, however, it must first be loaded
<div class="targetlang"><pre>
octave:1&gt; function l = my_lcm(a,b)
&gt; example
&gt; l = abs(a*b)/example.gcd(a,b);
&gt; swigexample
&gt; l = abs(a*b)/swigexample.gcd(a,b);
&gt; endfunction
octave:2&gt; my_lcm(4,6)
ans = 12
octave:3&gt; example.gcd(4,6)
octave:3&gt; swigexample.gcd(4,6)
error: can't perform indexing operations for &lt;unknown type&gt; type
octave:3&gt; example;
octave:4&gt; example.gcd(4,6)
octave:3&gt; swigexample;
octave:4&gt; swigexample.gcd(4,6)
ans = 2
</pre></div>
<H3><a name="Octave_nn9"></a>30.3.2 Functions</H3>
<H3><a name="Octave_nn9"></a>31.3.2 Functions</H3>
<p>
Global functions are wrapped as new Octave built-in functions. For example,
</p>
<div class="code"><pre>&#037;module example
<div class="code"><pre>&#037;module swigexample
int fact(int n); </pre></div>
<p>
creates a built-in function <tt>example.fact(n)</tt> that works exactly like you think it does:
creates a built-in function <tt>swigexample.fact(n)</tt> that works exactly like you think it does:
</p>
<div class="targetlang"><pre>octave:1&gt; example.fact(4)
<div class="targetlang"><pre>octave:1&gt; swigexample.fact(4)
24 </pre></div>
<H3><a name="Octave_nn10"></a>30.3.3 Global variables</H3>
<H3><a name="Octave_nn10"></a>31.3.3 Global variables</H3>
<p>
Global variables are a little special in Octave. Given a global variable:
</p>
<div class="code"><pre>%module example
<div class="code"><pre>%module swigexample
extern double Foo;
</pre></div>
</pre></div>
<p>
To expose variables, SWIG actually generates two functions, to get and set the value. In this case, Foo_set and Foo_set would be generated. SWIG then automatically calls these functions when you get and set the variable-- in the former case creating a local copy in the interpreter of the C variables, and in the latter case copying an interpreter variables onto the C variable.
</p>
<div class="targetlang"><pre>octave:1&gt; example;
octave:2&gt; c=example.cvar.Foo
<div class="targetlang"><pre>octave:1&gt; swigexample;
octave:2&gt; c=swigexample.cvar.Foo
c = 3
octave:3&gt; example.cvar.Foo=4;
octave:3&gt; swigexample.cvar.Foo=4;
octave:4&gt; c
c = 3
octave:5&gt; example.cvar.Foo
octave:5&gt; swigexample.cvar.Foo
ans = 4</pre></div>
<p>
If a variable is marked with the %immutable directive then any attempts to set this variable will cause an Octave error. Given a global variable:
</p>
<div class="code"><pre>%module example
<div class="code"><pre>%module swigexample
%immutable;
extern double Foo;
%mutable;
@ -305,8 +266,8 @@ extern double Foo;
SWIG will allow the reading of <tt>Foo</tt> but when a set attempt is made, an error function will be called.
</p>
<div class="targetlang"><pre>octave:1&gt; example
octave:2&gt; example.Foo=4
<div class="targetlang"><pre>octave:1&gt; swigexample
octave:2&gt; swigexample.Foo=4
error: attempt to set immutable member variable
error: assignment failed, or no method for `swig_type = scalar'
error: evaluating assignment expression near line 2, column 12 </pre></div>
@ -315,19 +276,19 @@ error: evaluating assignment expression near line 2, column 12 </pre></div>
It is possible to add new functions or variables to the module. This also allows the user to rename/remove existing functions and constants (but not linked variables, mutable or immutable). Therefore users are recommended to be careful when doing so.
</p>
<div class="targetlang"><pre>octave:1&gt; example;
octave:2&gt; example.PI=3.142;
octave:3&gt; example.PI
<div class="targetlang"><pre>octave:1&gt; swigexample;
octave:2&gt; swigexample.PI=3.142;
octave:3&gt; swigexample.PI
ans = 3.1420 </pre></div>
<H3><a name="Octave_nn11"></a>30.3.4 Constants and enums</H3>
<H3><a name="Octave_nn11"></a>31.3.4 Constants and enums</H3>
<p>
Because Octave doesn't really have the concept of constants, C/C++ constants are not really constant in Octave. They are actually just a copy of the value into the Octave interpreter. Therefore they can be changed just as any other value. For example given some constants:
</p>
<div class="code"><pre>%module example
<div class="code"><pre>%module swigexample
%constant int ICONST=42;
#define SCONST "Hello World"
enum Days{SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY};
@ -337,12 +298,12 @@ enum Days{SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY};
This is 'effectively' converted into the following Octave code:
</p>
<div class="targetlang"><pre>example.ICONST=42
example.SCONST="Hello World"
example.SUNDAY=0
<div class="targetlang"><pre>swigexample.ICONST=42
swigexample.SCONST="Hello World"
swigexample.SUNDAY=0
.... </pre></div>
<H3><a name="Octave_nn12"></a>30.3.5 Pointers</H3>
<H3><a name="Octave_nn12"></a>31.3.5 Pointers</H3>
<p>
@ -350,7 +311,7 @@ example.SUNDAY=0
C/C++ pointers are fully supported by SWIG. Furthermore, SWIG has no problem working with incomplete type information. Given a wrapping of the &lt;file.h&gt; interface:
</p>
<div class="code"><pre>%module example
<div class="code"><pre>%module swigexample
FILE *fopen(const char *filename, const char *mode);
int fputs(const char *, FILE *);
int fclose(FILE *);
@ -361,18 +322,18 @@ When wrapped, you will be able to use the functions in a natural way from Octave
</p>
<div class="targetlang"><pre>
octave:1&gt; example;
octave:2&gt; f=example.fopen("w","junk");
octave:3&gt; example.fputs("Hello world",f);
octave:4&gt; example.fclose(f);
octave:1&gt; swigexample;
octave:2&gt; f=swigexample.fopen("w","junk");
octave:3&gt; swigexample.fputs("Hello world",f);
octave:4&gt; swigexample.fclose(f);
</pre></div>
<p>
Simply printing the value of a wrapped C++ type will print it's typename. E.g.,
Simply printing the value of a wrapped C++ type will print its typename. E.g.,
</p>
<div class="targetlang"><pre>octave:1&gt; example;
octave:2&gt; f=example.fopen("junk","w");
<div class="targetlang"><pre>octave:1&gt; swigexample;
octave:2&gt; f=swigexample.fopen("junk","w");
octave:3&gt; f
f =
@ -384,12 +345,12 @@ f =
As the user of the pointer, you are responsible for freeing it, or closing any resources associated with it (just as you would in a C program). This does not apply so strictly to classes and structs (see below).
</p>
<div class="targetlang"><pre>octave:1&gt; example;
octave:2&gt; f=example.fopen("not there","r");
<div class="targetlang"><pre>octave:1&gt; swigexample;
octave:2&gt; f=swigexample.fopen("not there","r");
error: value on right hand side of assignment is undefined
error: evaluating assignment expression near line 2, column 2 </pre></div>
<H3><a name="Octave_nn13"></a>30.3.6 Structures and C++ classes</H3>
<H3><a name="Octave_nn13"></a>31.3.6 Structures and C++ classes</H3>
<p>
@ -407,8 +368,8 @@ For each wrapped structure and class, a <tt>swig_ref</tt> will be exposed that h
</p>
<div class="targetlang">
<pre>octave:1&gt; example;
octave:2&gt; p=example.Point();
<pre>octave:1&gt; swigexample;
octave:2&gt; p=swigexample.Point();
octave:3&gt; p.x=3;
octave:4&gt; p.y=5;
octave:5&gt; p.x, p.y
@ -442,9 +403,9 @@ public:
can be used from Octave like this
</p>
<div class="targetlang">
<pre>octave:1&gt; example;
octave:2&gt; p1=example.Point(3,5);
octave:3&gt; p2=example.Point(1,2);
<pre>octave:1&gt; swigexample;
octave:2&gt; p1=swigexample.Point(3,5);
octave:3&gt; p2=swigexample.Point(1,2);
octave:4&gt; p1.distance(p2)
ans = 3.6056
</pre></div>
@ -524,7 +485,7 @@ ans = 1
Depending on the ownership setting of a <tt>swig_ref</tt>, it may call C++ destructors when its reference count goes to zero. See the section on memory management below for details.
</p>
<H3><a name="Octave_nn15"></a>30.3.7 C++ inheritance</H3>
<H3><a name="Octave_nn15"></a>31.3.7 C++ inheritance</H3>
<p>
@ -533,7 +494,7 @@ This information contains the full class hierarchy. When an indexing operation (
the tree is walked to find a match in the current class as well as any of its bases. The lookup is then cached in the <tt>swig_ref</tt>.
</p>
<H3><a name="Octave_nn17"></a>30.3.8 C++ overloaded functions</H3>
<H3><a name="Octave_nn17"></a>31.3.8 C++ overloaded functions</H3>
<p>
@ -543,7 +504,7 @@ The dispatch function selects which overload to call (if any) based on the passe
<tt>typecheck</tt> typemaps are used to analyze each argument, as well as assign precedence. See the chapter on typemaps for details.
</p>
<H3><a name="Octave_nn18"></a>30.3.9 C++ operators</H3>
<H3><a name="Octave_nn18"></a>31.3.9 C++ operators</H3>
<p>
@ -647,7 +608,7 @@ On the C++ side, the default mappings are as follows:
Octave can also utilise friend (i.e. non-member) operators with a simple %rename: see the example in the Examples/octave/operator directory.
</p>
<H3><a name="Octave_nn19"></a>30.3.10 Class extension with %extend</H3>
<H3><a name="Octave_nn19"></a>31.3.10 Class extension with %extend</H3>
<p>
@ -677,7 +638,7 @@ octave:3&gt; printf("%s\n",a);
octave:4&gt; a.__str()
4
</pre></div>
<H3><a name="Octave_nn20"></a>30.3.11 C++ templates</H3>
<H3><a name="Octave_nn20"></a>31.3.11 C++ templates</H3>
<p>
@ -685,7 +646,7 @@ C++ class and function templates are fully supported as in other modules, in tha
For example, function templates can be instantiated as follows:
</p>
<div class="code"><pre>%module example
<div class="code"><pre>%module swigexample
%inline {
template&lt;class __scalar&gt;
__scalar mul(__scalar a,__scalar b) {
@ -713,7 +674,7 @@ ans = 22 + 46i
Similarly, class templates can be instantiated as in the following example,
</p>
<div class="code"><pre>%module example
<div class="code"><pre>%module swigexample
%include &lt;std_complex.i&gt;
%include &lt;std_string.i&gt;
%inline {
@ -754,14 +715,14 @@ ans =
</pre></div>
<H3><a name="Octave_nn21"></a>30.3.12 C++ Smart Pointers</H3>
<H3><a name="Octave_nn21"></a>31.3.12 C++ Smart Pointers</H3>
<p>
C++ smart pointers are fully supported as in other modules.
</p>
<H3><a name="Octave_nn22"></a>30.3.13 Directors (calling Octave from C++ code)</H3>
<H3><a name="Octave_nn22"></a>31.3.13 Directors (calling Octave from C++ code)</H3>
<p>
@ -842,14 +803,14 @@ c-side routine called
octave-side routine called
</pre></div>
<H3><a name="Octave_nn23"></a>30.3.14 Threads</H3>
<H3><a name="Octave_nn23"></a>31.3.14 Threads</H3>
<p>
The use of threads in wrapped Director code is not supported; i.e., an Octave-side implementation of a C++ class must be called from the Octave interpreter's thread. Anything fancier (apartment/queue model, whatever) is left to the user. Without anything fancier, this amounts to the limitation that Octave must drive the module... like, for example, an optimization package that calls Octave to evaluate an objective function.
</p>
<H3><a name="Octave_nn24"></a>30.3.15 Memory management</H3>
<H3><a name="Octave_nn24"></a>31.3.15 Memory management</H3>
<p>
@ -883,14 +844,14 @@ The %newobject directive may be used to control this behavior for pointers retur
In the case where one wishes for the C++ side to own an object that was created in Octave (especially a Director object), one can use the __disown() method to invert this logic. Then letting the Octave reference count go to zero will not destroy the object, but destroying the object will invalidate the Octave-side object if it still exists (and call destructors of other C++ bases in the case of multiple inheritance/<tt>subclass()</tt>'ing).
</p>
<H3><a name="Octave_nn25"></a>30.3.16 STL support</H3>
<H3><a name="Octave_nn25"></a>31.3.16 STL support</H3>
<p>
Various STL library files are provided for wrapping STL containers.
</p>
<H3><a name="Octave_nn26"></a>30.3.17 Matrix typemaps</H3>
<H3><a name="Octave_nn26"></a>31.3.17 Matrix typemaps</H3>
<p>

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Perl5"></a>31 SWIG and Perl5</H1>
<H1><a name="Perl5"></a>32 SWIG and Perl5</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -68,6 +68,15 @@
<li><a href="#Perl5_nn46">Modifying the proxy methods</a>
</ul>
<li><a href="#Perl5_nn47">Adding additional Perl code</a>
<li><a href="#Perl5_directors">Cross language polymorphism</a>
<ul>
<li><a href="#Perl5_nn48">Enabling directors</a>
<li><a href="#Perl5_nn49">Director classes</a>
<li><a href="#Perl5_nn50">Ownership and object destruction</a>
<li><a href="#Perl5_nn51">Exception unrolling</a>
<li><a href="#Perl5_nn52">Overhead and code bloat</a>
<li><a href="#Perl5_nn53">Typemaps</a>
</ul>
</ul>
</div>
<!-- INDEX -->
@ -87,7 +96,7 @@ later. We're no longer testing regularly with older versions, but
Perl 5.6 seems to mostly work, while older versions don't.
</p>
<H2><a name="Perl5_nn2"></a>31.1 Overview</H2>
<H2><a name="Perl5_nn2"></a>32.1 Overview</H2>
<p>
@ -108,7 +117,7 @@ described. Advanced customization features, typemaps, and other
options are found near the end of the chapter.
</p>
<H2><a name="Perl5_nn3"></a>31.2 Preliminaries</H2>
<H2><a name="Perl5_nn3"></a>32.2 Preliminaries</H2>
<p>
@ -133,7 +142,7 @@ To build the module, you will need to compile the file
<tt>example_wrap.c</tt> and link it with the rest of your program.
</p>
<H3><a name="Perl5_nn4"></a>31.2.1 Getting the right header files</H3>
<H3><a name="Perl5_nn4"></a>32.2.1 Getting the right header files</H3>
<p>
@ -165,13 +174,13 @@ $ perl -e 'use Config; print "$Config{archlib}\n";'
</pre>
</div>
<H3><a name="Perl5_nn5"></a>31.2.2 Compiling a dynamic module</H3>
<H3><a name="Perl5_nn5"></a>32.2.2 Compiling a dynamic module</H3>
<p>
The preferred approach to building an extension module is to compile it into
a shared object file or DLL. To do this, you will need to compile your program
using commands like this (shown for Linux):
a shared object file or DLL. Assuming you have code you need to link to in a file called <tt>example.c</tt>,
you will need to compile your program using commands like this (shown for Linux):
</p>
<div class="code"><pre>
@ -198,7 +207,7 @@ the target should be named `<tt>example.so</tt>',
`<tt>example.sl</tt>', or the appropriate dynamic module name on your system.
</p>
<H3><a name="Perl5_nn6"></a>31.2.3 Building a dynamic module with MakeMaker</H3>
<H3><a name="Perl5_nn6"></a>32.2.3 Building a dynamic module with MakeMaker</H3>
<p>
@ -232,7 +241,7 @@ the preferred approach to compilation. More information about MakeMaker can be
found in "Programming Perl, 2nd ed." by Larry Wall, Tom Christiansen,
and Randal Schwartz.</p>
<H3><a name="Perl5_nn7"></a>31.2.4 Building a static version of Perl</H3>
<H3><a name="Perl5_nn7"></a>32.2.4 Building a static version of Perl</H3>
<p>
@ -301,7 +310,7 @@ added to it. Depending on your machine, you may need to link with
additional libraries such as <tt>-lsocket, -lnsl, -ldl</tt>, etc.
</p>
<H3><a name="Perl5_nn8"></a>31.2.5 Using the module</H3>
<H3><a name="Perl5_nn8"></a>32.2.5 Using the module</H3>
<p>
@ -454,7 +463,7 @@ system configuration (this requires root access and you will need to
read the man pages).
</p>
<H3><a name="Perl5_nn9"></a>31.2.6 Compilation problems and compiling with C++</H3>
<H3><a name="Perl5_nn9"></a>32.2.6 Compilation problems and compiling with C++</H3>
<p>
@ -484,8 +493,8 @@ Solaris, you often need to add an extra library <tt>-lCrun</tt> like this:
<div class="code"><pre>
$ swig -c++ -perl example.i
$ CC -c example.cxx
$ CC -c example_wrap.cxx -I/usr/lib/perl/5.14/i386-linux/CORE
$ CC -Kpic -c example.cxx
$ CC -Kpic -c example_wrap.cxx -I/usr/lib/perl/5.14/i386-linux/CORE
$ CC -shared example.o example_wrap.o -o example.so <b>-lCrun</b>
</pre></div>
@ -597,7 +606,7 @@ have to find the macro that conflicts and add an #undef into the .i file. Pleas
any conflicting macros you find to <a href="http://www.swig.org/mail.html">swig-user mailing list</a>.
</p>
<H3><a name="Perl5_nn10"></a>31.2.7 Compiling for 64-bit platforms</H3>
<H3><a name="Perl5_nn10"></a>32.2.7 Compiling for 64-bit platforms</H3>
<p>
@ -624,7 +633,7 @@ also introduce problems on platforms that support more than one
linking standard (e.g., -o32 and -n32 on Irix).
</p>
<H2><a name="Perl5_nn11"></a>31.3 Building Perl Extensions under Windows</H2>
<H2><a name="Perl5_nn11"></a>32.3 Building Perl Extensions under Windows</H2>
<p>
@ -635,7 +644,7 @@ section assumes you are using SWIG with Microsoft Visual C++
although the procedure may be similar with other compilers.
</p>
<H3><a name="Perl5_nn12"></a>31.3.1 Running SWIG from Developer Studio</H3>
<H3><a name="Perl5_nn12"></a>32.3.1 Running SWIG from Developer Studio</H3>
<p>
@ -698,7 +707,7 @@ print "$a\n";
</pre></div>
<H3><a name="Perl5_nn13"></a>31.3.2 Using other compilers</H3>
<H3><a name="Perl5_nn13"></a>32.3.2 Using other compilers</H3>
<p>
@ -706,7 +715,7 @@ SWIG is known to work with Cygwin and may work with other compilers on Windows.
For general hints and suggestions refer to the <a href="Windows.html#Windows">Windows</a> chapter.
</p>
<H2><a name="Perl5_nn14"></a>31.4 The low-level interface</H2>
<H2><a name="Perl5_nn14"></a>32.4 The low-level interface</H2>
<p>
@ -716,7 +725,7 @@ can be used to control your application. However, it is also used to
construct more user-friendly proxy classes as described in the next section.
</p>
<H3><a name="Perl5_nn15"></a>31.4.1 Functions</H3>
<H3><a name="Perl5_nn15"></a>32.4.1 Functions</H3>
<p>
@ -739,7 +748,7 @@ use example;
$a = &amp;example::fact(2);
</pre></div>
<H3><a name="Perl5_nn16"></a>31.4.2 Global variables</H3>
<H3><a name="Perl5_nn16"></a>32.4.2 Global variables</H3>
<p>
@ -809,7 +818,7 @@ extern char *path; // Declared later in the input
</pre>
</div>
<H3><a name="Perl5_nn17"></a>31.4.3 Constants</H3>
<H3><a name="Perl5_nn17"></a>32.4.3 Constants</H3>
<p>
@ -849,7 +858,7 @@ print example::FOO,"\n";
</pre>
</div>
<H3><a name="Perl5_nn18"></a>31.4.4 Pointers</H3>
<H3><a name="Perl5_nn18"></a>32.4.4 Pointers</H3>
<p>
@ -958,7 +967,7 @@ as XS and <tt>xsubpp</tt>. Given the advancement of the SWIG typesystem and the
SWIG and XS, this is no longer supported.
</p>
<H3><a name="Perl5_nn19"></a>31.4.5 Structures</H3>
<H3><a name="Perl5_nn19"></a>32.4.5 Structures</H3>
<p>
@ -1092,7 +1101,7 @@ void Bar_f_set(Bar *b, Foo *val) {
</div>
<H3><a name="Perl5_nn20"></a>31.4.6 C++ classes</H3>
<H3><a name="Perl5_nn20"></a>32.4.6 C++ classes</H3>
<p>
@ -1157,7 +1166,7 @@ provides direct access to C++ objects. A higher level interface using Perl prox
can be built using these low-level accessors. This is described shortly.
</p>
<H3><a name="Perl5_nn21"></a>31.4.7 C++ classes and type-checking</H3>
<H3><a name="Perl5_nn21"></a>32.4.7 C++ classes and type-checking</H3>
<p>
@ -1193,7 +1202,7 @@ If necessary, the type-checker also adjusts the value of the pointer (as is nece
multiple inheritance is used).
</p>
<H3><a name="Perl5_nn22"></a>31.4.8 C++ overloaded functions</H3>
<H3><a name="Perl5_nn22"></a>32.4.8 C++ overloaded functions</H3>
<p>
@ -1237,7 +1246,7 @@ example::Spam_foo_d($s,3.14);
Please refer to the "SWIG Basics" chapter for more information.
</p>
<H3><a name="Perl5_nn23"></a>31.4.9 Operators</H3>
<H3><a name="Perl5_nn23"></a>32.4.9 Operators</H3>
<p>
@ -1264,7 +1273,7 @@ The following C++ operators are currently supported by the Perl module:
<li>operator or </li>
</ul>
<H3><a name="Perl5_nn24"></a>31.4.10 Modules and packages</H3>
<H3><a name="Perl5_nn24"></a>32.4.10 Modules and packages</H3>
<p>
@ -1359,7 +1368,7 @@ print Foo::fact(4),"\n"; # Call a function in package FooBar
</pre></div>
-->
<H2><a name="Perl5_nn25"></a>31.5 Input and output parameters</H2>
<H2><a name="Perl5_nn25"></a>32.5 Input and output parameters</H2>
<p>
@ -1578,7 +1587,7 @@ print "$c\n";
<b>Note:</b> The <tt>REFERENCE</tt> feature is only currently supported for numeric types (integers and floating point).
</p>
<H2><a name="Perl5_nn26"></a>31.6 Exception handling</H2>
<H2><a name="Perl5_nn26"></a>32.6 Exception handling</H2>
<p>
@ -1743,7 +1752,7 @@ This is still supported, but it is deprecated. The newer <tt>%exception</tt> di
functionality, but it has additional capabilities that make it more powerful.
</p>
<H2><a name="Perl5_nn27"></a>31.7 Remapping datatypes with typemaps</H2>
<H2><a name="Perl5_nn27"></a>32.7 Remapping datatypes with typemaps</H2>
<p>
@ -1760,7 +1769,7 @@ Typemaps are only used if you want to change some aspect of the primitive
C-Perl interface.
</p>
<H3><a name="Perl5_nn28"></a>31.7.1 A simple typemap example</H3>
<H3><a name="Perl5_nn28"></a>32.7.1 A simple typemap example</H3>
<p>
@ -1864,7 +1873,7 @@ example::count("e","Hello World");
</div>
<H3><a name="Perl5_nn29"></a>31.7.2 Perl5 typemaps</H3>
<H3><a name="Perl5_nn29"></a>32.7.2 Perl5 typemaps</H3>
<p>
@ -1969,7 +1978,7 @@ Return of C++ member data (all languages).
Check value of input parameter.
</div>
<H3><a name="Perl5_nn30"></a>31.7.3 Typemap variables</H3>
<H3><a name="Perl5_nn30"></a>32.7.3 Typemap variables</H3>
<p>
@ -2040,7 +2049,7 @@ properly assigned.
The Perl name of the wrapper function being created.
</div>
<H3><a name="Perl5_nn31"></a>31.7.4 Useful functions</H3>
<H3><a name="Perl5_nn31"></a>32.7.4 Useful functions</H3>
<p>
@ -2109,7 +2118,7 @@ int sv_isa(SV *, char *0;
</div>
<H2><a name="Perl5_nn32"></a>31.8 Typemap Examples</H2>
<H2><a name="Perl5_nn32"></a>32.8 Typemap Examples</H2>
<p>
@ -2118,7 +2127,7 @@ might look at the files "<tt>perl5.swg</tt>" and "<tt>typemaps.i</tt>" in
the SWIG library.
</p>
<H3><a name="Perl5_nn33"></a>31.8.1 Converting a Perl5 array to a char **</H3>
<H3><a name="Perl5_nn33"></a>32.8.1 Converting a Perl5 array to a char **</H3>
<p>
@ -2210,7 +2219,7 @@ print @$b,"\n"; # Print it out
</pre></div>
<H3><a name="Perl5_nn34"></a>31.8.2 Return values</H3>
<H3><a name="Perl5_nn34"></a>32.8.2 Return values</H3>
<p>
@ -2239,7 +2248,7 @@ can be done using the <tt>EXTEND()</tt> macro as in:
}
</pre></div>
<H3><a name="Perl5_nn35"></a>31.8.3 Returning values from arguments</H3>
<H3><a name="Perl5_nn35"></a>32.8.3 Returning values from arguments</H3>
<p>
@ -2293,7 +2302,7 @@ print "multout(7,13) = @r\n";
($x,$y) = multout(7,13);
</pre></div>
<H3><a name="Perl5_nn36"></a>31.8.4 Accessing array structure members</H3>
<H3><a name="Perl5_nn36"></a>32.8.4 Accessing array structure members</H3>
<p>
@ -2356,7 +2365,7 @@ the "in" typemap in the previous section would be used to convert an
to copy the converted array into a C data structure.
</p>
<H3><a name="Perl5_nn37"></a>31.8.5 Turning Perl references into C pointers</H3>
<H3><a name="Perl5_nn37"></a>32.8.5 Turning Perl references into C pointers</H3>
<p>
@ -2421,7 +2430,7 @@ print "$c\n";
</pre></div>
<H3><a name="Perl5_nn38"></a>31.8.6 Pointer handling</H3>
<H3><a name="Perl5_nn38"></a>32.8.6 Pointer handling</H3>
<p>
@ -2500,7 +2509,7 @@ For example:
</pre>
</div>
<H2><a name="Perl5_nn39"></a>31.9 Proxy classes</H2>
<H2><a name="Perl5_nn39"></a>32.9 Proxy classes</H2>
<p>
@ -2516,7 +2525,7 @@ to the underlying code. This section describes the implementation
details of the proxy interface.
</p>
<H3><a name="Perl5_nn40"></a>31.9.1 Preliminaries</H3>
<H3><a name="Perl5_nn40"></a>32.9.1 Preliminaries</H3>
<p>
@ -2538,7 +2547,7 @@ SWIG creates a collection of high-level Perl wrappers. In your scripts, you wil
high level wrappers. The wrappers, in turn, interact with the low-level procedural module.
</p>
<H3><a name="Perl5_nn41"></a>31.9.2 Structure and class wrappers</H3>
<H3><a name="Perl5_nn41"></a>32.9.2 Structure and class wrappers</H3>
<p>
@ -2664,7 +2673,7 @@ $v-&gt;DESTROY();
</pre></div>
<H3><a name="Perl5_nn42"></a>31.9.3 Object Ownership</H3>
<H3><a name="Perl5_nn42"></a>32.9.3 Object Ownership</H3>
<p>
@ -2751,7 +2760,7 @@ counting, garbage collection, or advanced features one might find in
sophisticated languages.
</p>
<H3><a name="Perl5_nn43"></a>31.9.4 Nested Objects</H3>
<H3><a name="Perl5_nn43"></a>32.9.4 Nested Objects</H3>
<p>
@ -2804,7 +2813,7 @@ $p-&gt;{f}-&gt;{x} = 0.0;
%${$p-&gt;{v}} = ( x=&gt;0, y=&gt;0, z=&gt;0);
</pre></div>
<H3><a name="Perl5_nn44"></a>31.9.5 Proxy Functions</H3>
<H3><a name="Perl5_nn44"></a>32.9.5 Proxy Functions</H3>
<p>
@ -2838,7 +2847,7 @@ This function replaces the original function, but operates in an
identical manner.
</p>
<H3><a name="Perl5_nn45"></a>31.9.6 Inheritance</H3>
<H3><a name="Perl5_nn45"></a>32.9.6 Inheritance</H3>
<p>
@ -2914,7 +2923,7 @@ particular, inheritance of data members is extremely tricky (and I'm
not even sure if it really works).
</p>
<H3><a name="Perl5_nn46"></a>31.9.7 Modifying the proxy methods</H3>
<H3><a name="Perl5_nn46"></a>32.9.7 Modifying the proxy methods</H3>
<p>
@ -2942,7 +2951,7 @@ public:
};
</pre></div>
<H2><a name="Perl5_nn47"></a>31.10 Adding additional Perl code</H2>
<H2><a name="Perl5_nn47"></a>32.10 Adding additional Perl code</H2>
<p>
@ -2993,6 +3002,363 @@ set_transform($im, $a);
</pre>
</div>
<H2><a name="Perl5_directors"></a>32.11 Cross language polymorphism</H2>
<p>
Proxy classes provide a more natural, object-oriented way to access
extension classes. As described above, each proxy instance has an
associated C++ instance, and method calls to the proxy are passed to the
C++ instance transparently via C wrapper functions.
</p>
<p>
This arrangement is asymmetric in the sense that no corresponding
mechanism exists to pass method calls down the inheritance chain from
C++ to Perl. In particular, if a C++ class has been extended in Perl
(by extending the proxy class), these extensions will not be visible
from C++ code. Virtual method calls from C++ are thus not able access
the lowest implementation in the inheritance chain.
</p>
<p>
Changes have been made to SWIG to address this problem and
make the relationship between C++ classes and proxy classes more
symmetric. To achieve this goal, new classes called directors are
introduced at the bottom of the C++ inheritance chain. The job of the
directors is to route method calls correctly, either to C++
implementations higher in the inheritance chain or to Perl
implementations lower in the inheritance chain. The upshot is that C++
classes can be extended in Perl and from C++ these extensions look
exactly like native C++ classes. Neither C++ code nor Perl code needs
to know where a particular method is implemented: the combination of
proxy classes, director classes, and C wrapper functions takes care of
all the cross-language method routing transparently.
</p>
<H3><a name="Perl5_nn48"></a>32.11.1 Enabling directors</H3>
<p>
The director feature is disabled by default. To use directors you
must make two changes to the interface file. First, add the "directors"
option to the %module directive, like this:
</p>
<div class="code">
<pre>
%module(directors="1") modulename
</pre>
</div>
<p>
Without this option no director code will be generated. Second, you
must use the %feature("director") directive to tell SWIG which classes
and methods should get directors. The %feature directive can be applied
globally, to specific classes, and to specific methods, like this:
</p>
<div class="code">
<pre>
// generate directors for all classes that have virtual methods
%feature("director");
// generate directors for all virtual methods in class Foo
%feature("director") Foo;
</pre>
</div>
<p>
You can use the %feature("nodirector") directive to turn off
directors for specific classes or methods. So for example,
</p>
<div class="code">
<pre>
%feature("director") Foo;
%feature("nodirector") Foo::bar;
</pre>
</div>
<p>
will generate directors for all virtual methods of class Foo except
bar().
</p>
<p>
Directors can also be generated implicitly through inheritance.
In the following, class Bar will get a director class that handles
the methods one() and two() (but not three()):
</p>
<div class="code">
<pre>
%feature("director") Foo;
class Foo {
public:
Foo(int foo);
virtual void one();
virtual void two();
};
class Bar: public Foo {
public:
virtual void three();
};
</pre>
</div>
<p>
then at the Perl side you can define
</p>
<div class="targetlang">
<pre>
use mymodule;
package MyFoo;
use base 'mymodule::Foo';
sub one {
print "one from Perl\n";
}
</pre>
</div>
<H3><a name="Perl5_nn49"></a>32.11.2 Director classes</H3>
<p>
For each class that has directors enabled, SWIG generates a new class
that derives from both the class in question and a special
<tt>Swig::Director</tt> class. These new classes, referred to as director
classes, can be loosely thought of as the C++ equivalent of the Perl
proxy classes. The director classes store a pointer to their underlying
Perl object and handle various issues related to object ownership.
</p>
<p>
For simplicity let's ignore the <tt>Swig::Director</tt> class and refer to the
original C++ class as the director's base class. By default, a director
class extends all virtual methods in the inheritance chain of its base
class (see the preceding section for how to modify this behavior).
Thus all virtual method calls, whether they originate in C++ or in
Perl via proxy classes, eventually end up in at the implementation in
the director class. The job of the director methods is to route these
method calls to the appropriate place in the inheritance chain. By
"appropriate place" we mean the method that would have been called if
the C++ base class and its extensions in Perl were seamlessly
integrated. That seamless integration is exactly what the director
classes provide, transparently skipping over all the messy extension API
glue that binds the two languages together.
</p>
<p>
In reality, the "appropriate place" is one of only two possibilities:
C++ or Perl. Once this decision is made, the rest is fairly easy. If
the correct implementation is in C++, then the lowest implementation of
the method in the C++ inheritance chain is called explicitly. If the
correct implementation is in Perl, the Perl API is used to call the
method of the underlying Perl object (after which the usual virtual
method resolution in Perl automatically finds the right
implementation).
</p>
<p>
Now how does the director decide which language should handle the method call?
The basic rule is to handle the method in Perl, unless there's a good
reason not to. The reason for this is simple: Perl has the most
"extended" implementation of the method. This assertion is guaranteed,
since at a minimum the Perl proxy class implements the method. If the
method in question has been extended by a class derived from the proxy
class, that extended implementation will execute exactly as it should.
If not, the proxy class will route the method call into a C wrapper
function, expecting that the method will be resolved in C++. The wrapper
will call the virtual method of the C++ instance, and since the director
extends this the call will end up right back in the director method. Now
comes the "good reason not to" part. If the director method were to blindly
call the Perl method again, it would get stuck in an infinite loop. We avoid this
situation by adding special code to the C wrapper function that tells
the director method to not do this. The C wrapper function compares the
pointer to the Perl object that called the wrapper function to the
pointer stored by the director. If these are the same, then the C
wrapper function tells the director to resolve the method by calling up
the C++ inheritance chain, preventing an infinite loop.
</p>
<p>
One more point needs to be made about the relationship between director
classes and proxy classes. When a proxy class instance is created in
Perl, SWIG creates an instance of the original C++ class.
This is exactly what happens without directors and
is true even if directors are enabled for the particular class in
question. When a class <i>derived</i> from a proxy class is created,
however, SWIG then creates an instance of the corresponding C++ director
class. The reason for this difference is that user-defined subclasses
may override or extend methods of the original class, so the director
class is needed to route calls to these methods correctly. For
unmodified proxy classes, all methods are ultimately implemented in C++
so there is no need for the extra overhead involved with routing the
calls through Perl.
</p>
<H3><a name="Perl5_nn50"></a>32.11.3 Ownership and object destruction</H3>
<p>
Memory management issues are slightly more complicated with directors
than for proxy classes alone. Perl instances hold a pointer to the
associated C++ director object, and the director in turn holds a pointer
back to a Perl object. By default, proxy classes own their C++
director object and take care of deleting it when they are garbage
collected.
</p>
<p>
This relationship can be reversed by calling the special
<tt>DISOWN()</tt> method of the proxy class. After calling this
method the director
class increments the reference count of the Perl object. When the
director class is deleted it decrements the reference count. Assuming no
outstanding references to the Perl object remain, the Perl object
will be destroyed at the same time. This is a good thing, since
directors and proxies refer to each other and so must be created and
destroyed together. Destroying one without destroying the other will
likely cause your program to segfault.
</p>
<p>
Also note that due to the proxy implementation, the <tt>DESTROY()</tt>
method on directors can be called for several reasons, many of which
have little to do with the teardown of an object instance. To help
disambiguate this, a second argument is added to the <tt>DESTROY()</tt>
call when a C++ director object is being released. So, to avoid running
your clean-up code when an object is not really going away, or after it
has already been reclaimed, it is suggested that custom destructors in
Perl subclasses looks something like:
</p>
<div class="targetlang">
<pre>
sub DESTROY {
my($self, $final) = @_;
if($final) {
# real teardown code
}
shift-&gt;SUPER::DESTROY(@_);
}
</pre>
</div>
<H3><a name="Perl5_nn51"></a>32.11.4 Exception unrolling</H3>
<p>
With directors routing method calls to Perl, and proxies routing them
to C++, the handling of exceptions is an important concern. By default, the
directors ignore exceptions that occur during method calls that are
resolved in Perl. To handle such exceptions correctly, it is necessary
to temporarily translate them into C++ exceptions. This can be done with
the %feature("director:except") directive. The following code should
suffice in most cases:
</p>
<div class="code">
<pre>
%feature("director:except") {
if ($error != NULL) {
throw Swig::DirectorMethodException();
}
}
</pre>
</div>
<p>
This code will check the Perl error state after each method call from
a director into Perl, and throw a C++ exception if an error occurred.
This exception can be caught in C++ to implement an error handler.
</p>
<p>
It may be the case that a method call originates in Perl, travels up
to C++ through a proxy class, and then back into Perl via a director
method. If an exception occurs in Perl at this point, it would be nice
for that exception to find its way back to the original caller. This can
be done by combining a normal %exception directive with the
<tt>director:except</tt> handler shown above. Here is an example of a
suitable exception handler:
</p>
<div class="code">
<pre>
%exception {
try { $action }
catch (Swig::DirectorException &amp;e) { SWIG_fail; }
}
</pre>
</div>
<p>
The class Swig::DirectorException used in this example is actually a
base class of Swig::DirectorMethodException, so it will trap this
exception. Because the Perl error state is still set when
Swig::DirectorMethodException is thrown, Perl will register the
exception as soon as the C wrapper function returns.
</p>
<H3><a name="Perl5_nn52"></a>32.11.5 Overhead and code bloat</H3>
<p>
Enabling directors for a class will generate a new director method for
every virtual method in the class' inheritance chain. This alone can
generate a lot of code bloat for large hierarchies. Method arguments
that require complex conversions to and from target language types can
result in large director methods. For this reason it is recommended that
you selectively enable directors only for specific classes that are
likely to be extended in Perl and used in C++.
</p>
<p>
Compared to classes that do not use directors, the call routing in the
director methods does add some overhead. In particular, at least one
dynamic cast and one extra function call occurs per method call from
Perl. Relative to the speed of Perl execution this is probably
completely negligible. For worst case routing, a method call that
ultimately resolves in C++ may take one extra detour through Perl in
order to ensure that the method does not have an extended Perl
implementation. This could result in a noticeable overhead in some cases.
</p>
<p>
Although directors make it natural to mix native C++ objects with Perl
objects (as director objects) via a common base class pointer, one
should be aware of the obvious fact that method calls to Perl objects
will be much slower than calls to C++ objects. This situation can be
optimized by selectively enabling director methods (using the %feature
directive) for only those methods that are likely to be extended in
Perl.
</p>
<H3><a name="Perl5_nn53"></a>32.11.6 Typemaps</H3>
<p>
Typemaps for input and output of most of the basic types from director
classes have been written. These are roughly the reverse of the usual
input and output typemaps used by the wrapper code. The typemap
operation names are 'directorin', 'directorout', and 'directorargout'.
The director code does not currently use any of the other kinds of typemaps.
It is not clear at this point which kinds are appropriate and
need to be supported.
</p>
</body>

View file

@ -7,7 +7,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Php"></a>32 SWIG and PHP</H1>
<H1><a name="Php"></a>33 SWIG and PHP</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -79,7 +79,7 @@ your extension into php directly, you will need the complete PHP source tree
available.
</p>
<H2><a name="Php_nn1"></a>32.1 Generating PHP Extensions</H2>
<H2><a name="Php_nn1"></a>33.1 Generating PHP Extensions</H2>
<p>
@ -126,7 +126,7 @@ and it doesn't play nicely with package system. We don't recommend
this approach, or provide explicit support for it.
</p>
<H3><a name="Php_nn1_1"></a>32.1.1 Building a loadable extension</H3>
<H3><a name="Php_nn1_1"></a>33.1.1 Building a loadable extension</H3>
<p>
@ -141,12 +141,12 @@ least work for Linux though):
gcc -shared example_wrap.o -o example.so
</pre></div>
<H3><a name="Php_nn1_3"></a>32.1.2 Using PHP Extensions</H3>
<H3><a name="Php_nn1_3"></a>33.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 the <tt>[PHP]</tt> section of
can load it for every script by adding this line to the <tt>[PHP]</tt> section of
<tt>php.ini</tt>:
</p>
@ -156,7 +156,7 @@ can load it for every script by adding this line the <tt>[PHP]</tt> section of
<p>
Alternatively, you can load it explicitly only for scripts which need it
by adding this line:
by adding this line to the start of each such PHP script::
</p>
<div class="code"><pre>
@ -164,7 +164,7 @@ by adding this line:
</pre></div>
<p>
to the start of each PHP file. SWIG also generates a php module, which
SWIG also generates a php module, which
attempts to do the <tt>dl()</tt> call for you:
</p>
@ -172,7 +172,7 @@ attempts to do the <tt>dl()</tt> call for you:
include("example.php");
</pre></div>
<H2><a name="Php_nn2"></a>32.2 Basic PHP interface</H2>
<H2><a name="Php_nn2"></a>33.2 Basic PHP interface</H2>
<p>
@ -183,7 +183,7 @@ other symbols unless care is taken to <tt>%rename</tt> them. At present
SWIG doesn't have support for the namespace feature added in PHP 5.3.
</p>
<H3><a name="Php_nn2_1"></a>32.2.1 Constants</H3>
<H3><a name="Php_nn2_1"></a>33.2.1 Constants</H3>
<p>
@ -260,7 +260,7 @@ is treated as true by the if test, when the value of the intended constant
would be treated as false!
</p>
<H3><a name="Php_nn2_2"></a>32.2.2 Global Variables</H3>
<H3><a name="Php_nn2_2"></a>33.2.2 Global Variables</H3>
<p>
@ -309,7 +309,7 @@ undefined.
At this time SWIG does not support custom accessor methods.
</p>
<H3><a name="Php_nn2_3"></a>32.2.3 Functions</H3>
<H3><a name="Php_nn2_3"></a>33.2.3 Functions</H3>
<p>
@ -362,7 +362,7 @@ print $s; # The value of $s was not changed.
-->
<H3><a name="Php_nn2_4"></a>32.2.4 Overloading</H3>
<H3><a name="Php_nn2_4"></a>33.2.4 Overloading</H3>
<p>
@ -418,7 +418,7 @@ taking the integer argument.
</p>
-->
<H3><a name="Php_nn2_5"></a>32.2.5 Pointers and References</H3>
<H3><a name="Php_nn2_5"></a>33.2.5 Pointers and References</H3>
<p>
@ -503,7 +503,20 @@ echo "The sum $in1 + $in2 = $result\n";
Because PHP has a native concept of reference, it may seem more natural
to the PHP developer to use references to pass pointers. To enable
this, one needs to include <b>phppointers.i</b> which defines the
named typemap REFERENCE.
named typemap REF.
</p>
<p>
Prior to SWIG 3.0, the REF typemaps relied on PHP's call-time
pass-by-reference, which was deprecated in PHP 5.3 and removed in PHP 5.4.
So if you use these REF typemaps, you should ensure that SWIG&ge;3.0 is
used to generate wrappers from your interface file.
</p>
<p>
In case you write your own typemaps, SWIG supports an attribute called
<tt>byref</tt>: if you set that, then SWIG will make sure that the generated
wrapper function will want the input parameter as a reference.
</p>
<div class="code"><pre>
@ -526,7 +539,7 @@ include("example.php");
$in1 = 3;
$in2 = 5;
$result = 0;
add(&amp;$in1,&amp;$in2,&amp;$result);
add($in1,$in2,$result);
echo "The sum $in1 + $in2 = $result\n";
?&gt;
@ -550,7 +563,7 @@ PHP in a number of ways: by using <tt>unset</tt> on an existing
variable, or assigning <tt>NULL</tt> to a variable.
</p>
<H3><a name="Php_nn2_6"></a>32.2.6 Structures and C++ classes</H3>
<H3><a name="Php_nn2_6"></a>33.2.6 Structures and C++ classes</H3>
<p>
@ -611,7 +624,7 @@ Would be used in the following way from PHP5:
Member variables and methods are accessed using the <tt>-&gt;</tt> operator.
</p>
<H4><a name="Php_nn2_6_1"></a>32.2.6.1 Using <tt>-noproxy</tt></H4>
<H4><a name="Php_nn2_6_1"></a>33.2.6.1 Using <tt>-noproxy</tt></H4>
<p>
@ -637,7 +650,7 @@ Complex_im_set($obj,$d);
Complex_im_get($obj);
</pre></div>
<H4><a name="Php_nn2_6_2"></a>32.2.6.2 Constructors and Destructors</H4>
<H4><a name="Php_nn2_6_2"></a>33.2.6.2 Constructors and Destructors</H4>
<p>
@ -678,7 +691,7 @@ the programmer can either reassign the variable or call
<tt>unset($v)</tt>
</p>
<H4><a name="Php_nn2_6_3"></a>32.2.6.3 Static Member Variables</H4>
<H4><a name="Php_nn2_6_3"></a>33.2.6.3 Static Member Variables</H4>
<p>
@ -705,7 +718,7 @@ would be accessed in PHP as,
<div class="code"><pre>
include("example.php");
echo "There has now been " . Ko::threats() . " threats\n";
echo "There have now been " . Ko::threats() . " threats\n";
</pre></div>
@ -718,10 +731,10 @@ function, e.g.
Ko::threats(10);
echo "There has now been " . Ko::threats() . " threats\n";
echo "There have now been " . Ko::threats() . " threats\n";
</pre></div>
<H4><a name="Php_nn2_6_4"></a>32.2.6.4 Static Member Functions</H4>
<H4><a name="Php_nn2_6_4"></a>33.2.6.4 Static Member Functions</H4>
<p>
@ -743,7 +756,7 @@ Ko::threats();
</pre></div>
<H3><a name="Php_nn2_7"></a>32.2.7 PHP Pragmas, Startup and Shutdown code</H3>
<H3><a name="Php_nn2_7"></a>33.2.7 PHP Pragmas, Startup and Shutdown code</H3>
<p>
@ -831,7 +844,7 @@ The <tt>%rinit</tt> and <tt>%rshutdown</tt> statements are very similar but inse
into the request init (PHP_RINIT_FUNCTION) and request shutdown (PHP_RSHUTDOWN_FUNCTION) code respectively.
</p>
<H2><a name="Php_nn3"></a>32.3 Cross language polymorphism</H2>
<H2><a name="Php_nn3"></a>33.3 Cross language polymorphism</H2>
<p>
@ -866,7 +879,7 @@ wrapper functions takes care of all the cross-language method routing
transparently.
</p>
<H3><a name="Php_nn3_1"></a>32.3.1 Enabling directors</H3>
<H3><a name="Php_nn3_1"></a>33.3.1 Enabling directors</H3>
<p>
@ -895,9 +908,6 @@ globally, to specific classes, and to specific methods, like this:
// generate directors for all virtual methods in class Foo
%feature("director") Foo;
// generate a director for just Foo::bar()
%feature("director") Foo::bar;
</pre>
</div>
@ -958,7 +968,7 @@ class MyFoo extends Foo {
</div>
<H3><a name="Php_nn3_2"></a>32.3.2 Director classes</H3>
<H3><a name="Php_nn3_2"></a>33.3.2 Director classes</H3>
@ -1038,7 +1048,7 @@ so there is no need for the extra overhead involved with routing the
calls through PHP.
</p>
<H3><a name="Php_nn3_3"></a>32.3.3 Ownership and object destruction</H3>
<H3><a name="Php_nn3_3"></a>33.3.3 Ownership and object destruction</H3>
<p>
@ -1094,7 +1104,7 @@ In this example, we are assuming that FooContainer will take care of
deleting all the Foo pointers it contains at some point.
</p>
<H3><a name="Php_nn3_4"></a>32.3.4 Exception unrolling</H3>
<H3><a name="Php_nn3_4"></a>33.3.4 Exception unrolling</H3>
<p>
@ -1153,7 +1163,7 @@ Swig::DirectorMethodException is thrown, PHP will register the exception
as soon as the C wrapper function returns.
</p>
<H3><a name="Php_nn3_5"></a>32.3.5 Overhead and code bloat</H3>
<H3><a name="Php_nn3_5"></a>33.3.5 Overhead and code bloat</H3>
<p>
@ -1186,7 +1196,7 @@ optimized by selectively enabling director methods (using the %feature
directive) for only those methods that are likely to be extended in PHP.
</p>
<H3><a name="Php_nn3_6"></a>32.3.6 Typemaps</H3>
<H3><a name="Php_nn3_6"></a>33.3.6 Typemaps</H3>
<p>
@ -1200,7 +1210,7 @@ need to be supported.
</p>
<H3><a name="Php_nn3_7"></a>32.3.7 Miscellaneous</H3>
<H3><a name="Php_nn3_7"></a>33.3.7 Miscellaneous</H3>
<p> Director typemaps for STL classes are mostly in place, and hence you

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Pike"></a>33 SWIG and Pike</H1>
<H1><a name="Pike"></a>34 SWIG and Pike</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -46,10 +46,10 @@ least, make sure you read the "<a href="SWIG.html#SWIG">SWIG Basics</a>"
chapter.<br>
</p>
<H2><a name="Pike_nn2"></a>33.1 Preliminaries</H2>
<H2><a name="Pike_nn2"></a>34.1 Preliminaries</H2>
<H3><a name="Pike_nn3"></a>33.1.1 Running SWIG</H3>
<H3><a name="Pike_nn3"></a>34.1.1 Running SWIG</H3>
<p>
@ -94,7 +94,7 @@ can use the <tt>-o</tt> option:
<div class="code">
<pre>$ <b>swig -pike -o pseudonym.c example.i</b><br></pre>
</div>
<H3><a name="Pike_nn4"></a>33.1.2 Getting the right header files</H3>
<H3><a name="Pike_nn4"></a>34.1.2 Getting the right header files</H3>
<p>
@ -114,7 +114,7 @@ You're looking for files with the names <tt>global.h</tt>, <tt>program.h</tt>
and so on.
</p>
<H3><a name="Pike_nn5"></a>33.1.3 Using your module</H3>
<H3><a name="Pike_nn5"></a>34.1.3 Using your module</H3>
<p>
@ -129,10 +129,10 @@ Pike v7.4 release 10 running Hilfe v3.5 (Incremental Pike Frontend)
(1) Result: 24
</pre></div>
<H2><a name="Pike_nn6"></a>33.2 Basic C/C++ Mapping</H2>
<H2><a name="Pike_nn6"></a>34.2 Basic C/C++ Mapping</H2>
<H3><a name="Pike_nn7"></a>33.2.1 Modules</H3>
<H3><a name="Pike_nn7"></a>34.2.1 Modules</H3>
<p>
@ -143,7 +143,7 @@ concerned), SWIG's <tt>%module</tt> directive doesn't really have any
significance.
</p>
<H3><a name="Pike_nn8"></a>33.2.2 Functions</H3>
<H3><a name="Pike_nn8"></a>34.2.2 Functions</H3>
<p>
@ -168,7 +168,7 @@ exactly as you'd expect it to:
(1) Result: 24
</pre></div>
<H3><a name="Pike_nn9"></a>33.2.3 Global variables</H3>
<H3><a name="Pike_nn9"></a>34.2.3 Global variables</H3>
<p>
@ -197,7 +197,7 @@ will result in two functions, <tt>Foo_get()</tt> and <tt>Foo_set()</tt>:
(3) Result: 3.141590
</pre></div>
<H3><a name="Pike_nn10"></a>33.2.4 Constants and enumerated types</H3>
<H3><a name="Pike_nn10"></a>34.2.4 Constants and enumerated types</H3>
<p>
@ -205,7 +205,7 @@ Enumerated types in C/C++ declarations are wrapped as Pike constants,
not as Pike enums.
</p>
<H3><a name="Pike_nn11"></a>33.2.5 Constructors and Destructors</H3>
<H3><a name="Pike_nn11"></a>34.2.5 Constructors and Destructors</H3>
<p>
@ -213,7 +213,7 @@ Constructors are wrapped as <tt>create()</tt> methods, and destructors are
wrapped as <tt>destroy()</tt> methods, for Pike classes.
</p>
<H3><a name="Pike_nn12"></a>33.2.6 Static Members</H3>
<H3><a name="Pike_nn12"></a>34.2.6 Static Members</H3>
<p>

View file

@ -12,13 +12,23 @@
<ul>
<li><a href="#Preface_nn2">Introduction</a>
<li><a href="#Preface_nn4">SWIG Versions</a>
<li><a href="#Preface_license">SWIG License</a>
<li><a href="#Preface_nn5">SWIG resources</a>
<li><a href="#Preface_nn6">Prerequisites</a>
<li><a href="#Preface_nn7">Organization of this manual</a>
<li><a href="#Preface_nn8">How to avoid reading the manual</a>
<li><a href="#Preface_nn9">Backwards compatibility</a>
<li><a href="#Preface_release_notes">Release notes</a>
<li><a href="#Preface_nn10">Credits</a>
<li><a href="#Preface_nn11">Bug reports</a>
<li><a href="#Preface_installation">Installation</a>
<ul>
<li><a href="#Preface_windows_installation">Windows installation</a>
<li><a href="#Preface_unix_installation">Unix installation</a>
<li><a href="#Preface_osx_installation">Macintosh OS X installation</a>
<li><a href="#Preface_testing">Testing</a>
<li><a href="#Preface_examples">Examples</a>
</ul>
</ul>
</div>
<!-- INDEX -->
@ -57,13 +67,26 @@ In the late 1990's, the most stable version of SWIG was release
over a period of 10 years starting from the year 2000. The final version in the 1.3.x
series was 1.3.40, but in truth the 1.3.x series had been stable for many years.
An official stable version was released along with the decision to make SWIG
license changes and this gave rise to version 2.0.0 in 2010. The license was clarified
license changes and this gave rise to version 2.0.0 in 2010.
</p>
<H2><a name="Preface_license"></a>1.3 SWIG License</H2>
<p>
The LICENSE file shipped with SWIG in the top level directory contains the SWIG license.
For further insight into the license including the license of SWIG's output code, please visit
the SWIG legal page - <a href="http://www.swig.org/legal.html">http://www.swig.org/legal.html</a>.
</p>
<p>
The license was clarified in version 2.0.0
so that the code that SWIG generated could be distributed
under license terms of the user's choice/requirements and at the same time the SWIG
source was placed under the GNU General Public License version 3.
</p>
<H2><a name="Preface_nn5"></a>1.3 SWIG resources</H2>
<H2><a name="Preface_nn5"></a>1.4 SWIG resources</H2>
<p>
@ -93,16 +116,17 @@ SWIG along with information about beta releases and future work.
</p>
<p>
Subversion access to the latest version of SWIG is also available. More information
Git and Subversion access to the latest version of SWIG is also available. More information
about this can be obtained at:
</p>
<div class="shell"><pre>
<a href="http://www.swig.org/svn.html">http://www.swig.org/svn.html</a>
<a href="http://www.swig.org/svn.html">SWIG Bleeding Edge</a>
</pre></div>
<H2><a name="Preface_nn6"></a>1.4 Prerequisites</H2>
<H2><a name="Preface_nn6"></a>1.5 Prerequisites</H2>
<p>
@ -127,7 +151,7 @@ However, this isn't meant to be a tutorial on C++ programming. For many
of the gory details, you will almost certainly want to consult a good C++ reference. If you don't program
in C++, you may just want to skip those parts of the manual.
<H2><a name="Preface_nn7"></a>1.5 Organization of this manual</H2>
<H2><a name="Preface_nn7"></a>1.6 Organization of this manual</H2>
<p>
@ -139,7 +163,7 @@ can probably skip to that chapter and find almost everything you need
to know.
</p>
<H2><a name="Preface_nn8"></a>1.6 How to avoid reading the manual</H2>
<H2><a name="Preface_nn8"></a>1.7 How to avoid reading the manual</H2>
<p>
@ -151,7 +175,7 @@ The SWIG distribution also comes with a large directory of
examples that illustrate different topics.
</p>
<H2><a name="Preface_nn9"></a>1.7 Backwards compatibility</H2>
<H2><a name="Preface_nn9"></a>1.8 Backwards compatibility</H2>
<p>
@ -162,8 +186,8 @@ this isn't always possible as the
primary goal over time is to make SWIG
better---a process that would simply be impossible if the developers
are constantly bogged down with backwards compatibility issues.
Potential incompatibilities are clearly marked in the detailed release notes
(CHANGES files).
Potential incompatibilities are clearly marked in the detailed
<a href="#Preface_release_notes">release notes</a>.
</p>
@ -187,7 +211,16 @@ Note: The version symbol is not defined in the generated SWIG
wrapper file. The SWIG preprocessor has defined SWIG_VERSION since SWIG-1.3.11.
</p>
<H2><a name="Preface_nn10"></a>1.8 Credits</H2>
<H2><a name="Preface_release_notes"></a>1.9 Release notes</H2>
<p>
The CHANGES.current, CHANGES and RELEASENOTES files shipped with SWIG in the top level directory
contain, respectively, detailed release notes for the current version,
detailed release notes for previous releases and summary release notes from SWIG-1.3.22 onwards.
</p>
<H2><a name="Preface_nn10"></a>1.10 Credits</H2>
<p>
@ -200,7 +233,7 @@ who have made contributions at all levels over time. Contributors
are mentioned either in the COPYRIGHT file or CHANGES files shipped with SWIG or in submitted bugs.
</p>
<H2><a name="Preface_nn11"></a>1.9 Bug reports</H2>
<H2><a name="Preface_nn11"></a>1.11 Bug reports</H2>
<p>
@ -215,5 +248,204 @@ used, and any important pieces of the SWIG generated wrapper code. We
can only fix bugs if we know about them.
</p>
<H2><a name="Preface_installation"></a>1.12 Installation</H2>
<H3><a name="Preface_windows_installation"></a>1.12.1 Windows installation</H3>
<p>
Please see the dedicated <a href="Windows.html">Windows chapter</a> for instructions on installing
SWIG on Windows and running the examples. The Windows distribution is
called swigwin and includes a prebuilt SWIG executable, swig.exe, included in
the top level directory. Otherwise it is exactly the same as
the main SWIG distribution. There is no need to download anything else.
</p>
<H3><a name="Preface_unix_installation"></a>1.12.2 Unix installation</H3>
<p>
You must use <a href="http://www.gnu.org/software/make/">GNU make</a> to build and install SWIG.
</p>
<p>
<a href="http://www.pcre.org/">PCRE</a>
needs to be installed on your system to build SWIG, in particular
pcre-config must be available. If you have PCRE headers and libraries but not
pcre-config itself or, alternatively, wish to override the compiler or linker
flags returned by pcre-config, you may set PCRE_LIBS and PCRE_CFLAGS variables
to be used instead. And if you don't have PCRE at all, the configure script
will provide instructions for obtaining it.
</p>
<p>
To build and install SWIG, simply type the following:
</p>
<div class="shell"><pre>
$ ./configure
$ make
$ make install
</pre></div>
<p>
By default SWIG installs itself in /usr/local. If you need to install SWIG in
a different location or in your home directory, use the <tt>--prefix</tt> option
to <tt>./configure</tt>. For example:
</p>
<div class="shell"><pre>
$ ./configure --prefix=/home/yourname/projects
$ make
$ make install
</pre></div>
<p>
Note: the directory given to <tt>--prefix</tt> must be an absolute pathname. Do <b>not</b> use
the ~ shell-escape to refer to your home directory. SWIG won't work properly
if you do this.
</p>
<p>
The INSTALL file shipped in the top level directory details more about using configure. Also try
</p>
<div class="shell"><pre>
$ ./configure --help.
</pre></div>
<p>
The configure script will attempt to locate various packages on your machine
including Tcl, Perl5, Python and all the other target languages that SWIG
supports. Don't panic if you get 'not found' messages -- SWIG does not need these
packages to compile or run. The configure script is actually looking for
these packages so that you can try out the SWIG examples contained
in the 'Examples' directory without having to hack Makefiles.
Note that the <tt>--without-xxx</tt> options, where xxx is a target language, have
minimal effect. All they do is reduce the amount of testing done with
'make check'. The SWIG executable and library files installed cannot currently
be configured with a subset of target languages.
</p>
<p>
SWIG used to include a set of runtime libraries for some languages for working
with multiple modules. These are no longer built during the installation stage.
However, users can build them just like any wrapper module as described in
the <a href="Modules.html">Modules chapter</a>.
The CHANGES file shipped with SWIG in the top level directory
also lists some examples which build the runtime library.
</p>
<p>
Note:
</p>
<ul>
<li>
If you checked the code out via Git, you will have to run <tt>./autogen.sh</tt>
before <tt>./configure</tt>. In addition, a full build of SWIG requires
a number of packages to be installed. Full instructions at
<a href="http://www.swig.org/svn.html">SWIG bleeding edge</a>.
</li>
</ul>
<H3><a name="Preface_osx_installation"></a>1.12.3 Macintosh OS X installation</H3>
<p>
SWIG is known to work on various flavors of OS X. Follow the Unix installation
instructions above. However, as of this writing, there is still great deal of
inconsistency with how shared libaries are handled by various scripting languages
on OS X.
</p>
<p>
Users of OS X should be aware that Darwin handles shared libraries and linking in
a radically different way than most Unix systems. In order to test SWIG and run
the examples, SWIG configures itself to use flat namespaces and to allow undefined
symbols (<tt>-flat_namespace -undefined suppress</tt>). This mostly closely follows the Unix
model and makes it more likely that the SWIG examples will work with whatever
installation of software you might have. However, this is generally not the recommended
technique for building larger extension modules. Instead, you should utilize
Darwin's two-level namespaces. Some details about this can be found here
<a href="http://developer.apple.com/documentation/ReleaseNotes/DeveloperTools/TwoLevelNamespaces.html">http://developer.apple.com/documentation/ReleaseNotes/DeveloperTools/TwoLevelNamespaces.html</a>.
</p>
<p>
Needless to say, you might have to experiment a bit to get things working at first.
</p>
<H3><a name="Preface_testing"></a>1.12.4 Testing</H3>
<p>
If you want to test SWIG after building it, a check can be performed on Unix operating systems.
Type the following:
</p>
<div class="shell"><pre>
$ make -k check
</pre></div>
<p>
This step can be performed either before or after installation.
The check requires at least one of the target languages to be
installed. If it fails, it may mean that you have an uninstalled
language module or that the file 'Examples/Makefile' has been
incorrectly configured. It may also fail due to compiler issues such
as a broken C++ compiler. Even if the check fails, there is a
pretty good chance SWIG still works correctly --- you will just have to
mess around with one of the examples and some makefiles to get it to work.
Some tests may also fail due to missing dependency packages, eg PCRE
or Boost, but this will require careful analysis of the configure output
done during configuration.
</p>
<p>
The test suite executed by the check is designed to stress-test
many parts of the implementation including obscure corner cases. If some
of these tests fail or generate warning messages, there is no reason for
alarm --- the test may be related to some new SWIG feature or a difficult bug
that we're trying to resolve. Chances are that SWIG will work just fine
for you. Note that if you have more than one CPU/core, then you can use
parallel make to speed up the check as it does take quite some time to run,
for example:
</p>
<div class="shell"><pre>
$ make -j2 -k check
</pre></div>
<p>
Also, SWIG's support for C++ is sufficiently advanced that certain
tests may fail on older C++ compilers (for instance if your compiler
does not support member templates). These errors are harmless if you
don't intend to use these features in your own programs.
</p>
<p>
Note: The test-suite currently contains over 500 tests. If you
have many different target languages installed and a slow machine, it
might take more than an hour to run the test-suite.
</p>
<H3><a name="Preface_examples"></a>1.12.5 Examples</H3>
<p>
The Examples directory contains a variety of examples of using SWIG
and it has some browsable documentation. Simply point your browser to
the file "Example/index.html".
</p>
<p>
The Examples directory also includes Visual C++ project 6 (.dsp) files for
building some of the examples on Windows. Later versions of Visual Studio
will convert these old style project files into a current solution file.
</p>
</body>
</html>

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Preprocessor"></a>7 Preprocessing</H1>
<H1><a name="Preprocessor"></a>8 Preprocessing</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -37,7 +37,7 @@ However, a number of modifications and enhancements have been made. This
chapter describes some of these modifications.
</p>
<H2><a name="Preprocessor_nn2"></a>7.1 File inclusion</H2>
<H2><a name="Preprocessor_nn2"></a>8.1 File inclusion</H2>
<p>
@ -63,7 +63,7 @@ By default, the <tt>#include</tt> is ignored unless you run SWIG with the
is that you often don't want SWIG to try and wrap everything included
in standard header system headers and auxiliary files.
<H2><a name="Preprocessor_nn3"></a>7.2 File imports</H2>
<H2><a name="Preprocessor_nn3"></a>8.2 File imports</H2>
<p>
@ -92,7 +92,7 @@ The <tt>-importall</tt> directive tells SWIG to follow all <tt>#include</tt> sta
as imports. This might be useful if you want to extract type definitions from system
header files without generating any wrappers.
<H2><a name="Preprocessor_condition_compilation"></a>7.3 Conditional Compilation</H2>
<H2><a name="Preprocessor_condition_compilation"></a>8.3 Conditional Compilation</H2>
<p>
@ -152,7 +152,7 @@ SWIG (except for the symbol `<tt>SWIG</tt>' which is only defined
within the SWIG compiler).
</p>
<H2><a name="Preprocessor_nn5"></a>7.4 Macro Expansion</H2>
<H2><a name="Preprocessor_nn5"></a>8.4 Macro Expansion</H2>
<p>
@ -207,7 +207,7 @@ like <tt>#x</tt>. This is a non-standard SWIG extension.
</li>
</ul>
<H2><a name="Preprocessor_nn6"></a>7.5 SWIG Macros</H2>
<H2><a name="Preprocessor_nn6"></a>8.5 SWIG Macros</H2>
<p>
@ -253,7 +253,7 @@ many of SWIG's advanced features and libraries are built using this mechanism (s
support).
</p>
<H2><a name="Preprocessor_nn7"></a>7.6 C99 and GNU Extensions</H2>
<H2><a name="Preprocessor_nn7"></a>8.6 C99 and GNU Extensions</H2>
<p>
@ -309,14 +309,14 @@ interface building. However, they are used internally to implement a number of
SWIG directives and are provided to make SWIG more compatible with C99 code.
</p>
<H2><a name="Preprocessor_delimiters"></a>7.7 Preprocessing and delimiters</H2>
<H2><a name="Preprocessor_delimiters"></a>8.7 Preprocessing and delimiters</H2>
<p>
The preprocessor handles { }, " " and %{ %} delimiters differently.
</p>
<H3><a name="Preprocessor_nn8"></a>7.7.1 Preprocessing and %{ ... %} &amp; " ... " delimiters</H3>
<H3><a name="Preprocessor_nn8"></a>8.7.1 Preprocessing and %{ ... %} &amp; " ... " delimiters</H3>
<p>
@ -341,7 +341,7 @@ the contents of the <tt>%{ ... %}</tt> block are copied without
modification to the output (including all preprocessor directives).
</p>
<H3><a name="Preprocessor_nn9"></a>7.7.2 Preprocessing and { ... } delimiters</H3>
<H3><a name="Preprocessor_nn9"></a>8.7.2 Preprocessing and { ... } delimiters</H3>
<p>
@ -383,7 +383,7 @@ to actually go into the wrapper file, prefix the preprocessor directives with <t
SWIG will strip the extra <tt>%</tt> and leave the preprocessor directive in the code.
</p>
<H2><a name="Preprocessor_typemap_delimiters"></a>7.8 Preprocessor and Typemaps</H2>
<H2><a name="Preprocessor_typemap_delimiters"></a>8.8 Preprocessor and Typemaps</H2>
<p>
@ -454,7 +454,7 @@ would generate
</div>
<H2><a name="Preprocessor_nn10"></a>7.9 Viewing preprocessor output</H2>
<H2><a name="Preprocessor_nn10"></a>8.9 Viewing preprocessor output</H2>
<p>
@ -464,7 +464,7 @@ Instead the results after the preprocessor has run are displayed.
This might be useful as an aid to debugging and viewing the results of macro expansions.
</p>
<H2><a name="Preprocessor_warning_error"></a>7.10 The #error and #warning directives</H2>
<H2><a name="Preprocessor_warning_error"></a>8.10 The #error and #warning directives</H2>
<p>

File diff suppressed because it is too large Load diff

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="R"></a>35 SWIG and R</H1>
<H1><a name="R"></a>36 SWIG and R</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -33,7 +33,7 @@ compile and run an R interface to QuantLib running on Mandriva Linux
with gcc. The R bindings also work on Microsoft Windows using Visual C++.
</p>
<H2><a name="R_nn2"></a>35.1 Bugs</H2>
<H2><a name="R_nn2"></a>36.1 Bugs</H2>
<p>
@ -45,7 +45,7 @@ Currently the following features are not implemented or broken:
<li>C Array wrappings
</ul>
<H2><a name="R_nn3"></a>35.2 Using R and SWIG</H2>
<H2><a name="R_nn3"></a>36.2 Using R and SWIG</H2>
<p>
@ -119,7 +119,7 @@ Without it, inheritance of wrapped objects may fail.
These two files can be loaded in any order
</p>
<H2><a name="R_nn4"></a>35.3 Precompiling large R files</H2>
<H2><a name="R_nn4"></a>36.3 Precompiling large R files</H2>
In cases where the R file is large, one make save a lot of loading
@ -137,7 +137,7 @@ will save a large amount of loading time.
<H2><a name="R_nn5"></a>35.4 General policy</H2>
<H2><a name="R_nn5"></a>36.4 General policy</H2>
<p>
@ -146,7 +146,7 @@ wrapping over the underlying functions and rely on the R type system
to provide R syntax.
</p>
<H2><a name="R_language_conventions"></a>35.5 Language conventions</H2>
<H2><a name="R_language_conventions"></a>36.5 Language conventions</H2>
<p>
@ -155,7 +155,7 @@ and [ are overloaded to allow for R syntax (one based indices and
slices)
</p>
<H2><a name="R_nn6"></a>35.6 C++ classes</H2>
<H2><a name="R_nn6"></a>36.6 C++ classes</H2>
<p>
@ -167,7 +167,7 @@ keep track of the pointer object which removes the necessity for a lot
of the proxy class baggage you see in other languages.
</p>
<H2><a name="R_nn7"></a>35.7 Enumerations</H2>
<H2><a name="R_nn7"></a>36.7 Enumerations</H2>
<p>

View file

@ -1,9 +1,9 @@
This directory contains the HTML for the SWIG users manual.
All of this HTML is hand-written. However, section numbering, indices,
and the table of contents is generated automatically by the 'maketoc.py'
and the table of contents are generated automatically by the 'maketoc.py'
script. The Makefile has further information on how the various alternative
forms of the documentation is generated from the hand-written HTML.
forms of the documentation are generated from the hand-written HTML.
There are 4 types of boxes that code or whatever can be inside:
- <div class="shell">...</div>

File diff suppressed because it is too large Load diff

View file

@ -224,7 +224,7 @@ $ swig -c++ -python -o example_wrap.cpp example.i
<p>
The C/C++ output file created by SWIG often
contains everything that is needed to construct a extension module
contains everything that is needed to construct an extension module
for the target scripting language. SWIG is not a stub compiler nor is it
usually necessary to edit the output file (and if you look at the output,
you probably won't want to). To build the final extension module, the
@ -233,7 +233,7 @@ program to create a shared library.
</p>
<p>
Many target languages will also generate proxy class files in the
For many target languages SWIG will also generate proxy class files in the
target language. The default output directory for these language
specific files is the same directory as the generated C/C++ file. This
can be modified using the <tt>-outdir</tt> option. For example:
@ -258,7 +258,7 @@ this option the default output directory is the path to the input file.
If <tt>-o</tt> and
<tt>-outcurrentdir</tt> are used together, <tt>-outcurrentdir</tt> is effectively ignored
as the output directory for the language files is the same directory as the
generated C/C++ file if not overidden with <tt>-outdir</tt>.
generated C/C++ file if not overridden with <tt>-outdir</tt>.
</p>
<H3><a name="SWIG_nn5"></a>5.1.3 Comments</H3>
@ -484,7 +484,7 @@ Or in Python:
Whenever possible, SWIG creates an interface that closely matches the underlying C/C++
code. However, due to subtle differences between languages, run-time
environments, and semantics, it is not always possible to do so. The
next few sections describes various aspects of this mapping.
next few sections describe various aspects of this mapping.
</p>
<H3><a name="SWIG_nn10"></a>5.2.1 Basic Type Handling</H3>
@ -728,7 +728,7 @@ However, for the same conservative reasons even a constant with a simple cast wi
<div class="code">
<pre>
#define F_CONST (double) 5 // A floating pointer constant with cast
#define F_CONST (double) 5 // A floating point constant with cast
</pre>
</div>
@ -750,7 +750,7 @@ enum values as assigned by the C compiler.
<p>
The <tt>%constant</tt> directive is used to more precisely create
constants corresponding to different C datatypes. Although it is not
usually not needed for simple values, it is more useful when working
usually needed for simple values, it is more useful when working
with pointers and other more complex datatypes. Typically, <tt>%constant</tt>
is only used when you want to add constants to the scripting language
interface that are not defined in the original header file.
@ -868,7 +868,7 @@ from a scripting language to a C <tt>char *</tt>, the pointer usually
points to string data stored inside the interpreter. It is almost
always a really bad idea to modify this data. Furthermore, some
languages may explicitly disallow it. For instance, in Python,
strings are supposed be immutable. If you violate this, you will probably
strings are supposed to be immutable. If you violate this, you will probably
receive a vast amount of wrath when you unleash your module on the world.
</p>
@ -1483,7 +1483,7 @@ void transpose(double (*a)[20]);
<p>
Like C, SWIG does not perform array bounds checking.
It is up to the
user to make sure the pointer points a suitably allocated region of memory.
user to make sure the pointer points to a suitably allocated region of memory.
</p>
<p>
@ -1888,11 +1888,22 @@ and a more descriptive one, but the two functions are otherwise equivalent:
<i>pattern</i> part is a regular expression in Perl syntax (as supported
by the <a href="http://www.pcre.org/">Perl Compatible Regular Expressions (PCRE)</a>)
library and the <i>subst</i> string
can contain back-references introduced by <tt>'\'</tt> or, as backslashes need
to be escaped in C strings, rather by <tt>"\\"</tt>. For example, to remove
any alphabetic prefix before an underscore you could use the following directive:
<tt>%rename("regex:/(\\w+)_(.*)/\\2/")</tt></td>
<td><tt>Prefix_Print</tt></td><td><tt>Print</tt></td>
can contain back-references of the form <tt>\N</tt> where <tt>N</tt> is a digit
from 0 to 9, or one of the following escape sequences: <tt>\l</tt>, <tt>\L</tt>,
<tt>\u</tt>, <tt>\U</tt> or <tt>\E</tt>. The back-references are replaced with the
contents of the corresponding capture group while the escape sequences perform the
case conversion in the substitution string: <tt>\l</tt> and <tt>\L</tt> convert to
the lower case, while <tt>\u</tt> and <tt>\U</tt> convert to the upper case. The
difference between the elements of each pair is that <tt>\l</tt> and <tt>\u</tt>
change the case of the next character only, while <tt>\L</tt> and <tt>\U</tt> do
it for all the remaining characters or until <tt>\E</tt> is encountered.
Finally please notice that backslashes need to be escaped in C strings, so in
practice <tt>"\\"</tt> must be used in all these escape sequences. For example,
to remove any alphabetic prefix before an underscore and capitalize the remaining
part you could use the following directive:
<tt>%rename("regex:/(\\w+)_(.*)/\\u\\2/")</tt></td>
<td><tt>prefix_print</tt></td><td><tt>Print</tt></td>
</tr>
<tr>
<td><tt>command:cmd</tt></td>
@ -2254,7 +2265,7 @@ disabled using <tt>%nocallback</tt>. When you do this, the interface now works
<p>
Notice that when the function is used as a callback, special names
such as <tt>add_cb</tt> is used instead. To call the function
such as <tt>add_cb</tt> are used instead. To call the function
normally, just use the original function name such as <tt>add()</tt>.
</p>
@ -2300,7 +2311,7 @@ handle C++ are described in the next section.
If SWIG encounters the definition of a structure or union, it
creates a set of accessor functions. Although SWIG does not need
structure definitions to build an interface, providing definitions
make it possible to access structure members. The accessor functions
makes it possible to access structure members. The accessor functions
generated by SWIG simply take a pointer to an object and allow access
to an individual member. For example, the declaration :</p>
@ -2423,7 +2434,7 @@ vector_struct</tt>, SWIG knows that this is the same as
Structures involving character strings require some care. SWIG assumes
that all members of type <tt>char *</tt> have been dynamically
allocated using <tt>malloc()</tt> and that they are NULL-terminated
ASCII strings. When such a member is modified, the previously contents
ASCII strings. When such a member is modified, the previous contents
will be released, and the new contents allocated. For example :</p>
<div class="code"><pre>
@ -2508,7 +2519,7 @@ typedef struct Bar {
<p>
When a structure member is wrapped, it is handled as a pointer, unless the <tt>%naturalvar</tt> directive
is used where it is handled more like a C++ reference (see <a href="SWIGPlus.html#SWIGPlus_member_data">C++ Member data</a>).
The accessors to the member variable as a pointer is effectively wrapped as follows:
The accessors to the member variable as a pointer are effectively wrapped as follows:
</p>
<div class="code">
@ -2645,8 +2656,8 @@ struct Bar { // Default constructor generated.
<p>
Since ignoring the implicit or default destructors most of the times
produce memory leaks, SWIG will always try to generate them. If
Since ignoring the implicit or default destructors most of the time
produces memory leaks, SWIG will always try to generate them. If
needed, however, you can selectively disable the generation of the
default/implicit destructor by using <tt>%nodefaultdtor</tt>
</p>
@ -2676,7 +2687,7 @@ has now been enabled as the default behavior.
<b>Note:</b> There are also the <tt>-nodefault</tt> option and
<tt>%nodefault</tt> directive, which disable both the default or
implicit destructor generation. This could lead to memory leaks across
the target languages, and is highly recommended you don't use them.
the target languages, and it is highly recommended you don't use them.
</p>
@ -2699,7 +2710,7 @@ the following declaration :</p>
<div class="code"><pre>
/* file : vector.h */
...
typedef struct {
typedef struct Vector {
double x,y,z;
} Vector;
@ -2772,7 +2783,7 @@ of the Vector structure. For example:</p>
#include "vector.h"
%}
typedef struct {
typedef struct Vector {
double x,y,z;
%extend {
Vector(double x, double y, double z) { ... }
@ -2783,7 +2794,7 @@ typedef struct {
</pre></div>
<p>
Finally, <tt>%extend</tt> can be used to access externally written
Note that <tt>%extend</tt> can be used to access externally written
functions provided they follow the naming convention used in this
example :</p>
@ -2814,7 +2825,7 @@ double Vector_magnitude(Vector *v) {
#include "vector.h"
%}
typedef struct {
typedef struct Vector {
double x,y,z;
%extend {
Vector(int,int,int); // This calls new_Vector()
@ -2826,6 +2837,37 @@ typedef struct {
</pre>
</div>
<p>
The name used for %extend should be the name of the struct and not the name of any typedef to the struct.
For example:
</p>
<div class="code"><pre>
typedef struct Integer {
int value;
} Int;
%extend Integer { ... } /* Correct name */
%extend Int { ... } /* Incorrect name */
struct Float {
float value;
};
typedef struct Float FloatValue;
%extend Float { ... } /* Correct name */
%extend FloatValue { ... } /* Incorrect name */
</pre></div>
<p>
There is one exception to this rule and that is when the struct is anonymously named such as:
</p>
<div class="code"><pre>
typedef struct {
double value;
} Double;
%extend Double { ... } /* Okay */
</pre></div>
<p>
A little known feature of the <tt>%extend</tt> directive is that
it can also be used to add synthesized attributes or to modify the
@ -2862,7 +2904,7 @@ For example, consider this interface:
<div class="code">
<pre>
typedef struct {
typedef struct Person {
char name[50];
...
} Person;
@ -2876,7 +2918,7 @@ the interface as follows to ensure this occurs whenever a name is read or writte
<div class="code">
<pre>
typedef struct {
typedef struct Person {
%extend {
char name[50];
}
@ -3238,7 +3280,7 @@ initialization on module loading, you could write this:
<p>
This section describes the general approach for building interface
This section describes the general approach for building interfaces
with SWIG. The specifics related to a particular scripting language
are found in later chapters.</p>
@ -3253,9 +3295,9 @@ of steps you can follow to make an interface for a C program :</p>
<ul>
<li>Identify the functions that you want to wrap. It's probably not
necessary to access every single function in a C program--thus, a
necessary to access every single function of a C program--thus, a
little forethought can dramatically simplify the resulting scripting
language interface. C header files are particularly good source for
language interface. C header files are a particularly good source for
finding things to wrap.
<li>Create a new interface file to describe the scripting language
@ -3300,7 +3342,7 @@ to the <a href="http://www.swig.org/mail.html">swig-devel mailing list</a> or to
<p>
The preferred method of using SWIG is to generate separate interface
The preferred method of using SWIG is to generate a separate interface
file. Suppose you have the following C header file :</p>
<div class="code"><pre>
@ -3394,7 +3436,7 @@ include certain header files by using a <tt>%{,%}</tt> block like this:
#include &lt;GL/glu.h&gt;
%}
// Put rest of declarations here
// Put the rest of the declarations here
...
</pre></div>
@ -3436,7 +3478,7 @@ program that is more interactive. In many cases, the old
or Tcl script.</p>
<p>
<b>Note:</b> If some cases, you might be inclined to create a
<b>Note:</b> In some cases, you might be inclined to create a
scripting language wrapper for <tt>main()</tt>. If you do this, the
compilation will probably work and your module might even load
correctly. The only trouble is that when you call your

View file

@ -185,7 +185,6 @@ The following C++ features are not currently supported:</p>
<ul>
<li>Overloaded versions of certain operators (new, delete, etc.)
<li>Nested classes, see <a href="#SWIGPlus_nested_classes">Nested classes</a> for workarounds.
</ul>
<p>
@ -217,7 +216,7 @@ to use the C++ compiler. For example:
<div class="shell">
<pre>
$ swig -c++ -tcl example.i
$ c++ -c example_wrap.cxx
$ c++ -fPIC -c example_wrap.cxx
$ c++ example_wrap.o $(OBJS) -o example.so
</pre>
</div>
@ -960,8 +959,9 @@ Similarly, all data attributes declared as <tt>const</tt> are wrapped as read-on
</p>
<p>
By default, SWIG uses the const reference typemaps for members that are primitive types.
There are some subtle issues when wrapping data members that are
themselves classes. For instance, if you had another class like this,
not primitive types, such as classes. For instance, if you had another class like this,
</p>
<div class="code">
@ -974,7 +974,8 @@ public:
</div>
<p>
then the low-level accessor to the <tt>items</tt> member actually uses pointers. For example:
then the low-level accessor to the <tt>items</tt> member actually uses pointers.
For example:
</p>
<div class="code">
@ -999,31 +1000,7 @@ This can be somewhat unnatural for some types.
For example, a user would expect the STL std::string class member variables to be wrapped as a string in the target language,
rather than a pointer to this class.
The const reference typemaps offer this type of marshalling, so there is a feature to tell SWIG to use the const reference typemaps rather than the pointer typemaps.
It is the <tt>%naturalvar</tt> directive and is used as follows:
</p>
<div class="code">
<pre>
// All List variables will use const List&amp; typemaps
%naturalvar List;
// Only Foo::myList will use const List&amp; typemaps
%naturalvar Foo::myList;
struct Foo {
List myList;
};
// All variables will use const reference typemaps
%naturalvar;
</pre>
</div>
<p>
The observant reader will notice that <tt>%naturalvar</tt> works like any other
<a href="Customization.html#Customization_feature_flags">feature flag</a> directive,
except it can also be attached to class types.
The first of the example usages above show <tt>%naturalvar</tt> attaching to the <tt>List</tt> class.
Effectively this feature changes the way accessors are generated to the following:
It is the naturalvar feature and can be used to effectively change the way accessors are generated to the following:
</p>
<div class="code">
@ -1038,15 +1015,45 @@ void Foo_items_set(Foo *self, const List &amp;value) {
</div>
<p>
In fact it is generally a good idea to use this feature globally as the reference typemaps have extra NULL checking compared to the pointer typemaps.
The <tt>%naturalvar</tt> directive is a macro for, and hence equivalent to, <tt>%feature("naturalvar")</tt>. It can be used as follows:
</p>
<div class="code">
<pre>
// All List variables will use const List&amp; typemaps
%naturalvar List;
// Only Foo::myList will use const List&amp; typemaps
%naturalvar Foo::myList;
struct Foo {
List myList;
};
// All non-primitive types will use const reference typemaps
%naturalvar;
</pre>
</div>
<p>
The observant reader will notice that <tt>%naturalvar</tt> works like any other
<a href="Customization.html#Customization_feature_flags">feature flag</a> directive but with some extra flexibility.
The first of the example usages above shows <tt>%naturalvar</tt> attaching to the <tt>myList</tt>'s variable type, that is the <tt>List</tt> class.
The second usage shows <tt>%naturalvar</tt> attaching to the variable name.
Hence the naturalvar feature can be used on either the variable's name or type.
Note that using the naturalvar feature on a variable's name overrides any naturalvar feature attached to the variable's type.
</p>
<p>
It is generally a good idea to use this feature globally as the reference typemaps have extra NULL checking compared to the pointer typemaps.
A pointer can be NULL, whereas a reference cannot, so the extra checking ensures that the target language user does not pass in a value that translates
to a NULL pointer and thereby preventing any potential NULL pointer dereferences.
The <tt>%naturalvar</tt> feature will apply to global variables in addition to member variables in some language modules, eg C# and Java.
</p>
<p>
Other alternatives for turning this feature on globally are to use the <tt>swig -naturalvar</tt> commandline option
or the module mode option, <tt>%module(naturalvar=1)</tt>
The naturalvar behavior can also be turned on as a global setting via the <tt>-naturalvar</tt> commandline option
or the module mode option, <tt>%module(naturalvar=1)</tt>.
However, any use of <tt>%feature("naturalvar")</tt> will override the global setting.
</p>
<p>
@ -1522,7 +1529,7 @@ multiple inheritance.
spirit, and target language capabilities, as possible. In most
cases, this means that SWIG will parse the non-public inheritance
declarations, but that will have no effect in the generated code,
besides the implicit policies derived for constructor and
besides the implicit policies derived for constructors and
destructors.
</p>
@ -2838,6 +2845,12 @@ struct Derived : Base {
}
</pre></div>
<p>
The following special variables are expanded if used within a %extend block:
$name, $symname, $overname, $decl, $fulldecl, $parentname and $parentsymname.
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
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>
@ -3121,8 +3134,8 @@ nothing is known about <tt>List&lt;int&gt;</tt>, you will get a warning message
<div class="shell">
<pre>
example.h:42. Nothing known about class 'List&lt;int &gt;' (ignored).
example.h:42. Maybe you forgot to instantiate 'List&lt;int &gt;' using %template.
example.h:42: Warning 401. Nothing known about class 'List&lt;int &gt;'. Ignored.
example.h:42: Warning 401. Maybe you forgot to instantiate 'List&lt;int &gt;' using %template.
</pre>
</div>
@ -3163,7 +3176,7 @@ Don't worry--if you get the order wrong, SWIG should generate a warning message.
Occasionally, you may need to tell SWIG about base classes that are defined by templates,
but which aren't supposed to be wrapped. Since SWIG is not able to automatically
instantiate templates for this purpose, you must do it manually. To do this, simply
use <tt>%template</tt> with no name. For example:
use the empty template instantiation, that is, <tt>%template</tt> with no name. For example:
</p>
<div class="code">
@ -4427,7 +4440,7 @@ around some other class. For example:
template&lt;class T&gt; class SmartPtr {
T *pointee;
public:
...
SmartPtr(T *p) : pointee(p) { ... }
T *operator-&gt;() {
return pointee;
}
@ -4447,7 +4460,7 @@ typedef SmartPtr&lt;Foo_Impl&gt; Foo;
// Create smart pointer Foo
Foo make_Foo() {
return SmartPtr(new Foo_Impl());
return SmartPtr&lt;Foo_Impl&gt;(new Foo_Impl());
}
// Do something with smart pointer Foo
@ -4455,6 +4468,9 @@ void do_something(Foo f) {
printf("x = %d\n", f-&gt;x);
f-&gt;bar();
}
// Call the wrapped smart pointer proxy class in the target language 'Foo'
%template(Foo) SmartPtr&lt;Foo_Impl&gt;;
</pre>
</div>
@ -4958,141 +4974,55 @@ public:
<p>
There is some support for nested structs and unions when wrapping C code,
see <a href="SWIG.html#SWIG_nested_structs">Nested structures</a> for further details.
The added complexity of C++ compared to C means this approach does not work well for
C++ code (when using the -c++ command line option).
For C++, a nested class is treated much like an opaque pointer, so anything useful within the nested class, such as its
methods and variables, are not accessible from the target language.
True nested class support may be added to SWIG in the future, however,
until then some of the following workarounds can be applied to improve the situation.
If the target language supports the nested classes concept (like Java), the nested C++ classes
are wrapped as nested target language proxy classes. (In case of Java - "static" nested classes.)
Only public nested classes are wrapped. Otherwise there is little difference between nested and
normal classes.
</p>
<p>
It might be possible to use partial class information as often you can accept that the nested class is not needed,
especially if it is not actually used in any methods you need from the target language.
Imagine you are wrapping the following <tt>Outer</tt> class which contains a nested class <tt>Inner</tt>.
The easiest thing to do is turn a blind eye to the warning that SWIG generates, or simply suppress it:
If the target language doesn't support nested classes directly, or the support is not implemented in the
language module (like for python currently), then the visible nested classes are moved to the same name
space as the containing class (nesting hierarchy is "flattened"). The same behaviour may be turned on for
C# and Java by the %feature ("flatnested"); If there is a class with the same name in the outer namespace
the inner class (or the global one) may be renamed or ignored:
</p>
<div class="code">
<pre>
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::Inner;
class Outer {
public:
class Inner {
public:
...
};
Inner getInner();
void useInner(const Inner&amp; inner);
...
};
</pre>
</div>
<p>
Note that if <tt>Inner</tt> can be used as an opaque type, the default wrapping approach suffices.
For example, if the nested class does not need to be created from the target language, but can be obtained via a method
call, such as the <tt>getInner()</tt> method above, the returned value can then be passed around, such as passed into the
<tt>useInner()</tt> method.
</p>
<p>
With some more effort the above situation can be improved somewhat and a nested class can be constructed and used
from the target language much like any other non-nested class. Assuming we have the <tt>Outer</tt> class in a header file:
</p>
<div class="code">
<pre>
// File outer.h
class Outer {
public:
class Inner {
public:
int var;
Inner(int v = 0) : var(v) {}
};
Inner getInner();
void useInner(const Inner&amp; inner);
};
</pre>
</div>
<p>
The following interface file works around the nested class limitations by redefining the nested class as a global class.
A typedef for the compiler and the <tt>nestedworkaround</tt>
<a href="Customization.html#Customization_feature_flags">feature flag</a> is also required in
order for the generated wrappers to compile. This flag simply removes all the type information from SWIG, so SWIG treats
the nested class as if it had not been parsed at all.
</p>
<div class="code">
<pre>
// File : example.i
%module example
// Redefine nested class in global scope in order for SWIG to generate
// a proxy class. Only SWIG parses this definition.
class Inner {
%rename (Bar_Foo) Bar::Foo;
class Foo {};
class Bar {
public:
int var;
Inner(int v = 0) : var(v) {}
class Foo {};
};
%nestedworkaround Outer::Inner;
%{
#include "outer.h"
%}
%include "outer.h"
// We've fooled SWIG into thinking that Inner is a global class, so now we need
// to trick the C++ compiler into understanding this apparent global type.
%{
typedef Outer::Inner Inner;
%}
</pre>
</div>
<p>
The downside to this approach is a more complex interface file and having to maintain two definitions of <tt>Inner</tt>,
the real one and the one in the interface file that SWIG parses.
However, the upside is that all the methods/variables in the nested class are available from the target language
as a proxy class is generated instead of treating the nested class as an opaque type.
The proxy class can be constructed from the target language and passed into any methods accepting the nested class.
Also note that the original header file is parsed unmodified.
</p>
<p>
Finally, conditional compilation can be used as a workaround to comment out nested class definitions in the actual headers,
assuming you are able to modify them.
<b>Compatibility Note:</b>
Prior to SWIG-3.0.0, there was limited nested class support. Nested classes were treated as opaque pointers.
However, there was a workaround for nested class support in these older versions requiring the user to replicate
the nested class in the global scope, adding in a typedef for the nested class in the global scope and
using the "nestedworkaround" feature on the nested class. This resulted in approximately the
same behaviour as the "flatnested" feature. With proper nested class support now available in SWIG-3.0.0, this
feature has been deprecated and no longer works requiring code changes. If you see the following warning:
</p>
<div class="code">
<div class="shell">
<pre>
// File outer.h
class Outer {
public:
#ifndef SWIG
class Inner {
public:
...
};
#endif
...
};
example.i:8: Warning 126: The nestedworkaround feature is deprecated
</pre>
</div>
<p>
This workaround used to be common when SWIG could not deal with nested classes particulary well.
This should just be a last resort for unusual corner cases now as SWIG can parse nested classes and even handle nested template classes fairly well.
consider using the "flatnested" feature discussed above which generates a non-nested proxy class, like the
"nestedworkaround" feature did. Alternatively, use the default nested class code generation, which may generate an
equivalent to a nested proxy class in the target language, depending on the target language support.
</p>
<p>
<b>Compatibility Note:</b> SWIG-1.3.40 and earlier versions did not have the <tt>nestedworkaround</tt> feature
SWIG-1.3.40 and earlier versions did not have the <tt>nestedworkaround</tt> feature
and the generated code resulting from parsing nested classes did not always compile.
Nested class warnings could also not be suppressed using %warnfilter.
</p>

View file

@ -293,7 +293,7 @@ A proxy class is a special kind of object that gets created
in a scripting language to access a C/C++ class (or struct) in a way
that looks like the original structure (that is, it proxies the real
C++ class). For example, if you
have the following C definition :</p>
have the following C++ definition :</p>
<div class="code"><pre>
class Vector {
@ -334,12 +334,12 @@ Finally, in Tcl :
<div class="targetlang"><pre>
Vector v
v configure -x 3 -y 4 -z 13
v configure -x 3 -y 4 -z -13
</pre></div>
<p>
When proxy classes are used, two objects are at really work--one in
When proxy classes are used, two objects are really at work--one in
the scripting language, and an underlying C/C++ object. Operations
affect both objects equally and for all practical purposes, it appears
as if you are simply manipulating a C/C++ object.
@ -353,7 +353,7 @@ The final step in using a scripting language with your C/C++
application is adding your extensions to the scripting language
itself. There are two primary approaches for doing
this. The preferred technique is to build a dynamically loadable
extension in the form a shared library. Alternatively, you can
extension in the form of a shared library. Alternatively, you can
recompile the scripting language interpreter with your extensions
added to it.
</p>
@ -364,21 +364,16 @@ added to it.
<p>
To create a shared library or DLL, you often need to look at the
manual pages for your compiler and linker. However, the procedure
for a few common machines is shown below:</p>
for a few common platforms is shown below:</p>
<div class="shell"><pre>
# Build a shared library for Solaris
gcc -c example.c example_wrap.c -I/usr/local/include
gcc -fpic -c example.c example_wrap.c -I/usr/local/include
ld -G example.o example_wrap.o -o example.so
# Build a shared library for Linux
gcc -fpic -c example.c example_wrap.c -I/usr/local/include
gcc -shared example.o example_wrap.o -o example.so
# Build a shared library for Irix
gcc -c example.c example_wrap.c -I/usr/local/include
ld -shared example.o example_wrap.o -o example.so
</pre></div>
<p>

View file

@ -1,12 +1,12 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SWIG-2.0 Documentation</title>
<title>SWIG-3.0 Documentation</title>
</head>
<body bgcolor="#ffffff">
<H1><a name="Sections"></a>SWIG-2.0 Documentation</H1>
<H1><a name="Sections"></a>SWIG-3.0 Documentation</H1>
Last update : SWIG-2.0.6 (30 April 2012)
Last update : SWIG-3.0.1 (in progress)
<H2>Sections</H2>
@ -18,6 +18,7 @@ Last update : SWIG-2.0.6 (30 April 2012)
<li><a href="Scripting.html#Scripting">Scripting</a></li>
<li><a href="SWIG.html#SWIG">SWIG Basics</a> (Read this!)</li>
<li><a href="SWIGPlus.html#SWIGPlus">SWIG and C++</a></li>
<li><a href="CPlusPlus11.html#CPlusPlus11">SWIG and C++11</a></li>
<li><a href="Preprocessor.html#Preprocessor">The SWIG preprocessor</a></li>
<li><a href="Library.html#Library">The SWIG library</a></li>
<li><a href="Arguments.html#Arguments">Argument handling</a></li>

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Tcl"></a>37 SWIG and Tcl</H1>
<H1><a name="Tcl"></a>38 SWIG and Tcl</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -83,7 +83,7 @@ Tcl 8.0 or a later release. Earlier releases of SWIG supported Tcl 7.x, but
this is no longer supported.
</p>
<H2><a name="Tcl_nn2"></a>37.1 Preliminaries</H2>
<H2><a name="Tcl_nn2"></a>38.1 Preliminaries</H2>
<p>
@ -109,7 +109,7 @@ build a Tcl extension module. To finish building the module, you
need to compile this file and link it with the rest of your program.
</p>
<H3><a name="Tcl_nn3"></a>37.1.1 Getting the right header files</H3>
<H3><a name="Tcl_nn3"></a>38.1.1 Getting the right header files</H3>
<p>
@ -127,19 +127,20 @@ this is the case, you should probably make a symbolic link so that <tt>tcl.h</tt
header file.
</p>
<H3><a name="Tcl_nn4"></a>37.1.2 Compiling a dynamic module</H3>
<H3><a name="Tcl_nn4"></a>38.1.2 Compiling a dynamic module</H3>
<p>
The preferred approach to building an extension module is to compile it into
a shared object file or DLL. To do this, you will need to compile your program
a shared object file or DLL. Assuming you have code you need to link to in a file
called <tt>example.c</tt>, you will need to compile your program
using commands like this (shown for Linux):
</p>
<div class="code"><pre>
$ swig -tcl example.i
$ gcc -c example.c
$ gcc -c example_wrap.c -I/usr/local/include
$ gcc -fPIC -c example.c
$ gcc -fPIC -c example_wrap.c -I/usr/local/include
$ gcc -shared example.o example_wrap.o -o example.so
</pre></div>
@ -162,7 +163,7 @@ The name of the module is specified using the <tt>%module</tt> directive or the
<tt> -module</tt> command line option.
</p>
<H3><a name="Tcl_nn5"></a>37.1.3 Static linking</H3>
<H3><a name="Tcl_nn5"></a>38.1.3 Static linking</H3>
<p>
@ -228,7 +229,7 @@ minimal in most situations (and quite frankly not worth the extra
hassle in the opinion of this author).
</p>
<H3><a name="Tcl_nn6"></a>37.1.4 Using your module</H3>
<H3><a name="Tcl_nn6"></a>38.1.4 Using your module</H3>
<p>
@ -356,7 +357,7 @@ to the default system configuration (this requires root access and you will need
the man pages).
</p>
<H3><a name="Tcl_nn7"></a>37.1.5 Compilation of C++ extensions</H3>
<H3><a name="Tcl_nn7"></a>38.1.5 Compilation of C++ extensions</H3>
<p>
@ -373,8 +374,8 @@ compiler. For example:
<div class="code"><pre>
% swig -c++ -tcl example.i
% g++ -c example.cxx
% g++ -c example_wrap.cxx -I/usr/local/include
% g++ -fPIC -c example.cxx
% g++ -fPIC -c example_wrap.cxx -I/usr/local/include
% g++ -shared example.o example_wrap.o -o example.so
</pre></div>
@ -386,8 +387,8 @@ Solaris, you often need to add an extra library <tt>-lCrun</tt> like this:
<div class="code"><pre>
% swig -c++ -tcl example.i
% CC -c example.cxx
% CC -c example_wrap.cxx -I/usr/local/include
% CC -KPIC -c example.cxx
% CC -KPIC -c example_wrap.cxx -I/usr/local/include
% CC -G example.o example_wrap.o -L/opt/SUNWspro/lib -o example.so -lCrun
</pre></div>
@ -439,7 +440,7 @@ erratic program behavior. If working with lots of software components, you
might want to investigate using a more formal standard such as COM.
</p>
<H3><a name="Tcl_nn8"></a>37.1.6 Compiling for 64-bit platforms</H3>
<H3><a name="Tcl_nn8"></a>38.1.6 Compiling for 64-bit platforms</H3>
<p>
@ -466,7 +467,7 @@ also introduce problems on platforms that support more than one
linking standard (e.g., -o32 and -n32 on Irix).
</p>
<H3><a name="Tcl_nn9"></a>37.1.7 Setting a package prefix</H3>
<H3><a name="Tcl_nn9"></a>38.1.7 Setting a package prefix</H3>
<p>
@ -485,7 +486,7 @@ option will append the prefix to the name when creating a command and
call it "<tt>Foo_bar</tt>".
</p>
<H3><a name="Tcl_nn10"></a>37.1.8 Using namespaces</H3>
<H3><a name="Tcl_nn10"></a>38.1.8 Using namespaces</H3>
<p>
@ -507,7 +508,7 @@ 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>
<H2><a name="Tcl_nn11"></a>37.2 Building Tcl/Tk Extensions under Windows 95/NT</H2>
<H2><a name="Tcl_nn11"></a>38.2 Building Tcl/Tk Extensions under Windows 95/NT</H2>
<p>
@ -518,7 +519,7 @@ covers the process of using SWIG with Microsoft Visual C++.
although the procedure may be similar with other compilers.
</p>
<H3><a name="Tcl_nn12"></a>37.2.1 Running SWIG from Developer Studio</H3>
<H3><a name="Tcl_nn12"></a>38.2.1 Running SWIG from Developer Studio</H3>
<p>
@ -576,7 +577,7 @@ MSDOS &gt; tclsh80
%
</pre></div>
<H3><a name="Tcl_nn13"></a>37.2.2 Using NMAKE</H3>
<H3><a name="Tcl_nn13"></a>38.2.2 Using NMAKE</H3>
<p>
@ -639,7 +640,7 @@ to get you started. With a little practice, you'll be making lots of
Tcl extensions.
</p>
<H2><a name="Tcl_nn14"></a>37.3 A tour of basic C/C++ wrapping</H2>
<H2><a name="Tcl_nn14"></a>38.3 A tour of basic C/C++ wrapping</H2>
<p>
@ -650,7 +651,7 @@ classes. This section briefly covers the essential aspects of this
wrapping.
</p>
<H3><a name="Tcl_nn15"></a>37.3.1 Modules</H3>
<H3><a name="Tcl_nn15"></a>38.3.1 Modules</H3>
<p>
@ -684,7 +685,7 @@ To fix this, supply an extra argument to <tt>load</tt> like this:
</pre>
</div>
<H3><a name="Tcl_nn16"></a>37.3.2 Functions</H3>
<H3><a name="Tcl_nn16"></a>38.3.2 Functions</H3>
<p>
@ -709,7 +710,7 @@ like you think it does:
%
</pre></div>
<H3><a name="Tcl_nn17"></a>37.3.3 Global variables</H3>
<H3><a name="Tcl_nn17"></a>38.3.3 Global variables</H3>
<p>
@ -789,7 +790,7 @@ extern char *path; // Read-only (due to %immutable)
</pre>
</div>
<H3><a name="Tcl_nn18"></a>37.3.4 Constants and enums</H3>
<H3><a name="Tcl_nn18"></a>38.3.4 Constants and enums</H3>
<p>
@ -873,7 +874,7 @@ When an identifier name is given, it is used to perform an implicit hash-table l
conversion. This allows the <tt>global</tt> statement to be omitted.
</p>
<H3><a name="Tcl_nn19"></a>37.3.5 Pointers</H3>
<H3><a name="Tcl_nn19"></a>38.3.5 Pointers</H3>
<p>
@ -969,7 +970,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return
<tt>None</tt> if the conversion can't be performed.
</p>
<H3><a name="Tcl_nn20"></a>37.3.6 Structures</H3>
<H3><a name="Tcl_nn20"></a>38.3.6 Structures</H3>
<p>
@ -1251,7 +1252,7 @@ Note: Tcl only destroys the underlying object if it has ownership. See the
memory management section that appears shortly.
</p>
<H3><a name="Tcl_nn21"></a>37.3.7 C++ classes</H3>
<H3><a name="Tcl_nn21"></a>38.3.7 C++ classes</H3>
<p>
@ -1318,7 +1319,7 @@ In Tcl, the static member is accessed as follows:
</pre>
</div>
<H3><a name="Tcl_nn22"></a>37.3.8 C++ inheritance</H3>
<H3><a name="Tcl_nn22"></a>38.3.8 C++ inheritance</H3>
<p>
@ -1367,7 +1368,7 @@ For instance:
It is safe to use multiple inheritance with SWIG.
</p>
<H3><a name="Tcl_nn23"></a>37.3.9 Pointers, references, values, and arrays</H3>
<H3><a name="Tcl_nn23"></a>38.3.9 Pointers, references, values, and arrays</H3>
<p>
@ -1421,7 +1422,7 @@ to hold the result and a pointer is returned (Tcl will release this memory
when the return value is garbage collected).
</p>
<H3><a name="Tcl_nn24"></a>37.3.10 C++ overloaded functions</H3>
<H3><a name="Tcl_nn24"></a>38.3.10 C++ overloaded functions</H3>
<p>
@ -1544,7 +1545,7 @@ first declaration takes precedence.
Please refer to the "SWIG and C++" chapter for more information about overloading.
</p>
<H3><a name="Tcl_nn25"></a>37.3.11 C++ operators</H3>
<H3><a name="Tcl_nn25"></a>38.3.11 C++ operators</H3>
<p>
@ -1646,7 +1647,7 @@ There are ways to make this operator appear as part of the class using the <tt>%
Keep reading.
</p>
<H3><a name="Tcl_nn26"></a>37.3.12 C++ namespaces</H3>
<H3><a name="Tcl_nn26"></a>38.3.12 C++ namespaces</H3>
<p>
@ -1710,7 +1711,7 @@ utilizes thousands of small deeply nested namespaces each with
identical symbol names, well, then you get what you deserve.
</p>
<H3><a name="Tcl_nn27"></a>37.3.13 C++ templates</H3>
<H3><a name="Tcl_nn27"></a>38.3.13 C++ templates</H3>
<p>
@ -1762,7 +1763,7 @@ More details can be found in the <a href="SWIGPlus.html#SWIGPlus">SWIG and C++</
examples will appear later.
</p>
<H3><a name="Tcl_nn28"></a>37.3.14 C++ Smart Pointers</H3>
<H3><a name="Tcl_nn28"></a>38.3.14 C++ Smart Pointers</H3>
<p>
@ -1846,7 +1847,7 @@ simply use the <tt>__deref__()</tt> method. For example:
</pre>
</div>
<H2><a name="Tcl_nn29"></a>37.4 Further details on the Tcl class interface</H2>
<H2><a name="Tcl_nn29"></a>38.4 Further details on the Tcl class interface</H2>
<p>
@ -1859,7 +1860,7 @@ of low-level details were omitted. This section provides a brief overview
of how the proxy classes work.
</p>
<H3><a name="Tcl_nn30"></a>37.4.1 Proxy classes</H3>
<H3><a name="Tcl_nn30"></a>38.4.1 Proxy classes</H3>
<p>
@ -1924,7 +1925,7 @@ function. This allows objects to be encapsulated objects that look a lot like
as shown in the last section.
</p>
<H3><a name="Tcl_nn31"></a>37.4.2 Memory management</H3>
<H3><a name="Tcl_nn31"></a>38.4.2 Memory management</H3>
<p>
@ -2112,7 +2113,7 @@ typemaps--an advanced topic discussed later.
</p>
<H2><a name="Tcl_nn32"></a>37.5 Input and output parameters</H2>
<H2><a name="Tcl_nn32"></a>38.5 Input and output parameters</H2>
<p>
@ -2300,7 +2301,7 @@ set c [lindex $dim 1]
</pre>
</div>
<H2><a name="Tcl_nn33"></a>37.6 Exception handling </H2>
<H2><a name="Tcl_nn33"></a>38.6 Exception handling </H2>
<p>
@ -2434,7 +2435,7 @@ Since SWIG's exception handling is user-definable, you are not limited to C++ ex
See the chapter on "<a href="Customization.html#Customization">Customization Features</a>" for more examples.
</p>
<H2><a name="Tcl_nn34"></a>37.7 Typemaps</H2>
<H2><a name="Tcl_nn34"></a>38.7 Typemaps</H2>
<p>
@ -2451,7 +2452,7 @@ Typemaps are only used if you want to change some aspect of the primitive
C-Tcl interface.
</p>
<H3><a name="Tcl_nn35"></a>37.7.1 What is a typemap?</H3>
<H3><a name="Tcl_nn35"></a>38.7.1 What is a typemap?</H3>
<p>
@ -2568,7 +2569,7 @@ parameter is omitted):
</pre>
</div>
<H3><a name="Tcl_nn36"></a>37.7.2 Tcl typemaps</H3>
<H3><a name="Tcl_nn36"></a>38.7.2 Tcl typemaps</H3>
<p>
@ -2706,7 +2707,7 @@ Initialize an argument to a value before any conversions occur.
Examples of these methods will appear shortly.
</p>
<H3><a name="Tcl_nn37"></a>37.7.3 Typemap variables</H3>
<H3><a name="Tcl_nn37"></a>38.7.3 Typemap variables</H3>
<p>
@ -2777,7 +2778,7 @@ properly assigned.
The Tcl name of the wrapper function being created.
</div>
<H3><a name="Tcl_nn38"></a>37.7.4 Converting a Tcl list to a char ** </H3>
<H3><a name="Tcl_nn38"></a>38.7.4 Converting a Tcl list to a char ** </H3>
<p>
@ -2839,7 +2840,7 @@ argv[2] = Larry
3
</pre></div>
<H3><a name="Tcl_nn39"></a>37.7.5 Returning values in arguments</H3>
<H3><a name="Tcl_nn39"></a>38.7.5 Returning values in arguments</H3>
<p>
@ -2881,7 +2882,7 @@ result, a Tcl function using these typemaps will work like this :
%
</pre></div>
<H3><a name="Tcl_nn40"></a>37.7.6 Useful functions</H3>
<H3><a name="Tcl_nn40"></a>38.7.6 Useful functions</H3>
<p>
@ -2958,7 +2959,7 @@ int Tcl_IsShared(Tcl_Obj *obj);
</pre>
</div>
<H3><a name="Tcl_nn41"></a>37.7.7 Standard typemaps</H3>
<H3><a name="Tcl_nn41"></a>38.7.7 Standard typemaps</H3>
<p>
@ -3042,7 +3043,7 @@ work)
</pre>
</div>
<H3><a name="Tcl_nn42"></a>37.7.8 Pointer handling</H3>
<H3><a name="Tcl_nn42"></a>38.7.8 Pointer handling</H3>
<p>
@ -3118,7 +3119,7 @@ For example:
</pre>
</div>
<H2><a name="Tcl_nn43"></a>37.8 Turning a SWIG module into a Tcl Package.</H2>
<H2><a name="Tcl_nn43"></a>38.8 Turning a SWIG module into a Tcl Package.</H2>
<p>
@ -3190,7 +3191,7 @@ As a final note, most SWIG examples do not yet use the
to use the <tt>load</tt> command instead.
</p>
<H2><a name="Tcl_nn44"></a>37.9 Building new kinds of Tcl interfaces (in Tcl)</H2>
<H2><a name="Tcl_nn44"></a>38.9 Building new kinds of Tcl interfaces (in Tcl)</H2>
<p>
@ -3289,7 +3290,7 @@ danger of blowing something up (although it is easily accomplished
with an out of bounds array access).
</p>
<H3><a name="Tcl_nn45"></a>37.9.1 Proxy classes</H3>
<H3><a name="Tcl_nn45"></a>38.9.1 Proxy classes</H3>
<p>
@ -3410,7 +3411,7 @@ short, but clever Tcl script can be combined with SWIG to do many
interesting things.
</p>
<H2><a name="Tcl_nn46"></a>37.10 Tcl/Tk Stubs</H2>
<H2><a name="Tcl_nn46"></a>38.10 Tcl/Tk Stubs</H2>
<p>

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Typemaps"></a>10 Typemaps</H1>
<H1><a name="Typemaps"></a>11 Typemaps</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -95,7 +95,7 @@
<H2><a name="Typemaps_nn2"></a>10.1 Introduction</H2>
<H2><a name="Typemaps_nn2"></a>11.1 Introduction</H2>
<p>
@ -112,7 +112,7 @@ to re-read the earlier chapters if you have found your way to this
chapter with only a vague idea of what SWIG already does by default.
</p>
<H3><a name="Typemaps_nn3"></a>10.1.1 Type conversion</H3>
<H3><a name="Typemaps_nn3"></a>11.1.1 Type conversion</H3>
<p>
@ -205,7 +205,7 @@ to read the extension documentation for your favorite language to know
how it works (an exercise left to the reader).
</p>
<H3><a name="Typemaps_nn4"></a>10.1.2 Typemaps</H3>
<H3><a name="Typemaps_nn4"></a>11.1.2 Typemaps</H3>
<p>
@ -306,7 +306,7 @@ parts of the generated wrapper functions. Because arbitrary code can be insert
possible to completely change the way in which values are converted.
</p>
<H3><a name="Typemaps_nn5"></a>10.1.3 Pattern matching</H3>
<H3><a name="Typemaps_nn5"></a>11.1.3 Pattern matching</H3>
<p>
@ -408,7 +408,7 @@ In this case, a single input object is expanded into a pair of C arguments. Thi
provides a hint to the unusual variable naming scheme involving <tt>$1</tt>, <tt>$2</tt>, and so forth.
</p>
<H3><a name="Typemaps_nn6"></a>10.1.4 Reusing typemaps</H3>
<H3><a name="Typemaps_nn6"></a>11.1.4 Reusing typemaps</H3>
<p>
@ -464,7 +464,7 @@ typedef int size_t;
then SWIG already knows that the <tt>int</tt> typemaps apply. You don't have to do anything.
</p>
<H3><a name="Typemaps_nn7"></a>10.1.5 What can be done with typemaps?</H3>
<H3><a name="Typemaps_nn7"></a>11.1.5 What can be done with typemaps?</H3>
<p>
@ -576,7 +576,7 @@ typemaps that expand upon this list. For example, the Java module defines a var
aspects of the Java bindings. Consult language specific documentation for further details.
</p>
<H3><a name="Typemaps_nn8"></a>10.1.6 What can't be done with typemaps?</H3>
<H3><a name="Typemaps_nn8"></a>11.1.6 What can't be done with typemaps?</H3>
<p>
@ -639,7 +639,7 @@ void wrap_foo(char *s, int x) {
</pre>
</div>
<H3><a name="Typemaps_aspects"></a>10.1.7 Similarities to Aspect Oriented Programming</H3>
<H3><a name="Typemaps_aspects"></a>11.1.7 Similarities to Aspect Oriented Programming</H3>
<p>
@ -657,7 +657,7 @@ SWIG can also be viewed as has having a second set of aspects based around <a hr
Features such as <tt>%exception</tt> are also cross-cutting concerns as they encapsulate code that can be used to add logging or exception handling to any function.
</p>
<H3><a name="Typemaps_nn9"></a>10.1.8 The rest of this chapter</H3>
<H3><a name="Typemaps_nn9"></a>11.1.8 The rest of this chapter</H3>
<p>
@ -677,14 +677,14 @@ of "The C Programming Language" by Kernighan and Ritchie or
"The C++ Programming Language" by Stroustrup before going any further.
</p>
<H2><a name="Typemaps_nn10"></a>10.2 Typemap specifications</H2>
<H2><a name="Typemaps_nn10"></a>11.2 Typemap specifications</H2>
<p>
This section describes the behavior of the <tt>%typemap</tt> directive itself.
</p>
<H3><a name="Typemaps_defining"></a>10.2.1 Defining a typemap</H3>
<H3><a name="Typemaps_defining"></a>11.2.1 Defining a typemap</H3>
<p>
@ -773,7 +773,7 @@ Here are some examples of valid typemap specifications:
}
/* Typemap with modifiers */
%typemap(in,doc="integer") int "$1 = gh_scm2int($input);";
%typemap(in,doc="integer") int "$1 = scm_to_int($input);";
/* Typemap applied to patterns of multiple arguments */
%typemap(in) (char *str, int len),
@ -797,7 +797,7 @@ Admittedly, it's not the most readable syntax at first glance. However, the pur
individual pieces will become clear.
</p>
<H3><a name="Typemaps_nn12"></a>10.2.2 Typemap scope</H3>
<H3><a name="Typemaps_nn12"></a>11.2.2 Typemap scope</H3>
<p>
@ -847,7 +847,7 @@ class Foo {
</pre>
</div>
<H3><a name="Typemaps_nn13"></a>10.2.3 Copying a typemap</H3>
<H3><a name="Typemaps_nn13"></a>11.2.3 Copying a typemap</H3>
<p>
@ -905,7 +905,7 @@ The patterns for <tt>%apply</tt> follow the same rules as for <tt>%typemap</tt>.
</pre>
</div>
<H3><a name="Typemaps_nn14"></a>10.2.4 Deleting a typemap</H3>
<H3><a name="Typemaps_nn14"></a>11.2.4 Deleting a typemap</H3>
<p>
@ -938,7 +938,7 @@ For example:
after the clear operation.
</p>
<H3><a name="Typemaps_nn15"></a>10.2.5 Placement of typemaps</H3>
<H3><a name="Typemaps_nn15"></a>11.2.5 Placement of typemaps</H3>
<p>
@ -1018,7 +1018,7 @@ It should be noted that for scoping to work, SWIG has to know that <tt>string</t
within a particular namespace. In this example, this is done using the forward class declaration <tt>class string</tt>.
</p>
<H2><a name="Typemaps_pattern_matching"></a>10.3 Pattern matching rules</H2>
<H2><a name="Typemaps_pattern_matching"></a>11.3 Pattern matching rules</H2>
<p>
@ -1026,7 +1026,7 @@ The section describes the pattern matching rules by which C/C++ datatypes are as
The matching rules can be observed in practice by using the debugging options also described.
</p>
<H3><a name="Typemaps_nn17"></a>10.3.1 Basic matching rules</H3>
<H3><a name="Typemaps_nn17"></a>11.3.1 Basic matching rules</H3>
<p>
@ -1125,7 +1125,7 @@ void F(int x[1000]); // int [ANY] rule (typemap 5)
stripped all qualifiers in one step.
</p>
<H3><a name="Typemaps_typedef_reductions"></a>10.3.2 Typedef reductions matching</H3>
<H3><a name="Typemaps_typedef_reductions"></a>11.3.2 Typedef reductions matching</H3>
<p>
@ -1300,7 +1300,7 @@ void go(Struct aStruct);
</pre>
</div>
<H3><a name="Typemaps_nn19"></a>10.3.3 Default typemap matching rules</H3>
<H3><a name="Typemaps_nn19"></a>11.3.3 Default typemap matching rules</H3>
<p>
@ -1438,7 +1438,7 @@ Finally the best way to view the typemap matching rules in action is via the <a
simpler scheme to match the current C++ class template partial specialization matching rules.
</p>
<H3><a name="Typemaps_multi_argument_typemaps_patterns"></a>10.3.4 Multi-arguments typemaps</H3>
<H3><a name="Typemaps_multi_argument_typemaps_patterns"></a>11.3.4 Multi-arguments typemaps</H3>
<p>
@ -1468,7 +1468,7 @@ but all subsequent arguments must match exactly.
</p>
<H3><a name="Typemaps_matching_template_comparison"></a>10.3.5 Matching rules compared to C++ templates</H3>
<H3><a name="Typemaps_matching_template_comparison"></a>11.3.5 Matching rules compared to C++ templates</H3>
<p>
@ -1627,7 +1627,7 @@ are similar to those for specialized template handling.
</p>
<H3><a name="Typemaps_debugging_search"></a>10.3.6 Debugging typemap pattern matching</H3>
<H3><a name="Typemaps_debugging_search"></a>11.3.6 Debugging typemap pattern matching</H3>
<p>
@ -1840,7 +1840,7 @@ Also the types may be displayed slightly differently - <tt>char const *</tt> and
</li>
</ul>
<H2><a name="Typemaps_nn21"></a>10.4 Code generation rules</H2>
<H2><a name="Typemaps_nn21"></a>11.4 Code generation rules</H2>
<p>
@ -1848,7 +1848,7 @@ This section describes rules by which typemap code is inserted into
the generated wrapper code.
</p>
<H3><a name="Typemaps_nn22"></a>10.4.1 Scope</H3>
<H3><a name="Typemaps_nn22"></a>11.4.1 Scope</H3>
<p>
@ -1926,7 +1926,7 @@ a block scope when it is emitted. This sometimes results in a less complicated
Note that only the third of the three typemaps have the typemap code passed through the SWIG preprocessor.
</p>
<H3><a name="Typemaps_nn23"></a>10.4.2 Declaring new local variables</H3>
<H3><a name="Typemaps_nn23"></a>11.4.2 Declaring new local variables</H3>
<p>
@ -2077,7 +2077,7 @@ each type must have its own local variable declaration.
</div>
<H3><a name="Typemaps_special_variables"></a>10.4.3 Special variables</H3>
<H3><a name="Typemaps_special_variables"></a>11.4.3 Special variables</H3>
<p>
@ -2329,7 +2329,7 @@ Another approach, which only works for arrays is to use the <tt>$1_basetype</tt>
</pre>
</div>
<H3><a name="Typemaps_special_variable_macros"></a>10.4.4 Special variable macros</H3>
<H3><a name="Typemaps_special_variable_macros"></a>11.4.4 Special variable macros</H3>
<p>
@ -2341,7 +2341,7 @@ it is done during the SWIG parsing/compilation stages.
The following special variable macros are available across all language modules.
</p>
<H4><a name="Typemaps_special_macro_descriptor"></a>10.4.4.1 $descriptor(type)</H4>
<H4><a name="Typemaps_special_macro_descriptor"></a>11.4.4.1 $descriptor(type)</H4>
<p>
@ -2352,7 +2352,7 @@ For example, <tt>$descriptor(std::vector&lt;int&gt; *)</tt> will expand into <tt
This macro is mostly used in the scripting target languages and is demonstrated later in the <a href="#Typemaps_runtime_type_checker_usage">Run-time type checker usage</a> section.
</p>
<H4><a name="Typemaps_special_macro_typemap"></a>10.4.4.2 $typemap(method, typepattern)</H4>
<H4><a name="Typemaps_special_macro_typemap"></a>11.4.4.2 $typemap(method, typepattern)</H4>
<p>
@ -2409,7 +2409,7 @@ The result is the following expansion
</pre>
</div>
<H2><a name="Typemaps_nn25"></a>10.5 Common typemap methods</H2>
<H2><a name="Typemaps_nn25"></a>11.5 Common typemap methods</H2>
<p>
@ -2417,7 +2417,7 @@ The set of typemaps recognized by a language module may vary. However,
the following typemap methods are nearly universal:
</p>
<H3><a name="Typemaps_nn26"></a>10.5.1 "in" typemap</H3>
<H3><a name="Typemaps_nn26"></a>11.5.1 "in" typemap</H3>
<p>
@ -2477,7 +2477,7 @@ Usually <tt>numinputs</tt> is not specified, whereupon the default value is 1, t
is the same as the old "ignore" typemap.
</p>
<H3><a name="Typemaps_nn27"></a>10.5.2 "typecheck" typemap</H3>
<H3><a name="Typemaps_nn27"></a>11.5.2 "typecheck" typemap</H3>
<p>
@ -2503,7 +2503,7 @@ If you define new "in" typemaps <em>and</em> your program uses overloaded method
"typecheck" typemaps. More details about this follow in the <a href="#Typemaps_overloading">Typemaps and overloading</a> section.
</p>
<H3><a name="Typemaps_nn28"></a>10.5.3 "out" typemap</H3>
<H3><a name="Typemaps_nn28"></a>11.5.3 "out" typemap</H3>
<p>
@ -2534,7 +2534,7 @@ $symname - Name of function/method being wrapped
The "out" typemap supports an optional attribute flag called "optimal". This is for code optimisation and is detailed in the <a href="#Typemaps_optimal">Optimal code generation when returning by value</a> section.
</p>
<H3><a name="Typemaps_nn29"></a>10.5.4 "arginit" typemap</H3>
<H3><a name="Typemaps_nn29"></a>11.5.4 "arginit" typemap</H3>
<p>
@ -2553,7 +2553,7 @@ For example:
</pre>
</div>
<H3><a name="Typemaps_nn30"></a>10.5.5 "default" typemap</H3>
<H3><a name="Typemaps_nn30"></a>11.5.5 "default" typemap</H3>
<p>
@ -2586,7 +2586,7 @@ See the <a href="SWIG.html#SWIG_default_args">Default/optional arguments</a> sec
for further information on default argument wrapping.
</p>
<H3><a name="Typemaps_nn31"></a>10.5.6 "check" typemap</H3>
<H3><a name="Typemaps_nn31"></a>11.5.6 "check" typemap</H3>
<p>
@ -2605,7 +2605,7 @@ converted. For example:
</pre>
</div>
<H3><a name="Typemaps_nn32"></a>10.5.7 "argout" typemap</H3>
<H3><a name="Typemaps_nn32"></a>11.5.7 "argout" typemap</H3>
<p>
@ -2651,7 +2651,7 @@ return values are often appended to return value of the function.
See the <tt>typemaps.i</tt> library file for examples.
</p>
<H3><a name="Typemaps_nn33"></a>10.5.8 "freearg" typemap</H3>
<H3><a name="Typemaps_nn33"></a>11.5.8 "freearg" typemap</H3>
<p>
@ -2684,7 +2684,7 @@ be used in other typemaps whenever a wrapper function needs to abort
prematurely.
</p>
<H3><a name="Typemaps_nn34"></a>10.5.9 "newfree" typemap</H3>
<H3><a name="Typemaps_nn34"></a>11.5.9 "newfree" typemap</H3>
<p>
@ -2713,7 +2713,7 @@ string *foo();
See <a href="Customization.html#Customization_ownership">Object ownership and %newobject</a> for further details.
</p>
<H3><a name="Typemaps_nn35"></a>10.5.10 "memberin" typemap</H3>
<H3><a name="Typemaps_nn35"></a>11.5.10 "memberin" typemap</H3>
<p>
@ -2735,7 +2735,7 @@ It is rarely necessary to write "memberin" typemaps---SWIG already provides
a default implementation for arrays, strings, and other objects.
</p>
<H3><a name="Typemaps_nn36"></a>10.5.11 "varin" typemap</H3>
<H3><a name="Typemaps_nn36"></a>11.5.11 "varin" typemap</H3>
<p>
@ -2743,7 +2743,7 @@ The "varin" typemap is used to convert objects in the target language to C for t
purposes of assigning to a C/C++ global variable. This is implementation specific.
</p>
<H3><a name="Typemaps_nn37"></a>10.5.12 "varout" typemap</H3>
<H3><a name="Typemaps_nn37"></a>11.5.12 "varout" typemap</H3>
<p>
@ -2751,7 +2751,7 @@ The "varout" typemap is used to convert a C/C++ object to an object in the targe
language when reading a C/C++ global variable. This is implementation specific.
</p>
<H3><a name="throws_typemap"></a>10.5.13 "throws" typemap</H3>
<H3><a name="throws_typemap"></a>11.5.13 "throws" typemap</H3>
<p>
@ -2797,7 +2797,7 @@ Note that if your methods do not have an exception specification yet they do thr
For a neat way to handle these, see the <a href="Customization.html#Customization_exception">Exception handling with %exception</a> section.
</p>
<H2><a name="Typemaps_nn39"></a>10.6 Some typemap examples</H2>
<H2><a name="Typemaps_nn39"></a>11.6 Some typemap examples</H2>
<p>
@ -2805,7 +2805,7 @@ This section contains a few examples. Consult language module documentation
for more examples.
</p>
<H3><a name="Typemaps_nn40"></a>10.6.1 Typemaps for arrays</H3>
<H3><a name="Typemaps_nn40"></a>11.6.1 Typemaps for arrays</H3>
<p>
@ -3064,7 +3064,7 @@ Now, you will find that member access is quite nice:
useless and has since been eliminated. To return structure members, simply use the "out" typemap.
</p>
<H3><a name="Typemaps_nn41"></a>10.6.2 Implementing constraints with typemaps</H3>
<H3><a name="Typemaps_nn41"></a>11.6.2 Implementing constraints with typemaps</H3>
<p>
@ -3112,7 +3112,7 @@ a NULL pointer. As a result, SWIG can often prevent a potential
segmentation faults or other run-time problems by raising an exception
rather than blindly passing values to the underlying C/C++ program.</p>
<H2><a name="Typemaps_nn43"></a>10.7 Typemaps for multiple target languages</H2>
<H2><a name="Typemaps_nn43"></a>11.7 Typemaps for multiple target languages</H2>
<p>
@ -3142,7 +3142,7 @@ The example above also shows a common approach of issuing a warning for an as ye
<tt>%typemap(ruby,in) int "$1 = NUM2INT($input);"</tt>.
</p>
<H2><a name="Typemaps_optimal"></a>10.8 Optimal code generation when returning by value</H2>
<H2><a name="Typemaps_optimal"></a>11.8 Optimal code generation when returning by value</H2>
<p>
@ -3331,7 +3331,7 @@ example.i:7: Warning 475: optimal attribute usage in the out typemap.
However, it doesn't always get it right, for example when <tt>$1</tt> is within some commented out code.
</p>
<H2><a name="Typemaps_multi_argument_typemaps"></a>10.9 Multi-argument typemaps</H2>
<H2><a name="Typemaps_multi_argument_typemaps"></a>11.9 Multi-argument typemaps</H2>
<p>
@ -3598,7 +3598,7 @@ with non-consecutive C/C++ arguments; a workaround such as a helper function re-
the arguments to make them consecutive will need to be written.
</p>
<H2><a name="Typemaps_warnings"></a>10.10 Typemap warnings</H2>
<H2><a name="Typemaps_warnings"></a>11.10 Typemap warnings</H2>
<p>
@ -3607,7 +3607,7 @@ See the information in the <a href="Warnings.html#Warnings_nn5">issuing warnings
</p>
<H2><a name="Typemaps_fragments"></a>10.11 Typemap fragments</H2>
<H2><a name="Typemaps_fragments"></a>11.11 Typemap fragments</H2>
<p>
@ -3860,7 +3860,7 @@ fragment usage unless a desire to really get to grips
with some powerful but tricky macro and fragment usage that is used in parts of the SWIG typemap library.
</p>
<H3><a name="Typemaps_fragment_type_specialization"></a>10.11.1 Fragment type specialization</H3>
<H3><a name="Typemaps_fragment_type_specialization"></a>11.11.1 Fragment type specialization</H3>
<p>
@ -3893,7 +3893,7 @@ struct A {
</pre>
</div>
<H3><a name="Typemaps_automatic_specialization"></a>10.11.2 Fragments and automatic typemap specialization</H3>
<H3><a name="Typemaps_automatic_specialization"></a>11.11.2 Fragments and automatic typemap specialization</H3>
<p>
@ -3939,7 +3939,7 @@ The interested (or very brave) reader can take a look at the fragments.swg file
</p>
<H2><a name="Typemaps_runtime_type_checker"></a>10.12 The run-time type checker</H2>
<H2><a name="Typemaps_runtime_type_checker"></a>11.12 The run-time type checker</H2>
<p>
@ -3956,7 +3956,7 @@ Requirements for the type system:
<li>Store inheritance and type equivalence information and be able to correctly
re-create the type pointer.</li>
<li>Share type information between modules.</li>
<li>Modules can be loaded in any order, irregardless of actual type
<li>Modules can be loaded in any order, regardless of actual type
dependency.</li>
<li>Avoid the use of dynamically allocated memory, and library/system calls in general.</li>
<li>Provide a reasonably fast implementation, minimizing the lookup time for all
@ -3965,7 +3965,7 @@ language modules.</li>
<li>Modules can be unloaded from the type system.</li>
</ul>
<H3><a name="Typemaps_nn45"></a>10.12.1 Implementation</H3>
<H3><a name="Typemaps_nn45"></a>11.12.1 Implementation</H3>
<p>
@ -4151,7 +4151,7 @@ structures rather than creating new ones. These <tt>swig_module_info</tt>
structures are chained together in a circularly linked list.
</p>
<H3><a name="Typemaps_runtime_type_checker_usage"></a>10.12.2 Usage</H3>
<H3><a name="Typemaps_runtime_type_checker_usage"></a>11.12.2 Usage</H3>
<p>This section covers how to use these functions from typemaps. To learn how to
@ -4245,7 +4245,7 @@ probably just look at the output of SWIG to get a better sense for how types are
managed.
</p>
<H2><a name="Typemaps_overloading"></a>10.13 Typemaps and overloading</H2>
<H2><a name="Typemaps_overloading"></a>11.13 Typemaps and overloading</H2>
<p>
@ -4556,7 +4556,7 @@ Subsequent "in" typemaps would then perform more extensive type-checking.
</li>
</ul>
<H2><a name="Typemaps_nn48"></a>10.14 More about <tt>%apply</tt> and <tt>%clear</tt></H2>
<H2><a name="Typemaps_nn48"></a>11.14 More about <tt>%apply</tt> and <tt>%clear</tt></H2>
<p>
@ -4642,7 +4642,7 @@ example:
</div>
<H2><a name="Typemaps_nn47"></a>10.15 Passing data between typemaps</H2>
<H2><a name="Typemaps_nn47"></a>11.15 Passing data between typemaps</H2>
<p>
@ -4679,7 +4679,7 @@ sure that the typemaps sharing information have exactly the same types and names
</p>
<H2><a name="Typemaps_nn52"></a>10.16 C++ "this" pointer</H2>
<H2><a name="Typemaps_nn52"></a>11.16 C++ "this" pointer</H2>
<p>
@ -4739,7 +4739,7 @@ will also match the typemap. One work around is to create an interface file tha
the method, but gives the argument a name other than <tt>self</tt>.
</p>
<H2><a name="Typemaps_nn51"></a>10.17 Where to go for more information?</H2>
<H2><a name="Typemaps_nn51"></a>11.17 Where to go for more information?</H2>
<p>

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Varargs"></a>13 Variable Length Arguments</H1>
<H1><a name="Varargs"></a>14 Variable Length Arguments</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -42,7 +42,7 @@ added in SWIG-1.3.12. Most other wrapper generation tools have
wisely chosen to avoid this issue.
</p>
<H2><a name="Varargs_nn2"></a>13.1 Introduction</H2>
<H2><a name="Varargs_nn2"></a>14.1 Introduction</H2>
<p>
@ -139,7 +139,7 @@ List make_list(const char *s, ...) {
</pre>
</div>
<H2><a name="Varargs_nn3"></a>13.2 The Problem</H2>
<H2><a name="Varargs_nn3"></a>14.2 The Problem</H2>
<p>
@ -232,7 +232,7 @@ can also support real varargs wrapping (with stack-frame manipulation) if you
are willing to get hands dirty. Keep reading.
</p>
<H2><a name="Varargs_nn4"></a>13.3 Default varargs support</H2>
<H2><a name="Varargs_nn4"></a>14.3 Default varargs support</H2>
<p>
@ -301,7 +301,7 @@ Read on for further solutions.
</p>
<H2><a name="Varargs_nn5"></a>13.4 Argument replacement using %varargs</H2>
<H2><a name="Varargs_nn5"></a>14.4 Argument replacement using %varargs</H2>
<p>
@ -398,7 +398,7 @@ int execlp(const char *path, const char *arg, ...);
</div>
<p>
Note that <tt>str3</tt> is the name of the last argument, as we have used <tt>%vargars</tt> with 3.
Note that <tt>str3</tt> is the name of the last argument, as we have used <tt>%varargs</tt> with 3.
Now <tt>execlp("a", "b", "c", "d", "e")</tt> will result in an error as one too many arguments has been passed,
as now only 2 additional 'str' arguments can be passed with the 3rd one always using the specified default <tt>NULL</tt>.
</p>
@ -412,7 +412,7 @@ mixed argument types such as <tt>printf()</tt>. Providing general purpose
wrappers to such functions presents special problems (covered shortly).
</p>
<H2><a name="Varargs_nn6"></a>13.5 Varargs and typemaps</H2>
<H2><a name="Varargs_nn6"></a>14.5 Varargs and typemaps</H2>
<p>
@ -509,10 +509,10 @@ like this:
<div class="code">
<pre>
%typemap(in) (...)(char *args[10]) {
%typemap(in) (...)(char *vargs[10]) {
int i;
int argc;
for (i = 0; i &lt; 10; i++) args[i] = 0;
for (i = 0; i &lt; 10; i++) vargs[i] = 0;
argc = PyTuple_Size(varargs);
if (argc &gt; 10) {
PyErr_SetString(PyExc_ValueError, "Too many arguments");
@ -528,7 +528,7 @@ like this:
return NULL;
}
pystr = PyUnicode_AsUTF8String(pyobj);
str = PyBytes_AsString(pystr);
str = strdup(PyBytes_AsString(pystr));
Py_XDECREF(pystr);
%#else
if (!PyString_Check(pyobj)) {
@ -537,22 +537,34 @@ like this:
}
str = PyString_AsString(pyobj);
%#endif
args[i] = str;
vargs[i] = str;
}
$1 = (void *) args;
$1 = (void *)vargs;
}
%typemap(freearg) (...) {
%#if PY_VERSION_HEX&gt;=0x03000000
int i;
for (i = 0; i &lt; 10; i++) {
free(vargs$argnum[i]);
}
%#endif
}
</pre>
</div>
<p>
In this typemap, the special variable <tt>varargs</tt> is a tuple
In the 'in' typemap, the special variable <tt>varargs</tt> is a tuple
holding all of the extra arguments passed (this is specific to the
Python module). The typemap then pulls this apart and sticks the
values into the array of strings <tt>args</tt>. Then, the array is
assigned to <tt>$1</tt> (recall that this is the <tt>void *</tt>
variable corresponding to <tt>(...)</tt>). However, this assignment
is only half of the picture----clearly this alone is not enough to
make the function work. To patch everything up, you have to rewrite the
make the function work. The 'freearg' typemap cleans up memory
allocated in the 'in' typemap; this code is generated to be called
after the <tt>execlp</tt> function is called. To patch everything
up, you have to rewrite the
underlying action code using the <tt>%feature</tt> directive like
this:
</p>
@ -560,9 +572,9 @@ this:
<div class="code">
<pre>
%feature("action") execlp {
char *args = (char **) arg3;
result = execlp(arg1, arg2, args[0], args[1], args[2], args[3], args[4],
args[5],args[6],args[7],args[8],args[9], NULL);
char **vargs = (char **) arg3;
result = execlp(arg1, arg2, vargs[0], vargs[1], vargs[2], vargs[3], vargs[4],
vargs[5], vargs[6], vargs[7], vargs[8], vargs[9], NULL);
}
int execlp(const char *path, const char *arg, ...);
@ -577,7 +589,7 @@ really want to elevate your guru status and increase your job
security, continue to the next section.
</p>
<H2><a name="Varargs_nn7"></a>13.6 Varargs wrapping with libffi</H2>
<H2><a name="Varargs_nn7"></a>14.6 Varargs wrapping with libffi</H2>
<p>
@ -829,7 +841,7 @@ provide an argument number for the first extra argument. This can be used to in
values. Please consult the chapter on each language module for more details.
</p>
<H2><a name="Varargs_nn8"></a>13.7 Wrapping of va_list</H2>
<H2><a name="Varargs_nn8"></a>14.7 Wrapping of va_list</H2>
<p>
@ -839,13 +851,13 @@ of type <tt>va_list</tt>. For example:
<div class="code">
<pre>
int vfprintf(FILE *f, const char *fmt, va_list ap);
int vprintf(const char *fmt, va_list ap);
</pre>
</div>
<p>
As far as we know, there is no obvious way to wrap these functions
with SWIG. This is because there is no documented way to assemble the
As far as we know, there is no obvious way to wrap these functions with
SWIG. This is because there is no documented way to assemble the
proper va_list structure (there are no C library functions to do it
and the contents of va_list are opaque). Not only that, the contents
of a <tt>va_list</tt> structure are closely tied to the underlying
@ -853,7 +865,37 @@ call-stack. It's not clear that exporting a <tt>va_list</tt> would
have any use or that it would work at all.
</p>
<H2><a name="Varargs_nn9"></a>13.8 C++ Issues</H2>
<p>
A workaround can be implemented by writing a simple varargs C wrapper and then using the techniques
discussed earlier in this chapter for varargs. Below is a simple wrapper for <tt>vprintf</tt> renamed so that
it can still be called as <tt>vprintf</tt> from your target language. The <tt>%varargs</tt>
used in the example restricts the function to taking one string argument.
</p>
<div class="code">
<pre>
%{
int vprintf(const char *fmt, va_list ap);
%}
%varargs(const char *) my_vprintf;
%rename(vprintf) my_vprintf;
%inline %{
int my_vprintf(const char *fmt, ...) {
va_list ap;
int result;
va_start(ap, fmt);
result = vprintf(fmt, ap);
va_end(ap);
return result;
}
%}
</pre>
</div>
<H2><a name="Varargs_nn9"></a>14.8 C++ Issues</H2>
<p>
@ -922,7 +964,7 @@ design or to provide an alternative interface using a helper function than it is
fully general wrapper to a varargs C++ member function.
</p>
<H2><a name="Varargs_nn10"></a>13.9 Discussion</H2>
<H2><a name="Varargs_nn10"></a>14.9 Discussion</H2>
<p>

View file

@ -6,7 +6,7 @@
</head>
<body bgcolor="#ffffff">
<H1><a name="Warnings"></a>14 Warning Messages</H1>
<H1><a name="Warnings"></a>15 Warning Messages</H1>
<!-- INDEX -->
<div class="sectiontoc">
<ul>
@ -35,7 +35,7 @@
<H2><a name="Warnings_nn2"></a>14.1 Introduction</H2>
<H2><a name="Warnings_nn2"></a>15.1 Introduction</H2>
<p>
@ -55,7 +55,7 @@ where the generated wrapper code will probably compile, but it may not
work like you expect.
</p>
<H2><a name="Warnings_suppression"></a>14.2 Warning message suppression</H2>
<H2><a name="Warnings_suppression"></a>15.2 Warning message suppression</H2>
<p>
@ -147,7 +147,7 @@ your interface. Ignore the warning messages at your own peril.
</p>
<H2><a name="Warnings_nn4"></a>14.3 Enabling extra warnings</H2>
<H2><a name="Warnings_nn4"></a>15.3 Enabling extra warnings</H2>
<p>
@ -220,7 +220,7 @@ that is, any warnings suppressed or added in <tt>%warnfilter</tt>, <tt>#pragma S
or the <tt>-w</tt> option.
</p>
<H2><a name="Warnings_nn5"></a>14.4 Issuing a warning message</H2>
<H2><a name="Warnings_nn5"></a>15.4 Issuing a warning message</H2>
<p>
@ -274,7 +274,7 @@ example.i:24: Warning 901: You are really going to regret this usage of blah * s
</pre>
</div>
<H2><a name="Warnings_symbolic_symbols"></a>14.5 Symbolic symbols</H2>
<H2><a name="Warnings_symbolic_symbols"></a>15.5 Symbolic symbols</H2>
<p>
@ -309,7 +309,7 @@ or
</pre>
</div>
<H2><a name="Warnings_nn6"></a>14.6 Commentary</H2>
<H2><a name="Warnings_nn6"></a>15.6 Commentary</H2>
<p>
@ -326,7 +326,7 @@ no obvious recovery. There is no mechanism for suppressing error
messages.
</p>
<H2><a name="Warnings_nn7"></a>14.7 Warnings as errors</H2>
<H2><a name="Warnings_nn7"></a>15.7 Warnings as errors</H2>
<p>
@ -335,7 +335,7 @@ option. This will cause SWIG to exit with a non successful exit code if a
warning is encountered.
</p>
<H2><a name="Warnings_nn8"></a>14.8 Message output format</H2>
<H2><a name="Warnings_nn8"></a>15.8 Message output format</H2>
<p>
@ -354,10 +354,10 @@ $ swig -python -Fmicrosoft example.i
example.i(4) : Syntax error in input.
</pre></div>
<H2><a name="Warnings_nn9"></a>14.9 Warning number reference</H2>
<H2><a name="Warnings_nn9"></a>15.9 Warning number reference</H2>
<H3><a name="Warnings_nn10"></a>14.9.1 Deprecated features (100-199)</H3>
<H3><a name="Warnings_nn10"></a>15.9.1 Deprecated features (100-199)</H3>
<ul>
@ -382,9 +382,10 @@ example.i(4) : Syntax error in input.
<li>119. Deprecated <tt>%typemap(ignore)</tt>.
<li>120. Deprecated command line option (-runtime, -noruntime).
<li>121. Deprecated <tt>%name</tt> directive.
<li>126. The 'nestedworkaround' feature is deprecated.
</ul>
<H3><a name="Warnings_nn11"></a>14.9.2 Preprocessor (200-299)</H3>
<H3><a name="Warnings_nn11"></a>15.9.2 Preprocessor (200-299)</H3>
<ul>
@ -396,7 +397,7 @@ example.i(4) : Syntax error in input.
<li>206. Unexpected tokens after #<em>directive</em> directive.
</ul>
<H3><a name="Warnings_nn12"></a>14.9.3 C/C++ Parser (300-399)</H3>
<H3><a name="Warnings_nn12"></a>15.9.3 C/C++ Parser (300-399)</H3>
<ul>
@ -423,7 +424,8 @@ example.i(4) : Syntax error in input.
<li>322. Redundant redeclaration of '<em>name</em>'.
<li>323. Recursive scope inheritance of '<em>name</em>'.
<li>324. Named nested template instantiations not supported. Processing as if no name was given to %template().
<li>325. Nested class not currently supported (<em>name</em> ignored).
<li>325. Nested <em>kind</em> not currently supported (<em>name</em> ignored).
<li>326. Deprecated %extend name used - the <em>kind</em> name '<em>name</em>' should be used instead of the typedef name '<em>name</em>'.
<li>350. operator new ignored.
<li>351. operator delete ignored.
<li>352. operator+ ignored.
@ -472,7 +474,7 @@ example.i(4) : Syntax error in input.
<li>395. operator delete[] ignored.
</ul>
<H3><a name="Warnings_nn13"></a>14.9.4 Types and typemaps (400-499) </H3>
<H3><a name="Warnings_nn13"></a>15.9.4 Types and typemaps (400-499) </H3>
<ul>
@ -497,11 +499,13 @@ example.i(4) : Syntax error in input.
<li>471. Unable to use return type <em>type</em> in director method
<li>474. Method <em>method</em> usage of the optimal attribute ignored in the out typemap as the following cannot be used to generate optimal code: <em>code</em>
<li>475. Multiple calls to <em>method</em> might be generated due to optimal attribute usage in the out typemap.
<li>476. Initialization using std::initializer_list.
<li>477. No directorthrows typemap defined for <em>type</em>
</ul>
<H3><a name="Warnings_nn14"></a>14.9.5 Code generation (500-599)</H3>
<H3><a name="Warnings_nn14"></a>15.9.5 Code generation (500-599)</H3>
<ul>
@ -526,9 +530,11 @@ example.i(4) : Syntax error in input.
<li>519. %template() contains no name. Template method ignored: <em>declaration</em>
<li>520. <em>Base/Derived</em> class '<em>classname1</em>' of '<em>classname2</em>' is not similarly marked as a smart pointer.
<li>521. Illegal destructor name <em>name</em>. Ignored.
<li>522. Use of an illegal constructor name '<em>name</em>' in %extend is deprecated, the constructor name should be '<em>name</em>'.
<li>523. Use of an illegal destructor name '<em>name</em>' in %extend is deprecated, the destructor name should be '<em>name</em>'.
</ul>
<H3><a name="Warnings_nn15"></a>14.9.6 Language module specific (700-899) </H3>
<H3><a name="Warnings_nn15"></a>15.9.6 Language module specific (700-899) </H3>
<ul>
@ -551,6 +557,8 @@ example.i(4) : Syntax error in input.
<li>822. Covariant return types not supported in Java. Proxy method will return <em>basetype</em> (Java).
<li>823. No javaconstruct typemap defined for <em>type</em> (Java).
<li>824. Missing JNI descriptor in directorin typemap defined for <em>type</em> (Java).
<li>825. "directorconnect" attribute missing in <em>type</em> "javaconstruct" typemap. (Java).
<li>826. The nspace feature is used on '<em>type</em>' without -package. The generated code may not compile as Java does not support types declared in a named package accessing types declared in an unnamed package. (Java).
</ul>
<ul>
@ -577,14 +585,14 @@ example.i(4) : Syntax error in input.
<li>871. Unrecognized pragma <em>pragma</em>. (Php).
</ul>
<H3><a name="Warnings_nn16"></a>14.9.7 User defined (900-999)</H3>
<H3><a name="Warnings_nn16"></a>15.9.7 User defined (900-999)</H3>
<p>
These numbers can be used by your own application.
</p>
<H2><a name="Warnings_nn17"></a>14.10 History</H2>
<H2><a name="Warnings_nn17"></a>15.10 History</H2>
<p>

View file

@ -79,8 +79,8 @@ If you want to build your own swig.exe have a look at <a href="#Windows_swig_exe
Using Microsoft Visual C++ is the most common approach to compiling and linking SWIG's output.
The Examples directory has a few Visual C++ project files (.dsp files).
These were produced by Visual C++ 6.
Later versions of Visual Studio should also be able to open and convert these project files.
The C# examples come with .NET 2003 solution (.sln) and project files instead of Visual C++ 6 project files.
Newer versions of Visual Studio should be able to open and convert these project files.
Each C# example comes with a Visual Studio 2005 solution and associated project files instead of Visual C++ 6 project files.
The project files have been set up to execute SWIG in a custom build rule for the SWIG interface (.i) file.
Alternatively run the <a href="#Windows_examples_cygwin">examples using Cygwin</a>.
@ -147,7 +147,7 @@ PERL5_LIB: D:\nsPerl5.004_04\lib\CORE\perl.lib<br>
<p>
<b><tt>PYTHON_INCLUDE</tt></b> : Set this to the directory that contains python.h<br>
<b><tt>PYTHON_INCLUDE</tt></b> : Set this to the directory that contains Python.h<br>
<b><tt>PYTHON_LIB</tt></b> : Set this to the python library including path for linking<p>
Example using Python 2.1.1:<br>
<tt>
@ -236,8 +236,8 @@ The short abbreviated instructions follow...
</ul>
<p>
The step by step instructions to download and install MinGW and MSYS, then download and build the latest version of SWIG from SVN follow...
Note that the instructions for obtaining SWIG from SVN are also online at <a href="http://www.swig.org/svn.html">SWIG SVN</a>.
The step by step instructions to download and install MinGW and MSYS, then download and build the latest version of SWIG from Github follow...
Note that the instructions for obtaining SWIG from Github are also online at <a href="http://www.swig.org/svn.html">SWIG Bleeding Edge</a>.
</p>
<p>
@ -300,15 +300,19 @@ tar -zxf bison-2.0-MSYS.tar.gz
</li>
<li>
To get the latest SWIG SVN (version from Subversion source control), type in the following:
The very latest development version of SWIG is available from <a href="https://github.com/swig/swig">SWIG on Github</a>
and can be downloaded as a zip file or if you have Git installed, via Git.
Either download the latest <a href="https://github.com/swig/swig/archive/master.zip">Zip file</a> snapshot and unzip and rename the top level folder to /usr/src/swig.
Otherwise if using Git, type in the following:
<div class="shell"><pre>
mkdir /usr/src
cd /usr/src
svn co https://swig.svn.sourceforge.net/svnroot/swig/trunk swig
git clone https://github.com/swig/swig.git
</pre></div>
<b>Pitfall note:</b>
If you want to check out SWIG to a different folder to the proposed
If you want to place SWIG in a different folder to the proposed
/usr/src/swig, do not use MSYS emulated windows drive letters, because
the autotools will fail miserably on those.
</li>

View file

@ -4,6 +4,7 @@ Windows.html
Scripting.html
SWIG.html
SWIGPlus.html
CPlusPlus11.html
Preprocessor.html
Library.html
Arguments.html

View file

@ -1,10 +1,10 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SWIG-2.0 Documentation</title>
<title>SWIG-3.0 Documentation</title>
</head>
<body bgcolor="#ffffff">
<H1><a name="index"></a>SWIG-2.0 Documentation</h1>
<H1><a name="index"></a>SWIG-3.0 Documentation</h1>
The SWIG documentation is available in one of the following formats.
<ul>

View file

@ -1,25 +1,66 @@
#
# Patch managed by http://www.holgerschurig.de/patcher.html
#
# This patch is against htmldoc 1.8.24, and it hacks in support for
# This patch is against htmldoc 1.8.27, and it hacks in support for
# correctly indenting the <div class=""> sections in the SWIG manual.
# This patch should only be used until the 1.9 branch of htmldoc
# stabalizes, since the 1.9 branch includes true CSS1 support.
# stabilizes, since the 1.9 branch includes true CSS1 support.
#
# This patch only affects the PDF generation, an unpatched htmldoc
# creates the one-page html documentation just fine.
#
--- htmldoc-1.8.24/htmldoc/ps-pdf.cxx~margin-left
+++ htmldoc-1.8.24/htmldoc/ps-pdf.cxx
@@ -158,6 +158,7 @@
diff -Naur htmldoc-1.8.27/htmldoc/htmldoc.cxx htmldoc-1.8.27-margin-left/htmldoc/htmldoc.cxx
--- htmldoc-1.8.27/htmldoc/htmldoc.cxx 2006-03-30 14:01:20.000000000 +0100
+++ htmldoc-1.8.27-margin-left/htmldoc/htmldoc.cxx 2013-05-11 10:11:47.428435647 +0100
@@ -65,6 +65,8 @@
const char *__XOS2RedirRoot(const char *);
}
#endif
+
+extern void parse_style(char *);
/*
@@ -1115,6 +1117,7 @@
else if (compare_strings(argv[i], "--version", 6) == 0)
{
puts(SVERSION);
+ puts("Patched with margin-left.patch");
return (0);
}
else if (compare_strings(argv[i], "--webpage", 3) == 0)
@@ -2403,6 +2406,10 @@
}
else if (strcmp(temp, "--cookies") == 0)
file_cookies(temp2);
+ else if (strcmp(temp, "--stylesheet") == 0)
+ {
+ parse_style(temp2);
+ }
}
}
diff -Naur htmldoc-1.8.27/htmldoc/Makefile htmldoc-1.8.27-margin-left/htmldoc/Makefile
--- htmldoc-1.8.27/htmldoc/Makefile 2005-10-28 21:32:59.000000000 +0100
+++ htmldoc-1.8.27-margin-left/htmldoc/Makefile 2013-05-11 09:39:04.392367869 +0100
@@ -36,7 +36,7 @@
OBJS = gui.o file.o html.o htmldoc.o htmllib.o htmlsep.o \
http.o http-addr.o http-addrlist.o http-support.o image.o \
iso8859.o license.o md5.o progress.o ps-pdf.o rc4.o \
- snprintf.o string.o toc.o util.o
+ snprintf.o string.o toc.o util.o style.o
#
diff -Naur htmldoc-1.8.27/htmldoc/ps-pdf.cxx htmldoc-1.8.27-margin-left/htmldoc/ps-pdf.cxx
--- htmldoc-1.8.27/htmldoc/ps-pdf.cxx 2006-08-01 17:58:50.000000000 +0100
+++ htmldoc-1.8.27-margin-left/htmldoc/ps-pdf.cxx 2013-05-11 09:37:40.096364957 +0100
@@ -160,6 +160,7 @@
# undef page_t
#endif // __hpux
+extern int lookup_div_class(uchar *);
/*
* Constants...
@@ -4188,9 +4189,24 @@
* Output options...
@@ -4230,9 +4231,24 @@
para->child = para->last_child = NULL;
}
@ -45,30 +86,9 @@
if (para->child != NULL)
{
parse_paragraph(para, *left, *right, *bottom, *top, x, y, page, *needspace);
--- htmldoc-1.8.24/htmldoc/htmldoc.cxx~margin-left
+++ htmldoc-1.8.24/htmldoc/htmldoc.cxx
@@ -62,6 +62,8 @@
const char *__XOS2RedirRoot(const char *);
}
#endif
+
+extern void parse_style(char *);
/*
@@ -2140,6 +2142,10 @@
}
else if (strcmp(temp, "--cookies") == 0)
file_cookies(temp2);
+ else if (strcmp(temp, "--stylesheet") == 0)
+ {
+ parse_style(temp2);
+ }
}
}
--- /dev/null
+++ htmldoc-1.8.24/htmldoc/style.cxx
diff -Naur htmldoc-1.8.27/htmldoc/style.cxx htmldoc-1.8.27-margin-left/htmldoc/style.cxx
--- htmldoc-1.8.27/htmldoc/style.cxx 1970-01-01 01:00:00.000000000 +0100
+++ htmldoc-1.8.27-margin-left/htmldoc/style.cxx 2013-05-11 09:37:40.096364957 +0100
@@ -0,0 +1,185 @@
+/* Extreamly simple parsing routines for CSS style sheets.
+ * We only parse div.class { } sections, and only look
@ -255,15 +275,3 @@
+
+ fclose(f);
+}
--- htmldoc-1.8.24/htmldoc/Makefile~margin-left
+++ htmldoc-1.8.24/htmldoc/Makefile
@@ -35,7 +35,7 @@
OBJS = gui.o file.o html.o htmldoc.o htmllib.o htmlsep.o http.o \
http-addr.o http-support.o image.o iso8859.o license.o md5.o \
- progress.o ps-pdf.o rc4.o snprintf.o string.o toc.o util.o
+ progress.o ps-pdf.o rc4.o snprintf.o string.o toc.o util.o style.o
#

File diff suppressed because it is too large Load diff

View file

@ -1,24 +1,18 @@
SWIG Examples
The "perl5", "python", "tcl", "guile", "java", "mzscheme", "ruby", and
"chicken" directories contain a number of simple examples that are
primarily used for testing.
The subdirectories of "Examples" named after SWIG's language backends
contain a number of simple examples that are primarily used for testing.
The file 'index.html' is the top of a hyperlinked document that
contains information about all of the examples along with various
notes related to each example.
The Examples directory is currently quite incomplete because it
is being reorganized. A more complete set of examples can be found
in the SWIG1.1p5 distribution (most of which should still work with
SWIG1.3).
Note: All of the examples rely upon the Makefile in this directory.
You may need to edit it to reflect the configuration of your machine
in case the configure script guesses incorrect settings.
*** Special note concering C++ ***
*** Special note concerning C++ ***
The configure script is currently unable to handle all of the possible
options for producing dynamically loadable C++ extensions. Here are

View file

@ -1,3 +1,4 @@
# see top-level Makefile.in
class
extend
simple

View file

@ -2,28 +2,25 @@ TOP = ../..
SWIG = $(TOP)/../preinst-swig
TARGET = example
INTERFACE = example.i
INTERFACEDIR = jni/
PACKAGEDIR = src/org/swig
PACKAGENAME= org.swig.classexample
SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/classexample
SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/classexample
PROJECTNAME= SwigClass
TARGETID = 1
#INSTALLOPTIONS = -s # To install on SD Card
all:: android
check: build
android::
android update project --target $(TARGETID) --name $(PROJECTNAME) --path .
$(SWIG) -c++ -java $(SWIGOPT) -o jni/$(TARGET)_wrap.cpp jni/$(INTERFACE)
ndk-build
ant debug
build:
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' \
PROJECTNAME='$(PROJECTNAME)' TARGETID='$(TARGETID)' android_cpp
install::
-adb uninstall $(PACKAGENAME)
adb install bin/$(PROJECTNAME)-debug.apk
install:
$(MAKE) -f $(TOP)/Makefile INSTALLOPTIONS='$(INSTALLOPTIONS)' PROJECTNAME='$(PROJECTNAME)' \
PACKAGEDIR='$(PACKAGEDIR)' PACKAGENAME='$(PACKAGENAME)' android_install
clean::
ant clean
rm -f jni/$(TARGET)_wrap.cpp
rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java`
check: all
clean:
$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' PROJECTNAME='$(PROJECTNAME)' \
PACKAGEDIR='$(PACKAGEDIR)' INTERFACEDIR='$(INTERFACEDIR)' android_clean

View file

@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) {
int Shape::nshapes = 0;
double Circle::area(void) {
double Circle::area() {
return M_PI*radius*radius;
}
double Circle::perimeter(void) {
double Circle::perimeter() {
return 2*M_PI*radius;
}
double Square::area(void) {
double Square::area() {
return width*width;
}
double Square::perimeter(void) {
double Square::perimeter() {
return 4*width;
}

View file

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

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.swig.extendexample"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" >
<activity android:name="SwigExtend"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View file

@ -0,0 +1,26 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
TARGET = example
INTERFACE = example.i
INTERFACEDIR = jni/
PACKAGEDIR = src/org/swig
PACKAGENAME= org.swig.extendexample
SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/extendexample
PROJECTNAME= SwigExtend
TARGETID = 1
#INSTALLOPTIONS = -s # To install on SD Card
check: build
build:
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' \
PROJECTNAME='$(PROJECTNAME)' TARGETID='$(TARGETID)' android_cpp
install:
$(MAKE) -f $(TOP)/Makefile INSTALLOPTIONS='$(INSTALLOPTIONS)' PROJECTNAME='$(PROJECTNAME)' \
PACKAGEDIR='$(PACKAGEDIR)' PACKAGENAME='$(PACKAGENAME)' android_install
clean:
$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' PROJECTNAME='$(PROJECTNAME)' \
PACKAGEDIR='$(PACKAGEDIR)' INTERFACEDIR='$(INTERFACEDIR)' android_clean

View file

@ -0,0 +1,17 @@
# This file is used to override default values used by the Ant build system.
#
# This file must be checked in Version Control Systems, as it is
# integral to the build system of your project.
# This file is only used by the Ant script.
# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.
# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.

View file

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="SwigExtend" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<loadproperties srcFile="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'"
unless="sdk.dir"
/>
<!-- extension targets. Uncomment the ones where you want to do custom work
in between standard targets -->
<!--
<target name="-pre-build">
</target>
<target name="-pre-compile">
</target>
/* This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir} */
<target name="-post-compile">
</target>
-->
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

View file

@ -0,0 +1,10 @@
# File: Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := example
LOCAL_SRC_FILES := example_wrap.cpp example.cpp
LOCAL_CFLAGS := -frtti
include $(BUILD_SHARED_LIBRARY)

View file

@ -0,0 +1,2 @@
# File: Application.mk
APP_STL := gnustl_static

View file

@ -0,0 +1,14 @@
/* File : example.cxx */
#include "example.h"
static Streamer * streamerInstance = 0;
void setStreamer(Streamer* streamer) {
streamerInstance = streamer;
}
Streamer& getStreamer() {
return *streamerInstance;
}

View file

@ -0,0 +1,71 @@
/* File : example.h */
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <sstream>
struct Streamer {
virtual void display(std::string text) const = 0;
virtual ~Streamer() {}
};
void setStreamer(Streamer* streamer);
Streamer& getStreamer();
template<typename T> Streamer& operator<<(Streamer& stream, T const& val) {
std::ostringstream s;
s << val;
stream.display(s.str());
return stream;
}
class Employee {
private:
std::string name;
public:
Employee(const char* n): name(n) {}
virtual std::string getTitle() { return getPosition() + " " + getName(); }
virtual std::string getName() { return name; }
virtual std::string getPosition() const { return "Employee"; }
virtual ~Employee() { getStreamer() << "~Employee() @ " << this << "\n"; }
};
class Manager: public Employee {
public:
Manager(const char* n): Employee(n) {}
virtual std::string getPosition() const { return "Manager"; }
};
class EmployeeList {
std::vector<Employee*> list;
public:
EmployeeList() {
list.push_back(new Employee("Bob"));
list.push_back(new Employee("Jane"));
list.push_back(new Manager("Ted"));
}
void addEmployee(Employee *p) {
list.push_back(p);
getStreamer() << "New employee added. Current employees are:" << "\n";
std::vector<Employee*>::iterator i;
for (i=list.begin(); i!=list.end(); i++) {
getStreamer() << " " << (*i)->getTitle() << "\n";
}
}
const Employee *get_item(int i) {
return list[i];
}
~EmployeeList() {
std::vector<Employee*>::iterator i;
getStreamer() << "~EmployeeList, deleting " << list.size() << " employees." << "\n";
for (i=list.begin(); i!=list.end(); i++) {
delete *i;
}
getStreamer() << "~EmployeeList empty." << "\n";
}
};

View file

@ -0,0 +1,18 @@
/* File : example.i */
%module(directors="1") example
%{
#include "example.h"
%}
%include "std_vector.i"
%include "std_string.i"
/* turn on director wrapping for Manager */
%feature("director") Employee;
%feature("director") Manager;
/* A base class for callbacks from C++ to output text on the Java side */
%feature("director") Streamer;
%include "example.h"

View file

@ -0,0 +1,10 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked in Version Control Systems,
# as it contains information specific to your local configuration.
# location of the SDK. This is only used by Ant
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=/home/william/android/android-sdk-linux_x86

View file

@ -0,0 +1,40 @@
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

View file

@ -0,0 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=android-8

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/RunButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Run..."
android:onClick="onRunButtonClick"
/>
<ScrollView
android:id="@+id/Scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/OutputText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</ScrollView>
</LinearLayout>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">SwigExtend</string>
</resources>

View file

@ -0,0 +1,129 @@
package org.swig.extendexample;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.ScrollView;
import android.text.method.ScrollingMovementMethod;
// CEO class, which overrides Employee::getPosition().
class CEO extends Manager {
public CEO(String name) {
super(name);
}
public String getPosition() {
return "CEO";
}
// Public method to stop the SWIG proxy base class from thinking it owns the underlying C++ memory.
public void disownMemory() {
swigCMemOwn = false;
}
}
public class SwigExtend extends Activity
{
TextView outputText = null;
ScrollView scroller = null;
/** Handles upcalls from C++ so that C++ code can display text on the TextView */
class TextViewStreamer extends Streamer {
public void display(String text) {
outputText.append(text);
}
}
TextViewStreamer textViewStreamer = new TextViewStreamer();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
outputText = (TextView)findViewById(R.id.OutputText);
outputText.setText("Press 'Run' to start...\n");
outputText.setMovementMethod(new ScrollingMovementMethod());
scroller = (ScrollView)findViewById(R.id.Scroller);
example.setStreamer(textViewStreamer);
}
public void onRunButtonClick(View view)
{
outputText.append("Started...\n");
nativeCall();
outputText.append("Finished!\n");
// Ensure scroll to end of text
scroller.post(new Runnable() {
public void run() {
scroller.fullScroll(ScrollView.FOCUS_DOWN);
}
});
}
/** Calls into C/C++ code */
public void nativeCall()
{
// Create an instance of CEO, a class derived from the Java proxy of the
// underlying C++ class. The calls to getName() and getPosition() are standard,
// the call to getTitle() uses the director wrappers to call CEO.getPosition().
CEO e = new CEO("Alice");
outputText.append( e.getName() + " is a " + e.getPosition() + "\n");
outputText.append( "Just call her \"" + e.getTitle() + "\"\n" );
outputText.append( "----------------------\n" );
// Create a new EmployeeList instance. This class does not have a C++
// director wrapper, but can be used freely with other classes that do.
EmployeeList list = new EmployeeList();
// EmployeeList owns its items, so we must surrender ownership of objects we add.
e.disownMemory();
list.addEmployee(e);
outputText.append( "----------------------\n" );
// Now we access the first four items in list (three are C++ objects that
// EmployeeList's constructor adds, the last is our CEO). The virtual
// methods of all these instances are treated the same. For items 0, 1, and
// 2, all methods resolve in C++. For item 3, our CEO, getTitle calls
// getPosition which resolves in Java. The call to getPosition is
// slightly different, however, because of the overridden getPosition() call, since
// now the object reference has been "laundered" by passing through
// EmployeeList as an Employee*. Previously, Java resolved the call
// immediately in CEO, but now Java thinks the object is an instance of
// class Employee. So the call passes through the
// Employee proxy class and on to the C wrappers and C++ director,
// eventually ending up back at the Java CEO implementation of getPosition().
// The call to getTitle() for item 3 runs the C++ Employee::getTitle()
// method, which in turn calls getPosition(). This virtual method call
// passes down through the C++ director class to the Java implementation
// in CEO. All this routing takes place transparently.
outputText.append( "(position, title) for items 0-3:\n" );
outputText.append( " " + list.get_item(0).getPosition() + ", \"" + list.get_item(0).getTitle() + "\"\n" );
outputText.append( " " + list.get_item(1).getPosition() + ", \"" + list.get_item(1).getTitle() + "\"\n" );
outputText.append( " " + list.get_item(2).getPosition() + ", \"" + list.get_item(2).getTitle() + "\"\n" );
outputText.append( " " + list.get_item(3).getPosition() + ", \"" + list.get_item(3).getTitle() + "\"\n" );
outputText.append( "----------------------\n" );
// Time to delete the EmployeeList, which will delete all the Employee*
// items it contains. The last item is our CEO, which gets destroyed as well.
list.delete();
outputText.append( "----------------------\n" );
}
/** static constructor */
static {
System.loadLibrary("example");
}
}

View file

@ -2,28 +2,25 @@ TOP = ../..
SWIG = $(TOP)/../preinst-swig
TARGET = example
INTERFACE = example.i
INTERFACEDIR = jni/
PACKAGEDIR = src/org/swig
PACKAGENAME= org.swig.simple
SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/simple
PROJECTNAME= SwigSimple
TARGETID = 1
#INSTALLOPTIONS = -s # To install on SD Card
all:: android
check: build
android::
android update project --target $(TARGETID) --name $(PROJECTNAME) --path .
$(SWIG) -java $(SWIGOPT) -o jni/$(TARGET)_wrap.c jni/$(INTERFACE)
ndk-build
ant debug
build:
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INTERFACEDIR='$(INTERFACEDIR)' \
PROJECTNAME='$(PROJECTNAME)' TARGETID='$(TARGETID)' android
install::
-adb uninstall $(PACKAGENAME)
adb install bin/$(PROJECTNAME)-debug.apk
install:
$(MAKE) -f $(TOP)/Makefile INSTALLOPTIONS='$(INSTALLOPTIONS)' PROJECTNAME='$(PROJECTNAME)' \
PACKAGEDIR='$(PACKAGEDIR)' PACKAGENAME='$(PACKAGENAME)' android_install
clean::
ant clean
rm -f jni/$(TARGET)_wrap.c
rm -f `find $(PACKAGEDIR) -name \*.java | grep -v $(PROJECTNAME).java`
check: all
clean:
$(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' PROJECTNAME='$(PROJECTNAME)' \
PACKAGEDIR='$(PACKAGEDIR)' INTERFACEDIR='$(INTERFACEDIR)' android_clean

View file

@ -1,38 +1,38 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
INTERFACE = example.i
SRCS =
SRCS =
CXXSRCS = example.cxx
TARGET = class
INCLUDE =
SWIGOPT =
CFLAGS =
CFLAGS =
VARIANT =
# uncomment the following lines to build a static exe (only pick one of the CHICKEN_MAIN lines)
#CHICKEN_MAIN = test-lowlevel-class.scm
#CHICKEN_MAIN = test-tinyclos-class.scm
#CHICKEN_MAIN = runme-lowlevel.scm
#CHICKEN_MAIN = runme-tinyclos.scm
#VARIANT = _static
all:: $(TARGET) $(TARGET)_proxy
check: build
$(MAKE) -f $(TOP)/Makefile CHICKEN_SCRIPT='runme-lowlevel.scm' chicken_run
$(MAKE) -f $(TOP)/Makefile CHICKEN_SCRIPT='runme-tinyclos.scm' chicken_run
build: $(TARGET) $(TARGET)_proxy
$(TARGET): $(INTERFACE) $(SRCS)
$(MAKE) -f $(TOP)/Makefile \
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp
$(TARGET)_proxy: $(INTERFACE) $(SRCS)
$(MAKE) -f $(TOP)/Makefile \
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT) -proxy' TARGET='$(TARGET)_proxy' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT) -proxy' TARGET='$(TARGET)_proxy' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp
clean::
clean:
$(MAKE) -f $(TOP)/Makefile chicken_clean
rm -f example.scm
rm -f $(TARGET)
check::
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-lowlevel-class.scm
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-tinyclos-class.scm

View file

@ -7,11 +7,11 @@ public:
}
virtual ~Shape() {
nshapes--;
};
double x, y;
}
double x, y;
void move(double dx, double dy);
virtual double area(void) = 0;
virtual double perimeter(void) = 0;
virtual double area() = 0;
virtual double perimeter() = 0;
static int nshapes;
enum SomeEnum {
@ -26,21 +26,16 @@ class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { };
virtual double area(void);
virtual double perimeter(void);
Circle(double r) : radius(r) { }
virtual double area();
virtual double perimeter();
};
class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
virtual double area(void);
virtual double perimeter(void);
Square(double w) : width(w) { }
virtual double area();
virtual double perimeter();
};

View file

@ -7,4 +7,3 @@
/* Let's just grab the original header file here */
%include "example.h"

View file

@ -2,29 +2,29 @@ TOP = ../..
SWIG = $(TOP)/../preinst-swig
INTERFACE = example.i
SRCS =
CXXSRCS =
CXXSRCS =
TARGET = constants
INCLUDE =
SWIGOPT =
CFLAGS =
VARIANT =
SWIGOPT =
CFLAGS =
VARIANT =
# uncomment the following two lines to build a static exe
#CHICKEN_MAIN = test-constants.scm
#CHICKEN_MAIN = runme.scm
#VARIANT = _static
all:: $(TARGET)
check: build
$(MAKE) -f $(TOP)/Makefile chicken_run
build: $(TARGET)
$(TARGET): $(INTERFACE) $(SRCS)
$(MAKE) -f $(TOP)/Makefile \
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)
clean::
clean:
$(MAKE) -f $(TOP)/Makefile chicken_clean
rm -f example.scm
rm -f $(TARGET)
check::
csi test-constants.scm

View file

@ -1,6 +1,9 @@
SWIG = ../../../preinst-swig
all: single multi
check: build
cd eggs/install && csi ../../test.scm
build: single multi
# This creates an egg which contains only the single module. Any additional implementation files
# that implement the interface being wrapped should also be added to this egg
@ -9,7 +12,7 @@ single: single_wrap.cxx
tar czf eggs/single.egg single.setup single.scm single_wrap.cxx
rm -f single.scm single_wrap.cxx
# complie the single module with -nounit
# compile the single module with -nounit
single_wrap.cxx: single.i
$(SWIG) -chicken -c++ -proxy -nounit single.i
@ -34,6 +37,3 @@ setup:
mkdir -p install && \
chicken-setup -repository `pwd`/install single.egg && \
chicken-setup -repository `pwd`/install multi.egg
check:
cd eggs/install && csi ../../test.scm

View file

@ -2,29 +2,29 @@ TOP = ../..
SWIG = $(TOP)/../preinst-swig
INTERFACE = example.i
SRCS = example.c
CXXSRCS =
CXXSRCS =
TARGET = multimap
INCLUDE =
SWIGOPT =
CFLAGS =
VARIANT =
SWIGOPT =
CFLAGS =
VARIANT =
# uncomment the following two lines to build a static exe
#CHICKEN_MAIN = test-multimap.scm
#CHICKEN_MAIN = runme.scm
#VARIANT = _static
all:: $(TARGET)
check: build
$(MAKE) -f $(TOP)/Makefile chicken_run
build: $(TARGET)
$(TARGET): $(INTERFACE) $(SRCS)
$(MAKE) -f $(TOP)/Makefile \
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)
clean::
clean:
$(MAKE) -f $(TOP)/Makefile chicken_clean
rm -f example.scm
rm -f $(TARGET)
check::
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-multimap.scm

View file

@ -1,4 +1,3 @@
;; run with './multimap test-multimap.scm'
;; feel free to uncomment and comment sections
(load-library 'example "multimap.so")

View file

@ -1,30 +1,30 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
INTERFACE = example.i
SRCS =
SRCS =
CXXSRCS = example.cxx
TARGET = overload
INCLUDE =
SWIGOPT = -proxy -unhideprimitive
CFLAGS =
VARIANT =
CFLAGS =
VARIANT =
# uncomment the following lines to build a static exe
#CHICKEN_MAIN = test-overload.scm
#CHICKEN_MAIN = runme.scm
#VARIANT = _static
all:: $(TARGET)
check: build
$(MAKE) -f $(TOP)/Makefile chicken_run
build: $(TARGET)
$(TARGET): $(INTERFACE) $(SRCS)
$(MAKE) -f $(TOP)/Makefile \
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp
clean::
clean:
$(MAKE) -f $(TOP)/Makefile chicken_clean
rm -f example.scm
rm -f $(TARGET)
check::
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-overload.scm

View file

@ -2,29 +2,29 @@ TOP = ../..
SWIG = $(TOP)/../preinst-swig
INTERFACE = example.i
SRCS = example.c
CXXSRCS =
CXXSRCS =
TARGET = simple
INCLUDE =
SWIGOPT =
CFLAGS =
VARIANT =
SWIGOPT =
CFLAGS =
VARIANT =
# uncomment the following two lines to build a static exe
#CHICKEN_MAIN = test-simple.scm
#CHICKEN_MAIN = runme.scm
#VARIANT = _static
all:: $(TARGET)
check: build
$(MAKE) -f $(TOP)/Makefile chicken_run
build: $(TARGET)
$(TARGET): $(INTERFACE) $(SRCS)
$(MAKE) -f $(TOP)/Makefile \
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)
SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)
clean::
clean:
$(MAKE) -f $(TOP)/Makefile chicken_clean
rm -f example.scm example-generic.scm example-clos.scm
rm -f $(TARGET)
check::
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-simple.scm

View file

@ -5,16 +5,15 @@ TARGET = example
INTERFACE = example.i
SWIGOPT =
CSHARPSRCS = *.cs
CSHARPFLAGS= -nologo -unsafe -out:runme.exe
CSHARPFLAGS= -nologo -debug+ -unsafe -out:runme.exe
all:: csharp
check: build
$(MAKE) -f $(TOP)/Makefile csharp_run
csharp::
build:
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp
$(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile
clean::
clean:
$(MAKE) -f $(TOP)/Makefile csharp_clean
check: all

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