diff --git a/.gitignore b/.gitignore
index 63fe6ddc9..ce576445d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,8 +3,10 @@
*.class
# Editor files and various other junk
-*.sw?
+.*.sw?
*.bak
+*.log
+.DS_Store
# Local PCRE
pcre
@@ -23,6 +25,7 @@ pcre
*.so
*.so.*
*.dylib
+*.bundle
# C/C++ static libraries, based on:
# https://github.com/github/gitignore/blob/master/C.gitignore
@@ -67,11 +70,11 @@ Examples/Makefile
Examples/guile/Makefile
Examples/test-suite/*/Makefile
Examples/xml/Makefile
-Lib/ocaml/swigp4.ml
/Makefile
Source/Include/stamp-h1
Source/Include/swigconfig.h
Source/Makefile
+Tools/javascript/Makefile
.deps
config.log
config.status
@@ -82,10 +85,14 @@ swig.spec
.dirstamp
CCache/ccache-swig
CCache/ccache-swig.1
+CCache/web/ccache-man.html
+Lib/swigwarn.swg
Source/CParse/parser.c
Source/CParse/parser.h
Source/eswig
+Source/TAGS
swig
+Tools/javascript/javascript
# Generated documentation
Doc/Manual/CCache.html
@@ -103,6 +110,7 @@ Examples/test-suite/d/*/
Examples/test-suite/go/*/
Examples/test-suite/guile/*/
Examples/test-suite/java/*/
+Examples/test-suite/javascript/*/
Examples/test-suite/lua/*/
Examples/test-suite/mzscheme/*/
Examples/test-suite/ocaml/*/
@@ -115,11 +123,19 @@ Examples/test-suite/r/*/
Examples/test-suite/ruby/*/
Examples/test-suite/tcl/*/
Examples/test-suite/uffi/*/
+*_wrap.c
+*_wrap.cxx
+*-gypcopy.cxx
-# SWIG generated files in examples
-Examples/**/*_wrap.c
-Examples/**/*_wrap.cxx
-Examples/**/*_wrap.cpp
+# C# generated files
+*_runme.exe.mdb
+*_runme.exe
+
+# Javascript generated files
+*.gyp
+
+# Octave generated files
+swigexample*.oct
# Python generated files, based on:
# https://github.com/github/gitignore/blob/master/Python.gitignore
@@ -127,10 +143,6 @@ Examples/**/*_wrap.cpp
*/__pycache__/
/__pycache__/
-# C# generated files
-*_runme.exe.mdb
-*_runme.exe
-
# Scilab generated files
builder.sce
loader.sce
@@ -143,3 +155,5 @@ lib*.hxx
# Scratch directories
Examples/scratch
+# Out of source tree build directories
+*build*/
diff --git a/.travis.yml b/.travis.yml
index 61ed1f681..342c3cd47 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,33 +7,117 @@ env:
matrix:
include:
- compiler: gcc
- env: SWIGLANG=python
+ env: SWIGLANG=csharp
+ - compiler: gcc
+ env: SWIGLANG=go
+ - compiler: gcc
+ env: SWIGLANG=guile
+ - compiler: gcc
+ env: SWIGLANG=java
+ - compiler: gcc
+ env: SWIGLANG=javascript ENGINE=node
+ - compiler: gcc
+ env: SWIGLANG=javascript ENGINE=jsc
+ - compiler: gcc
+ env: SWIGLANG=javascript ENGINE=v8
+ - 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
- compiler: gcc
env: SWIGLANG=scilab SWIGJOBS=-j4
allow_failures:
- # None
+ # None
before_install:
- - lsb_release -a
+ - date -u
- uname -a
+ - lsb_release -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" = "javascript" -a "$ENGINE" = "node"; then sudo apt-get install -qq rlwrap python-software-properties && echo 'yes' | sudo add-apt-repository ppa:chris-lea/node.js && sudo apt-get -qq update && sudo apt-get install -qq nodejs && sudo npm install -g node-gyp; fi
+ - if test "$SWIGLANG" = "javascript" -a "$ENGINE" = "jsc"; then sudo apt-get install -qq libwebkitgtk-dev; fi
+ - if test "$SWIGLANG" = "javascript" -a "$ENGINE" = "v8"; then sudo apt-get install -qq libv8-dev; fi
- if test "$SWIGLANG" = "guile"; then sudo apt-get -qq install guile-2.0-dev; fi
- if test "$SWIGLANG" = "lua"; then sudo apt-get -qq install lua5.1 liblua5.1-dev; fi
- if test "$SWIGLANG" = "octave"; then sudo apt-get -qq install octave3.2 octave3.2-headers; fi
- if test "$SWIGLANG" = "scilab"; then sudo apt-get -qq install scilab; fi
- if test "$SWIGLANG" = "php"; then sudo apt-get install php5-cli php5-dev; fi
- - if test "$SWIGLANG" = "python" -a "$PY3"; then sudo apt-get install python3-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
+ # Stricter compile flags for examples. Various headers and SWIG generated code prevents full use of -pedantic.
+ - declare -A CFLAGS_EXAMPLES && CFLAGS_EXAMPLES=(
+ ["csharp"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
+ ["go"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
+ ["guile"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
+ ["java"]="-Werror -std=gnu89 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
+ ["javascript"]="-Werror -std=gnu89 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
+ ["lua"]="-Werror -std=gnu89 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
+ ["octave"]="-Werror -std=gnu89 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
+ ["perl5"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
+ ["php"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
+ ["python"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
+ ["ruby"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
+ ["tcl"]="-Werror -std=gnu89 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
+ )
+ - declare -A CXXFLAGS_EXAMPLES && CXXFLAGS_EXAMPLES=(
+ ["csharp"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
+ ["go"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
+ ["guile"]="-Werror -std=c++98 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
+ ["java"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
+ ["javascript"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
+ ["lua"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
+ ["octave"]="-Werror -std=c++98 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
+ ["perl5"]="-Werror -std=c++98 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
+ ["php"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
+ ["python"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
+ ["ruby"]="-Werror -std=c++98 -fdiagnostics-show-option -pedantic -Wno-long-long -Wreturn-type"
+ ["tcl"]="-Werror -std=c++98 -fdiagnostics-show-option -Wno-long-long -Wreturn-type"
+ )
+ - $CC --version
+ - $CXX --version
script:
- - ./autogen.sh && ./configure
+ - echo 'Configuring...' && echo -en 'travis_fold:start:script.1\\r'
+ - ./autogen.sh && mkdir -p build/build && cd build/build && ../../configure $CONFIGOPTS
+ - echo -en 'travis_fold:end:script.1\\r'
- make -s $SWIGJOBS
- - if test -z "$SWIGLANG"; then make -s check-ccache; fi
- - ./swig -version
+ - ./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
+ - echo 'Installing...' && echo -en 'travis_fold:start:script.2\\r'
+ - if test -z "$SWIGLANG"; then sudo make -s install && swig -version && ccache-swig -V; fi
+ - echo -en 'travis_fold:end:script.2\\r'
- 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-examples CFLAGS="${CFLAGS_EXAMPLES[$SWIGLANG]}" CXXFLAGS="${CXXFLAGS_EXAMPLES[$SWIGLANG]}"; fi
- if test -n "$SWIGLANG"; then make -k $SWIGJOBS check-$SWIGLANG-test-suite; fi
+ - echo 'Cleaning...' && echo -en 'travis_fold:start:script.3\\r'
+ - make check-maintainer-clean && ../../configure $CONFIGOPTS
+ - echo -en 'travis_fold:end:script.3\\r'
branches:
only:
- master
diff --git a/ANNOUNCE b/ANNOUNCE
index 90cc9ba24..58de2fe10 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,8 +1,8 @@
-*** ANNOUNCE: SWIG 3.0.0 (in progress) ***
+*** ANNOUNCE: SWIG 3.0.2 (4 Jun 2014) ***
http://www.swig.org
-We're pleased to announce SWIG-3.0.0, the latest SWIG release.
+We're pleased to announce SWIG-3.0.2, the latest SWIG release.
What is SWIG?
=============
@@ -10,22 +10,22 @@ 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 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,
+PHP, C#, Go, Java, Javascript, 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-3.0.0.tar.gz
+ http://prdownloads.sourceforge.net/swig/swig-3.0.2.tar.gz
A Windows version is also available at
- http://prdownloads.sourceforge.net/swig/swigwin-3.0.0.zip
+ http://prdownloads.sourceforge.net/swig/swigwin-3.0.2.zip
Please report problems with this release to the swig-devel mailing list,
details at http://www.swig.org/mail.html.
diff --git a/CCache/Makefile.in b/CCache/Makefile.in
index d8f9042fe..6cded08d4 100644
--- a/CCache/Makefile.in
+++ b/CCache/Makefile.in
@@ -14,7 +14,7 @@ NOSOFTLINKSTEST=
CC=@CC@
CFLAGS=@CFLAGS@ -I.
SWIG=swig
-SWIG_LIB=../../Lib
+SWIG_LIB=../$(srcdir)/../Lib
EXEEXT=@EXEEXT@
# Use standard autoconf approach to transform executable name using --program-prefix and --program-suffix
@@ -27,38 +27,40 @@ HEADERS = ccache.h mdfour.h
all: $(PACKAGE_NAME)$(EXEEXT)
+# Regenerate Makefile if Makefile.in or config.status have changed.
+Makefile: $(srcdir)/Makefile.in ./config.status
+ $(SHELL) ./config.status
+
# Note that HTML documentation is actually generated and used from the main SWIG documentation Makefile
-docs: $(PACKAGE_NAME).1 web/ccache-man.html
+docs: $(srcdir)/$(PACKAGE_NAME).1 $(srcdir)/web/ccache-man.html
$(PACKAGE_NAME)$(EXEEXT): $(OBJS) $(HEADERS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
-$(PACKAGE_NAME).1: ccache.yo
- -yodl2man -o $(PACKAGE_NAME).1 ccache.yo
+$(srcdir)/$(PACKAGE_NAME).1: $(srcdir)/ccache.yo
+ -yodl2man -o $(srcdir)/$(PACKAGE_NAME).1 $(srcdir)/ccache.yo
-web/ccache-man.html: ccache.yo
- yodl2html -o web/ccache-man.html ccache.yo
+$(srcdir)/web/ccache-man.html: $(srcdir)/ccache.yo
+ yodl2html -o $(srcdir)/web/ccache-man.html $(srcdir)/ccache.yo
-install: $(PACKAGE_NAME)$(EXEEXT) $(PACKAGE_NAME).1
+install: $(PACKAGE_NAME)$(EXEEXT) $(srcdir)/$(PACKAGE_NAME).1
@echo "Installing $(PACKAGE_NAME)"
@echo "Installing $(DESTDIR)${bindir}/`echo $(PACKAGE_NAME) | sed '$(transform)'`$(EXEEXT)"
${INSTALLCMD} -d $(DESTDIR)${bindir}
${INSTALLCMD} -m 755 $(PACKAGE_NAME)$(EXEEXT) $(DESTDIR)${bindir}/`echo $(PACKAGE_NAME) | sed '$(transform)'`$(EXEEXT)
@echo "Installing $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1"
${INSTALLCMD} -d $(DESTDIR)${mandir}/man1
- ${INSTALLCMD} -m 644 ${srcdir}/$(PACKAGE_NAME).1 $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1
+ ${INSTALLCMD} -m 644 $(srcdir)/$(PACKAGE_NAME).1 $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1
-uninstall: $(PACKAGE_NAME)$(EXEEXT) $(PACKAGE_NAME).1
+uninstall: $(PACKAGE_NAME)$(EXEEXT) $(srcdir)/$(PACKAGE_NAME).1
rm -f $(DESTDIR)${bindir}/`echo $(PACKAGE_NAME) | sed '$(transform)'`$(EXEEXT)
rm -f $(DESTDIR)${mandir}/man1/`echo $(PACKAGE_NAME) | sed '$(transform)'`.1
clean:
/bin/rm -f $(OBJS) *~ $(PACKAGE_NAME)$(EXEEXT)
-check : test
-
test: test.sh
- SWIG_LIB='$(SWIG_LIB)' PATH=../..:$$PATH SWIG='$(SWIG)' CC='$(CC)' NOSOFTLINKSTEST='$(NOSOFTLINKSTEST)' ./test.sh
+ SWIG_LIB='$(SWIG_LIB)' PATH=../..:$$PATH SWIG='$(SWIG)' CC='$(CC)' NOSOFTLINKSTEST='$(NOSOFTLINKSTEST)' $(srcdir)/test.sh
check: test
@@ -67,11 +69,11 @@ distclean: clean
/bin/rm -rf autom4te.cache
maintainer-clean: distclean
- /bin/rm -f $(PACKAGE_NAME).1 web/ccache-man.html
+ /bin/rm -f $(srcdir)/$(PACKAGE_NAME).1 $(srcdir)/web/ccache-man.html
+
-
# FIXME: To fix this, test.sh needs to be able to take ccache from the
# installed prefix, not from the source dir.
-installcheck:
+installcheck:
@echo "WARNING! This is not really \"installcheck\" yet."
$(MAKE) check
diff --git a/CHANGES b/CHANGES
index 4cc222901..1cfedc31e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,513 @@ SWIG (Simplified Wrapper and Interface Generator)
See the CHANGES.current file for changes in the current version.
See the RELEASENOTES file for a summary of changes in each release.
+Version 3.0.1 (27 May 2014)
+===========================
+
+2014-05-25: hfalcic
+ [Python] Python 3 byte string output: use errors="surrogateescape"
+ if available on the version of Python that's in use. This allows
+ obtaining the original byte string (and potentially trying a fallback
+ encoding) if the bytes can't be decoded as UTF-8.
+
+ Previously, a UnicodeDecodeError would be raised with no way to treat
+ the data as bytes or try another codec.
+
+2014-05-18: vkalinin
+ Bug #175 - Restore %extend to work for unnamed nested structures by using a C
+ symbol comprising the outer structure name and unnamed variable instance name.
+
+2014-05-15: kwwette
+ Add #166 - 'make check' now works out of source. This required te examples to build
+ out of source. The main languages have been tested - C#, Go, Guile, Java, Javascript,
+ Lua, Octave, Perl, PHP, Python, Ruby and Tcl.
+
+2014-05-01: Oliver Buchtala
+ Javascript support added, see Javascript chapter in the documentation.
+
+2014-05-01: olly
+ [PHP] The generated __isset() method now returns true for read-only properties.
+
+2014-04-24: kwwette
+ [Go] Fix go ./configure parsing of gccgo --version, and
+ goruntime.swg typo in __GNUC_PATCHLEVEL__ (SF Bug #1298)
+
+2014-04-24: kwwette
+ Fix {python|perl5|ruby|tcl}/java examples
+
+ In Lib/gcj/cni.i, for compatibility with newer gcj versions:
+
+ - remove JvAllocObject() which gcj no longer defines, from gcj Changelog:
+ 2004-04-16 Bryce McKinlay 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. branches/gsoc2009-matevz Wikipedia article: http://en.wikipedia.org/wiki/C%2B%2B0x
+ The Rvalues are used in practice to speed up the move operations
+on different containers. In the following example, we want to swap the given elements:
+This can now be solved using the new function std::move():
+For the move function to take effect, user needs to reimplement the
+move constructor (taking ClassType&& as an argument) and
+operator=(ClassType&&):
+In practice, the Rvalues are used for temporaries (when passing the
+result of one function as an argument to another). Done: Added type&& to Swig parser. Added testcase
+cpp11_rvalue_reference.i. Operator && is treated the same as
+operator &. R11450 Article:
+http://www.artima.com/cppsource/rvalue.html In C++11 you can define functions as constant expressions.
+Functions need to return constant value in form "return expr",
+where expr is a constant expression.
+ A keyword "constexpr" is introduced for this. eg.:
+constexpr int getNumber() { return 5; } const int MY_CONSTANT =
+getNumber();
+ Constants are treated as normal variables in interpreted languages
+because they are not compiled into the executable. Java "final"
+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.
+ Done: Added the “constexpr “ keyword to Swig. Added testcase
+cpp11_constexpr. R11322 Problem: No compilers were known to support constexpr yet, so the
+testcase was temporarily commented out in common.mk.
+ 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.
+ Done: Added support for 'extern template class
+std::vector<MyClass>;'. Added testcase cpp11_template_explicit.
+R11385 , R11386 Initializer list is a new type in standard library:
+std::initializer_list<T>. New symbols {} are introduced for the
+initializer lists.
+ One can now use:
+
+Languages like Java, C# and Python already support direct creation of
+lists natively. 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. Done: Ignored the constructor having initializer_list as its
+argument. Show warning to the user. Added testcase
+cpp11_initializer_list. R11450 Article:
+http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1919.pdf The new C++11 standard will allow the following:
+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:
+The new way of using uniform initialization allows the following:
+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). Done: Added syntax for {} member initialization in class
+constructor. Added testcase cpp11_uniform_initialization. R11413 A new keyword 'auto' is introduced in C++11:
+The type of a1 and a2 is automatically determined according to the
+initialization value during the semantic phase of the compiler. Another macro 'decltype()' is introduced. The macro takes the
+concrete object as an argument and returns its type. User could use
+this as:
+Calling operators are allowed as well:
+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 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. This feature is always present inside the implementation block
+only.
+ C++11 introduces lambda functions defined as:
+If the lambda function contains a single return statement only or the
+function doesn't return any type, the return type '->' can be
+omitted. Lambda functions are function objects. The following example prints the number of items stored in a list:
+Parameters inside the [] are the visible parameters of the lambda
+functions. These can be & (references), = (copies), variable name
+(variable copy), &variable name (variable reference) or this
+(copy of the current object). Lambda functions can be stored using:
+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. Article:
+http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2550.pdf Done: Added syntax support for the lambda functions. Added
+testcase cpp11_lambda_functions.i. R11491, R11492 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:
+The solution C++11 offers is the combination of the 'auto' keyword
+before and '-> rettype' after the function declaration:
+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:
+Done: Added support for the 'auto' return type. Added support for the
+'-> type' after the funtion declaration. Added testcases
+cpp11_alternate_function_syntax.i and
+cpp11_alternate_function_syntax_runme.py. R11414 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 "concepts". 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.
+ Basic syntax (note LessThanComparable?
+instead of "class" or "typename"):
+
+Extended syntax (requires conditions are separated with &&,
+|| or !):
+
+Definition of the concepts:
+
+Concept maps allow usage of a specific type:
+
+Concept maps can act as mini-types, with function definitions and
+other constructs commonly associated with classes:
+
+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:
+
+Axioms are more like hints to the compiler to speed-up the process of
+compilation.
+ Ignored: Concepts and axioms were removed from the C++11 standard.
+ This feature allows classes constructors to call other
+constructors with different arguments (similar to Java and C#
+behaviour).
+ The syntax is as follows:
+
+Also when using the inheritance, the feature introduces inheritance
+of all superclass constructors without being defined separately in
+the inherited class:
+
+Swig already correctly parses and produces the correct wrapper for
+the “using” keyword. Done: Added testcase cpp11_constructors.i which covers both
+constructor delegation and constructor inheritance. R11532 Problem: Constructor delegation and constructor inheritance is not
+supported by any compiler yet, so it's impossible to try and test
+this feature. nullptr is part of the standard library.
+ It's defined as typedef decltype(nullptr) nullptr_t;
+ nullptr_t is defined in <cstddef>.
+ 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. Done: Written a testcase cpp11_null_pointer_constant.i and
+cpp11_null_pointer_constant_runme.py to prove the nullptr
+functionality. R11484 C++11 introduces a new syntax for strongly typed enum declaration:
+
+Typing if (Val4 == 101) will result in compilation error.
+ The enum itself can now be explicitely of type int, long, unsigned
+int etc.:
+
+And it can be forward declared as well:
+
+Done: Added syntax 'enum class Name' and forward declarators 'enum
+Name : inherited type' or 'enum class Name : inherited type' in
+R11449. TODO: Add semantic support for enum elements not clashing with
+enum elements in other enum classes. See cpp11_strongly_typed_enums.i
+warnings. 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:
+should be mapped to Support for right angled brackets was implemented using the
+following article as a base:
+http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1757.html
+ Done: Added support for angle brackets. Used the preferred
+"Approach 1". Added a testcase named
+cpp11_template_double_brackets. R11245 This is used when converting one type to another (eg. if
+(myObject) {}, where myObject is your custom class converted to
+bool).
+ Requires both operator and function overloading which is not
+supported in any target language (eg. python, php).
+ Done: Swig already supports the keyword "explicit" for
+function types as well. Added test case
+cpp11_explicit_conversion_operators. R11323 The new C++11 will allow creation of wrapper around the template.
+For example, if we want to do this:
+This is still illegal! But we can now use the new syntax for
+achieving the same effect:
+Here we created a new wrapper TypedefName taking one template
+argument <second> which creates a type SomeType<OtherType,
+second, 5>. OtherType and 5 are predefined here and hidden from
+the user – the user only uses TypedefName type. The same goes for the following example:
+Swig supports parsing typedefs for templates as well for example:
+Done: Expanded support for the new 'using' syntax and template
+aliasing. Added testcase cpp11_template_typedefs. R11533 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. 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:
+Swig already parses the given syntax. Done: Added testcase cpp11_unrestricted_unions. R11435, R11447 Problem: GCC doesn't support unrestricted unions yet so there is
+no way to actually test, if it works. The new C++11 offers the following syntax:
+This can be used for example:
+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:
+The tricky part is that variadic templates can unpack actually
+anywhere – including the class inheritance :(
+A new extension to sizeof is also introduced with this feature. The
+... after sizeof returns number of arguments:
+Done: Added syntax support for 'typename' or 'class' + ... + id.
+Added testcase cpp11_variadic_templates. R11458 Done: Added syntax support for BaseClass + ..., type + ... + id in
+parameters and baseclass + ... for intializers after constructor.
+Extended Swig syntax to support sizeof...(Args). R11467 Done: Fixed %template to support variadic number of templates. TODO: Only (if present) first variadically defined argument is
+currently used in %template directive. The next ones are ignored. Beside the implementation, the new C++11 Unicode and custom
+delimeter constants can occur in templates in the header file.
+ Done: Added symbols 'u', 'u8' and 'U' to mark the beginning of the
+UTF string. Also added test case cpp11_raw_string_literals. R11327 Done: Added R"DELIMITER[, ]DELIMITER" for a custom
+delimiter for the beginning/end of the string. R11328 TODO: Fix the Swig's C++ preprocessor bug when parsing an odd
+number of “ inside the string brackets. See
+Source/Preprocessor/cpp.c. C++ has different suffix literals. eg. 12.5f marks the number 12.5
+as float.
+ C++11 allows user to define his own suffix for the strings always
+starting with the underscore (_). eg. int a = "hello"_mySuffix;
+ The syntax is similar to other operator overloading functions:
+
+The null terminated const char* is the string between the "".
+The _mySuffix is the name of the suffix operator. And the OutputType
+is the outputType the operator returns.
+ Other forms are:
+
+Another possibility is to use variadic templates:
+
+This instantiates the literal processing function as
+operator""_Suffix<'1', '2', '3', '4'>. 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. Article:
+http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2765.pdf Done: Added syntax support for userdefined literals. Added
+testcase cpp11_userdefined_literals.i. R11494 TODO: %rename doesn't parse operator”” yet. New C++11 introduces keyword "thread_local" which marks
+the following variable dynamically located depending on the current
+thread when using the address-of (&) operator.
+ Syntax:
+
+Done: Add "thread_local" keyword to Swig. Added testcase
+cpp11_thread_local. R11393 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).
+ Words "default" and "delete" are introduced.
+The syntax is similar to declaration of pure virtual function:
+
+User has the ability by using keyword delete to disallow calling of
+the standard functions brought by C++ itself.
+
+Ignored: Swig already parses the keywords "= delete" and "=
+default". These keywords are used for built-in functions (copy
+constructor, operator= etc.), which are ignored by Swig anyway. Done: Added testcase cpp11_default_delete. R11535 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.
+ Done: Swig already parses the C code including the long long type.
+ static_assert() can be used at class scope as well eg.:
+
+Done: Added syntax support for "static_assert()". Added
+test case cpp11_static_assert. R11369 C++11 allows calls of sizeof to concrete objects as well:
+
+This kind of syntax is already supported by Swig. Done: Added testcase cpp11_sizeof_objects. R11538
+ C++11 will add the following classes to the standard library:
+
+Ignored: No changes to the language itself is made.
+ Tuple is array of various types. C++11 introduced this feature
+using variadic templates. Tuple is defined as:
+Constructor is automatically generated filling the tuple elements.
+get<X> function is introduced to get the Xth element in the
+tuple.
+Tuples can be copied to each other, if all the elements are copiable:
+TODO: Implement wrappers for the tuplet<> class. C++11 introduces the "unordered" version of existing
+types, which in practice work faster than the linear types:
+
+Swig should use the "unordered" types exactly the same as
+the original linear types. 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. TODO: Implement wrappers for unordered_ types. Initial work is
+already done in Lib/std/unordered_*.i files. Two new classes are introduced in C++11: basic_regex and
+match_results. Both are defined in regex header file.
+ Ignored: The new feature extends the standardy library only. No
+changes to Swig needed.
+ This feature deprecates auto_ptr and adds shared_ptr, weak_ptr and
+unique_ptr to the standard library.
+ This feature only adds the smart pointers to the standard library
+and doesn't effect the C++ syntax. Done: Added test case which uses all three smart pointers in the
+class. R11394 Problem: GCC standard library doesn't contain the new smart
+pointers yet.
+ 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.
+ Ignored: The new feature extends the standardy library only. No
+changes to Swig needed.
+ This feature adds ref and cref classes to the standard library
+(#include <utility>) usually used in tempalte functions.
+ Ignored: The new feature extends the standardy library only. No
+changes to Swig needed.
+ Two features are introduced:
+ The function template wrapper:
+ and the function object:
+
+Swig already supports the two. Done: Added a runtime testcase for function objects
+cpp11_function_objects. R11419. C++11 adds a new header file <type_traits> which includes
+helper functions to determine the template type while initializing
+the object at compile time.
+ Swig already supports the following code:
+
+Functions is_convertible, is_integral, is_integral_const etc. are
+part of the new header:
+
+Swig correctly parses the syntax for template<bool>,
+template<class T> and template<>.
+ Ignored: Swig requires explicitly defined template class
+(%template directive) to export it to the target language. The template function is introduced: std::result_of() which
+depends on decltype:
+
+Swig correctly parses the result_of class. TODO: The return type (the result_of::type member) is not
+calculated by Swig. This needs a much more complex semantic parser. Done: Added testcase cpp11_result_of. R11534
@@ -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.
@@ -396,7 +396,7 @@ See Section 17.5 Identifier converter
functions for more details.
@@ -436,7 +436,7 @@ Note that the block %{ ... %} is effectively a shortcut for
@@ -446,7 +446,7 @@ New users to SWIG are encouraged to read
interested in generating an interface to C++.
@@ -499,7 +499,7 @@ interested in generating an interface to C++.
@@ -512,7 +512,7 @@ interested in generating an interface to C++.
typemap.
@@ -593,7 +593,7 @@ char *xxx();
ff:def-foreign-call's.
@@ -606,7 +606,7 @@ char *xxx();
this function can be manipulated via the lout typemap.
@@ -622,7 +622,7 @@ char *xxx();
can be manipulated via the lout typemap.
@@ -635,7 +635,7 @@ char *xxx();
into the foreign module.
@@ -657,7 +657,7 @@ char *xxx();
foreign function interface.
@@ -665,7 +665,7 @@ char *xxx();
translated into lisp.
@@ -742,13 +742,13 @@ namespace car {
function such as (car '(1 2 3).
Constants, as declared by the preprocessor #define macro or SWIG
- %constant directive, are included in SWIGs parse tree
+ %constant 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 -nocwrap command-line option.
@@ -881,13 +881,13 @@ globalvar> (globalvar.nnn::glob_float)
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 typemaps.
@@ -901,7 +901,7 @@ globalvar> (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.
For example, the following header file
@@ -957,7 +957,7 @@ EXPORT const int ACL_ENUM___FOO3__SWIG_0 = FOO3;
-
@@ -1105,10 +1105,10 @@ namespace BAR {
-
@@ -1123,7 +1123,7 @@ namespace BAR {
integer values.
@@ -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.
@@ -1152,7 +1152,7 @@ namespace BAR {
the interface does nothing for friend directives,
@@ -1170,11 +1170,11 @@ namespace BAR {
use the more robust wrapper functions.
@@ -1187,7 +1187,7 @@ namespace BAR {
directive.
@@ -1197,7 +1197,7 @@ namespace BAR {
class schema.
@@ -1277,7 +1277,7 @@ synonym>
-
@@ -1298,7 +1298,7 @@ synonym>
@@ -1461,7 +1461,7 @@ overload>
-
@@ -1607,7 +1607,7 @@ opoverload>
-
@@ -1617,7 +1617,7 @@ opoverload>
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 printf(). It's declaration would
+ consider the function printf(). Its declaration would
appear as follows:
C++0x/C++11 support for SWIG
+Summary
+SVN branch
+New C++11 features status
+Rvalue reference and move semantics [done]
+template <class T> swap(T& a, T& 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)
+}template <class T> swap(T& a, T& b) {
+ T tmp(std::move(a));
+ a = std::move(b);
+ b = std::move(tmp);
+}class MyClass {
+ MyClass(MyClass&& p) : ptr(p.ptr) {p.ptr = 0;}
+ MyClass& operator=(MyClass&& p) {
+ std::swap(ptr, p.ptr);
+ return *this;
+ }
+};Generalized constant expressions [done]
+Extern template [done]
+Initializer lists [done]
+ class A {
+ public:
+ A( std::initializer_list<int> );
+ };
+ A a1 = {1,2,3,4};Uniform initialization [done]
+struct IdString {
+ std::string name;
+ int identifier;
+};
+
+IdString GetString() {
+ return {"SomeName", 4}; //Note the lack of explicit type.
+}IdString str1 = {„SomeName“, 4};
+IdString str2{„SomeName“, 4};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 constructorType inference [partially done]
+auto a1 = 100;
+auto a2 = myFunc();
int i = 100;
+decltype(i) j = 200; // decltype(i) = int
decltype(i+j) k = 300;
Range-based for-loop [ignored]
+Lambda functions and expressions [done]
+[](int x, int y) -> int { return x + y; }std::vector<int> someList;
+int total = 0;
+std::for_each( someList.begin(), someList.end(), [&total](int x) {total += x} );
+std::cout << total;auto myLambdaFunc = [this]() { this->SomePrivateMemberFunction() };Alternate function syntax [done]
+template< typename LHS, typename RHS>
+ decltype(lhs+rhs) AddingFunc(const LHS &lhs, const RHS &rhs) {return lhs + rhs;} //Not legal C++11template< typename LHS, typename RHS>
+ auto AddingFunc(const LHS &lhs, const RHS &rhs) -> decltype(lhs+rhs) {return lhs + rhs;}struct SomeStruct {
+ auto FuncName(int x, int y) -> int;
+};
+
+auto SomeStruct::FuncName(int x, int y) -> int {
+ return x + y;
+}Concepts, Axioms [ignored]
+ template<LessThanComparable? T>
+ const T& min(const T &x, const T &y) {
+ return y < x ? y : x;
+ }
template< typename T> requires LessThanComparable?<T>
+ const T& min(const T &x, const T &y) {
+ return y < x ? y : x;
+ }
concept LessThanComparable?< typename T > {
+ bool operator<(T,T);
+ requires GreaterThanComparable?<T>;
+ typename value_type;
+ typename reference;
+ };
template< typename T>
+ concept_map InputIterator?<T*> {
+ typedef T value_type ;
+ typedef T& reference ;
+ typedef T* pointer ;
+ typedef std::ptrdiff_t difference_type ;
+ };
concept Stack< typename X> {
+ typename value_type;
+ void push(X&, const value_type&);
+ void pop(X&);
+ value_type top(const X&);
+ bool empty(const X&);
+ };
+ template< typename T>
+ concept_map Stack<std::vector<T> > {
+ typedef T value_type;
+ void push(std::vector<T>& v, const T& x) { v.push_back(x); }
+ void pop(std::vector<T>& v) { v.pop_back(); }
+ T top(const std::vector<T>& v) { return v.back(); }
+ bool empty(const std::vector<T>& v) { return v.empty(); }
+ }; concept Semigroup< typename Op, typename T> : CopyConstructible?<T> {
+ 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);
+ }
+ };
Object construction improvement [done]
+ class SomeType {
+ int number;
+ public:
+ SomeType(int newNumber) : number(newNumber) {}
+ SomeType() : SomeType(42) {}
+ }; class BaseClass {
+ public:
+ BaseClass(int iValue);
+ };
+ class DerivedClass: public BaseClass {
+ public:
+ using BaseClass::BaseClass; // Adds DerivedClass(int) constructor
+ };Null pointer constant [done]
+Strongly typed enumerations [partially done]
+ enum class Enumeration {
+ Val1,
+ Val2,
+ Val3 = 100,
+ Val4 /* = 101 */
+ }; enum class Enum2 : unsigned int {Val1, Val2}; 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 "int".
+ 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.
class A { enum class EA { a,b,c,d }; };class A { class EA { enum {a,b,c,d}; }; };
+Angle bracket [done]
+Explicit conversion operators [done]
+Template typedefs [partially done]
+template< typename first, typename second, int third>
+class SomeType;
+
+template< typename second>
+typedef SomeType<OtherType, second, 5> TypedefName; //Illegal in C++
template< typename first, typename second, int third>
+class SomeType;
+
+template< typename second>
+using TypedefName = SomeType<OtherType, second, 5>;
typedef void (*PFD)(double); // Old style
+using PF = void (*)(double); // New introduced syntax
typedef List<int> intList;
Unrestricted unions [done]
+ 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;Variadic templates [partially done]
+template<typename... Values> class tuple;
class tuple<int, std::vector<int>, std::map<std::string, std::vector<int>>> someInstanceName;
void printf(const char *s) {
+ while (*s) {
+ if (*s == '%' && *(++s) != '%')
+ throw std::runtime_error("invalid format string: missing arguments");
+ std::cout << *s++;
+ }
+}
+
+template<typename T, typename... Args>
+void printf(const char* s, T value, Args... args) { // recursive action – split previous args to value + args
+ while (*s) {
+ if (*s == '%' && *(++s) != '%') {
+ std::cout << value;
+ printf(*s ? ++s : s, args...); // call even when *s == 0 to detect extra arguments
+ return;
+ }
+ std::cout << *s++;
+ }
+ throw std::logic_error("extra arguments provided to printf");
+}template <typename... BaseClasses> class ClassName : public BaseClasses... {
+public:
+
+ ClassName (BaseClasses&&... baseClasses) : BaseClasses(baseClasses)... {}
+}template<typename ...Args> struct SomeStruct {
+ static const int size = sizeof...(Args);
+}
+// SomeStruct<Type1, Type2>::size is 2 and SomeStruct<>::size is 0New string literals [partially done]
+User-defined literals [partially done]
+ OutputType operator "" _mySuffix(const char * string_values);
OutputType operator "" _mySuffix(const char * string_values, size_t num_chars);
+ OutputType operator "" _mySuffix(const wchar_t * string_values, size_t num_chars);
+ OutputType operator "" _mySuffix(const char16_t * string_values, size_t num_chars);
+ OutputType operator "" _mySuffix(const char32_t * string_values, size_t num_chars);
+ OutputType operator "" _mySuffix(int value); /* cooked version - ie. atoi() of string */
template<char...> OutputType operator "" _mySuffix();
+ OutputType someVariable = "1234"_mySuffix;
Thread-local storage [done]
+
+ struct A {
+ thread_local int val;
+ };Defaulting/deleting of standard functions on C++ objects [done]
+ struct NonCopyable {
+ NonCopyable & operator=(const NonCopyable&) = delete; /* Removes operator= */
+ NonCopyable(const NonCopyable&) = delete; /* Removed copy constructor */
+ NonCopyable() = default; /* Explicitly allows the empty constructor */
+ void *operator new(std::size_t) = delete; /* Removes new NonCopyable */
+ }; 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<class T> void f(T) = delete; /* Only accept int */
+ };Type long long int [done]
+Static assertions [done]
+ template <typename T>
+ struct Check {
+ static_assert(sizeof(int) <= sizeof(T), "not big enough");
+ };Allow sizeof to work on members of classes without an explicit
+object [done]
+ struct A { int member; };
+ sizeof(A::member); //Does not work with C++03. Okay with C++11Threading facilities [ignored]
+ * std::thread
+ * std::mutex, std::recursive_mutex
+ * std::condition_variable, std::condition_variable_any
+ * std::lock_guard, std::unique_lock
+ * std::packaged_task
Tuple types [TODO]
+template <class ...Types> class tuple;
typedef tuple< int, double, long &, const char * > test_tuple ;
+long lengthy = 12 ;
+test_tuple proof( 18, 6.5, lengthy, "Ciao!" ) ;
+lengthy = get<0>(proof) ; // Assign to 'lengthy' the value 18.
+get<3>(proof) = " Beautiful!" ; // Modify the tuple’s fourth element.
typedef tuple< int , double, string > tuple_1 t1 ;
+typedef tuple< char, short , const char * > tuple_2 t2( 'X', 2, "Hola!" ) ;
+t1 = t2 ; // Ok, first two elements can be converted,
+ // the third one can be constructed from a 'const char *'.
Hash tables [TODO]
+ - unordered set
+ - unordered multiset
+ - unordered map
+ - unordered multimap
Regular expressions [ignored]
+General-purpose smart pointers [done]
+Extensible random number facility [ignored]
+Wrapper reference [ignored]
+Polymorphous wrappers for function objects [done]
+
+
+ function<int ( int, int )> pF;
+
+
+ struct Test {
+ bool operator()( short x, short y );
+ };Type traits for metaprogramming [ignored]
+ template< int B, int N >
+ struct Pow {
+ // recursive call and recombination.
+ enum{ value = B*Pow< B, N-1 >::value };
+ };
+ template< int B > struct Pow< B, 0 > // N == 0 condition of termination.
+ {
+ enum{ value = 1 };
+ };
+ int quartic_of_three = Pow< 3, 4 >::value ;// First way of operating.
+template< bool B > struct algorithm {
+ template< class T1, class T2 > int do_it( T1 &, T2 & ) { /*...*/ }
+};
+// Second way of operating.
+template<> struct algorithm<true> {
+ template< class T1, class T2 > int do_it( T1, T2 ) { /*...*/ }
+};
+// Instantiating 'elaborate' will automatically instantiate the correct way to operate.
+template< class T1, class T2 > 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< is_integral<T1>::value && is_floating_point<T2>::value >::do_it( A, B );
+}Uniform method for computing return type of function objects
+[partially done]
+template< class Obj >
+class calculus_ver2 {
+ public:
+ template< class Arg >
+ typename std::result_of<Obj(Arg)>::type operator()( Arg& a ) const {
+ return member(a);
+ }
+ private:
+ Obj member;
+};
@@ -844,7 +844,7 @@ Returns a type object corresponding to the type string produced by the Swig_cloc
This function is the inverse of the clocal() function. Given a type and a name,
it produces a string containing the code needed to cast/convert the type produced by
-Swig_clocal() back into it's original type.
+Swig_clocal() back into its original type.
diff --git a/Doc/Devel/tree.html b/Doc/Devel/tree.html
index db3c6fee4..73a49ed55 100644
--- a/Doc/Devel/tree.html
+++ b/Doc/Devel/tree.html
@@ -185,7 +185,7 @@ this function merely records that those attributes did not exist in the original
This function is similar to Swig_save() 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 Swig_save(). Here is an example:
diff --git a/Doc/Manual/Allegrocl.html b/Doc/Manual/Allegrocl.html
index 12b915ee2..8295bad1c 100644
--- a/Doc/Manual/Allegrocl.html
+++ b/Doc/Manual/Allegrocl.html
@@ -8,7 +8,7 @@
-
-17 SWIG and Allegro Common Lisp
+18 SWIG and Allegro Common Lisp
@@ -135,10 +135,10 @@ be unhappy to see some enterprising folk use this work to add
to it.
-
17.1 Basics
+18.1 Basics
-17.1.1 Running SWIG
+18.1.1 Running SWIG
17.1.2 Command Line Options
+18.1.2 Command Line Options
17.1.3 Inserting user code into generated files
+18.1.3 Inserting user code into generated files
17.2 Wrapping Overview
+18.2 Wrapping Overview
17.2.1 Function Wrapping
+18.2.1 Function Wrapping
17.2.2 Foreign Wrappers
+18.2.2 Foreign Wrappers
17.2.3 FFI Wrappers
+18.2.3 FFI Wrappers
17.2.4 Non-overloaded Defuns
+18.2.4 Non-overloaded Defuns
17.2.5 Overloaded Defuns
+18.2.5 Overloaded Defuns
17.2.6 What about constant and variable access?
+18.2.6 What about constant and variable access?
17.2.7 Object Wrapping
+18.2.7 Object Wrapping
17.3 Wrapping Details
+18.3 Wrapping Details
17.3.1 Namespaces
+18.3.1 Namespaces
17.3.2 Constants
+18.3.2 Constants
17.3.3 Variables
+18.3.3 Variables
17.3.4 Enumerations
+18.3.4 Enumerations
17.3.5 Arrays
+18.3.5 Arrays
17.3.6 Classes and Structs and Unions (oh my!)
+18.3.6 Classes and Structs and Unions (oh my!)
-17.3.6.1 CLOS wrapping of
+18.3.6.1 CLOS wrapping of
17.3.6.2 CLOS Inheritance
+18.3.6.2 CLOS Inheritance
17.3.6.3 Member fields and functions
+18.3.6.3 Member fields and functions
17.3.6.4 Why not directly access C++ classes using foreign types?
+18.3.6.4 Why not directly access C++ classes using foreign types?
17.3.7 Templates
+18.3.7 Templates
-17.3.7.1 Generating wrapper code for templates
+18.3.7.1 Generating wrapper code for templates
17.3.7.2 Implicit Template instantiation
+18.3.7.2 Implicit Template instantiation
17.3.8 Typedef, Templates, and Synonym Types
+18.3.8 Typedef, Templates, and Synonym Types
17.3.8.1 Choosing a primary type
+18.3.8.1 Choosing a primary type
17.3.9 Function overloading/Parameter defaulting
+18.3.9 Function overloading/Parameter defaulting
17.3.10 Operator wrapping and Operator overloading
+18.3.10 Operator wrapping and Operator overloading
17.3.11 Varargs
+18.3.11 Varargs
@@ -1640,7 +1640,7 @@ opoverload> implemented.
-@@ -1652,7 +1652,7 @@ opoverload> newly defined types.
-@@ -1663,7 +1663,7 @@ opoverload> on Typemaps for more information.
-@@ -1728,14 +1728,14 @@ return-val wrapper-name(parm0, parm1, ..., parmN) -
The out 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 <convert and bind result to lresult> - 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:
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:
@@ -1784,7 +1784,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) these common typemaps here. -@@ -1803,7 +1803,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) 16.3.1 Namespaces for details.
-@@ -1846,7 +1846,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) -
@@ -1889,7 +1889,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) -
@@ -1959,7 +1959,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) -
@@ -1983,7 +1983,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) -
@@ -2017,10 +2017,10 @@ return-val wrapper-name(parm0, parm1, ..., parmN) -
@@ -2041,11 +2041,11 @@ return-val wrapper-name(parm0, parm1, ..., parmN) of arguments.
-Two basic identifier routines have been defined. -
@@ -2054,7 +2054,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) strings, from which a symbol will be created.
-@@ -2063,7 +2063,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) same symbol transformations.
-@@ -2072,7 +2072,7 @@ return-val wrapper-name(parm0, parm1, ..., parmN) default naming conventions.
-@@ -2093,7 +2093,7 @@ foreign environment.
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.
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.
-diff --git a/Doc/Manual/Android.html b/Doc/Manual/Android.html index 4d1be3944..e62139797 100644 --- a/Doc/Manual/Android.html +++ b/Doc/Manual/Android.html @@ -5,7 +5,7 @@
-@@ -40,10 +40,10 @@ Everything in the Java chapter applies to generating cod This chapter contains a few Android specific notes and examples.
-@@ -76,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.
-@@ -398,7 +398,7 @@ Run the app again and this time you will see the output pictured below, showing

@@ -435,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; }; @@ -447,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(); };

@@ -758,7 +758,7 @@ 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.
-diff --git a/Doc/Manual/Arguments.html b/Doc/Manual/Arguments.html index 1ae9a6d2f..3b7713686 100644 --- a/Doc/Manual/Arguments.html +++ b/Doc/Manual/Arguments.html @@ -6,7 +6,7 @@
-@@ -50,7 +50,7 @@ This section describes the typemaps.i library file--commonly used to change certain properties of argument conversion.
-@@ -194,7 +194,7 @@ else. To clear a typemap, the %clear directive should be used. For e
@@ -247,7 +247,7 @@ When the function is used in the scripting language interpreter, it will work li result = add(3,4) -
@@ -314,7 +314,7 @@ iresult, dresult = foo(3.5, 2) -
@@ -379,7 +379,7 @@ rather than directly overwriting the value of the original input object. SWIG. Backwards compatibility is preserved, but deprecated.
-@@ -413,7 +413,7 @@ Typemap declarations are lexically scoped so a typemap takes effect from the poi file or a matching %clear declaration.
-@@ -423,7 +423,7 @@ insure that a value is positive, or that a pointer is non-NULL. This can be accomplished including the constraints.i library file.
-@@ -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.
-@@ -465,7 +465,7 @@ NONNULL Non-NULL pointer (pointers only). -
diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html new file mode 100644 index 000000000..ce9174254 --- /dev/null +++ b/Doc/Manual/CPlusPlus11.html @@ -0,0 +1,1182 @@ + + +
+This chapter gives you a brief overview about the SWIG +implementation of the C++11 standard. This part of SWIG is still a work in +progress. +
+SWIG supports the new C++ syntax changes with some minor limitations +in some areas such as decltype expressions and variadic templates. Wrappers for the +new STL types (unordered_ containers, result_of, tuples) are incomplete. +The wrappers for the new containers would work much like the C++03 containers and +users are welcome to help by adapting the existing container interface files and submitting them +as a patch for inclusion in future versions of SWIG. +
+ ++SWIG correctly parses the rvalue reference syntax '&&', +for example the typical usage of it in the move constructor and move assignment operator below: +
+ +
+class MyClass {
+...
+ std::vector<int> numbers;
+public:
+ MyClass(MyClass &&other) : numbers(std::move(other.numbers)) {}
+ MyClass & operator=(MyClass &&other) {
+ numbers = std::move(other.numbers);
+ return *this;
+ }
+};
++Rvalue references are designed for C++ temporaries and so are not very useful when used from non-C++ target languages. +Generally you would just ignore them via %ignore before parsing the class. +For example, ignore the move constructor: +
+ ++%ignore MyClass::MyClass(MyClass &&); +
+The plan is to ignore move constructors by default in a future version of SWIG. Note that both normal assignment operators as well as move assignment operators are ignored by default in most target languages with the following warning: +
+ ++example.i:18: Warning 503: Can't wrap 'operator =' unless renamed to a valid identifier. ++
SWIG parses and identifies the keyword constexpr, but cannot fully utilise it. +These C++ compile time constants are usable as runtime constants from the target languages. +Below shows example usage for assigning a C++ compile time constant from a compile time constant function: +
+ +
+constexpr int XXX() { return 10; }
+constexpr int YYY = XXX() + 100;
++When either of these is used from a target language, a runtime call is made to obtain the underlying constant. +
+ +SWIG correctly parses the keywords extern template. +However, this template instantiation suppression in a translation unit has no relevance outside of the C++ compiler and so is not used by SWIG. +SWIG only uses %template for instantiating and wrapping templates.
+ ++template class std::vector<int>; // C++03 explicit instantiation in C++ +extern template class std::vector<int>; // C++11 explicit instantiation suppression in C++ +%template(VectorInt) std::vector<int>; // SWIG instantiation +
+Initializer lists are very much a C++ compiler construct and are not very accessible from wrappers as +they are intended for compile time initialization of classes using the special std::initializer_list type. +SWIG detects usage of initializer lists and will emit a special informative warning each time one is used: +
+ ++example.i:33: Warning 476: Initialization using std::initializer_list. ++
+Initializer lists usually appear in constructors but can appear in any function or method. +They often appear in constructors which are overloaded with alternative approaches to initializing a class, +such as the std container's push_back method for adding elements to a container. +The recommended approach then is to simply ignore the initializer-list constructor, for example: +
+ +
+%ignore Container::Container(std::initializer_list<int>);
+class Container {
+public:
+ Container(std::initializer_list<int>); // initializer-list constructor
+ Container();
+ void push_back(const int &);
+ ...
+};
+Alternatively you could modify the class and add another constructor for initialization by some other means, +for example by a std::vector:
+ +
+%include <std_vector.i>
+class Container {
+public:
+ Container(const std::vector<int> &);
+ Container(std::initializer_list<int>); // initializer-list constructor
+ Container();
+ void push_back(const int &);
+ ...
+};
+And then call this constructor from your target language, for example, in Python, the following will call the constructor taking the std::vector:
+ ++>>> c = Container( [1,2,3,4] ) +
+If you are unable to modify the class being wrapped, consider ignoring the initializer-list constructor and using +%extend to add in an alternative constructor: +
+ +
+%include <std_vector.i>
+%extend Container {
+ Container(const std::vector<int> &elements) {
+ Container *c = new Container();
+ for (int element : elements)
+ c->push_back(element);
+ return c;
+ }
+}
+
+%ignore Container::Container(std::initializer_list<int>);
+
+class Container {
+public:
+ Container(std::initializer_list<int>); // initializer-list constructor
+ Container();
+ void push_back(const int &);
+ ...
+};
++The above makes the wrappers look is as if the class had been declared as follows: +
+ +
+%include <std_vector.i>
+class Container {
+public:
+ Container(const std::vector<int> &);
+// Container(std::initializer_list<int>); // initializer-list constructor (ignored)
+ Container();
+ void push_back(const int &);
+ ...
+};
++std::initializer_list is simply a container that can only be initialized at compile time. +As it is just a C++ type, it is possible to write typemaps for a target language container to map onto +std::initializer_list. However, this can only be done for a fixed number of elements as +initializer lists are not designed to be constructed with a variable number of arguments at runtime. +The example below is a very simple approach which ignores any parameters passed in and merely initializes +with a fixed list of fixed integer values chosen at compile time: +
+ +
+%typemap(in) std::initializer_list<int> {
+ $1 = {10, 20, 30, 40, 50};
+}
+class Container {
+public:
+ Container(std::initializer_list<int>); // initializer-list constructor
+ Container();
+ void push_back(const int &);
+ ...
+};
++Any attempt at passing in values from the target language will be ignored and be replaced by {10, 20, 30, 40, 50}. +Needless to say, this approach is very limited, but could be improved upon, but only slightly. +A typemap could be written to map a fixed number of elements on to the std::initializer_list, +but with values decided at runtime. +The typemaps would be target language specific. +
+ ++Note that the default typemap for std::initializer_list does nothing but issue the warning +and hence any user supplied typemaps will override it and suppress the warning. +
+ +The curly brackets {} for member initialization are fully +supported by SWIG:
+ +
+struct BasicStruct {
+ int x;
+ double y;
+};
+
+struct AltStruct {
+ AltStruct(int x, double y) : x_{x}, y_{y} {}
+
+ int x_;
+ double y_;
+};
+
+BasicStruct var1{5, 3.2}; // only fills the struct components
+AltStruct var2{2, 4.3}; // calls the constructor
+Uniform initialization does not affect usage from the target language, for example in Python:
+ ++>>> a = AltStruct(10, 142.15) +>>> a.x_ +10 +>>> a.y_ +142.15 +
SWIG supports decltype() with some limitations. Single +variables are allowed, however, expressions are not supported yet. For +example, the following code will work:
++int i; +decltype(i) j; +
However, using an expression inside the decltype results in syntax error:
++int i; int j; +decltype(i+j) k; // syntax error +
This feature is part of the implementation block only. SWIG +ignores it.
+ +SWIG correctly parses most of the Lambda functions syntax. For example:
+
+auto val = [] { return something; };
+auto sum = [](int x, int y) { return x+y; };
+auto sum = [](int x, int y) -> int { return x+y; };
+The lambda functions are removed from the wrappers for now, because of the lack of support +for closures (scope of the lambda functions) in the target languages.
+ ++Lambda functions used to create variables can also be parsed, but due to limited support of auto when +the type is deduced from the expression, the variables are simply ignored. +
+ +
+auto six = [](int x, int y) { return x+y; }(4, 2);
++Better support should be available in a later release. +
+ +SWIG fully supports the new definition of functions. For example:
+
+struct SomeStruct {
+ int FuncName(int x, int y);
+};
+can now be written as in C++11:
+ +
+struct SomeStruct {
+ auto FuncName(int x, int y) -> int;
+};
+
+auto SomeStruct::FuncName(int x, int y) -> int {
+ return x + y;
+}
+The usage in the target languages remains the same, for example in Python:
+ ++>>> a = SomeStruct() +>>> a.FuncName(10,5) +15 +
SWIG will also deal with type inference for the return type, as per the limitations described earlier. For example:
++auto square(float a, float b) -> decltype(a); +
+There are three parts to object construction improvement. +The first improvement is constructor delegation such as the following: +
+ +
+class A {
+public:
+ int a;
+ int b;
+ int c;
+
+ A() : A(10) {}
+ A(int aa) : A(aa, 20) {}
+ A(int aa, int bb) : A(aa, bb, 30) {}
+ A(int aa, int bb, int cc) { a=aa; b=bb; c=cc; }
+};
++where peer constructors can be called. SWIG handles this without any issue. +
+ ++The second improvement is constructor inheritance via a using declaration. +This is parsed correctly, but the additional constructors are not currently added to the derived proxy class in the target language. +An example is shown below: + +
+ +
+class BaseClass {
+public:
+ BaseClass(int iValue);
+};
+
+class DerivedClass: public BaseClass {
+ public:
+ using BaseClass::BaseClass; // Adds DerivedClass(int) constructor
+};
++The final part is member initialization at the site of the declaration. +This kind of initialization is handled by SWIG. +
+ +
+class SomeClass {
+public:
+ SomeClass() {}
+ explicit SomeClass(int new_value) : value(new_value) {}
+
+ int value = 5;
+};
++The special identifiers final and override can be used on methods and destructors, +such as in the following example: +
+ +
+struct BaseStruct {
+ virtual void ab() const = 0;
+ virtual void cd();
+ virtual void ef();
+ virtual ~BaseStruct();
+};
+struct DerivedStruct : BaseStruct {
+ virtual void ab() const override;
+ virtual void cd() final;
+ virtual void ef() final override;
+ virtual ~DerivedStruct() override;
+};
+The nullptr constant is mostly unimportant in wrappers. In the few places it has an effect, it is treated like NULL.
+ +SWIG parses the new enum class syntax and forward declarator for the enums:
++enum class MyEnum : unsigned int; +
The strongly typed enumerations are treated the same as the ordinary and anonymous enums. +This is because the required nested class support in SWIG is new and has not yet been incorporated into the wrapping of these strongly typed enum classes. +This is usually not a problem, however, +there may be some name clashes. For example, the following code:
+ +
+class Color {
+ enum class PrintingColors : unsigned int {
+ Cyan, Magenta, Yellow, Black
+ };
+
+ enum class BasicColors {
+ Red, Green, Blue
+ };
+
+ enum class AllColors {
+ // produces warnings because of duplicate names
+ Yellow, Orange, Red, Magenta, Blue, Cyan, Green, Pink, Black, White
+ };
+};
+A workaround is to write these as a series of separate classes containing anonymous enums:
+ +
+class PrintingColors {
+ enum : unsigned int {
+ Cyan, Magenta, Yellow, Black
+ };
+};
+
+class BasicColors {
+ enum : unsigned int {
+ Red, Green, Blue
+ };
+};
+
+class AllColors {
+ enum : unsigned int {
+ Yellow, Orange, Red, Magenta, Blue, Cyan, Green, Pink, Black, White
+ };
+};
++Expect to see this improved in a future version of SWIG. +
+ +SWIG correctly parses the symbols >> as closing the +template block, if found inside it at the top level, or as the right +shift operator >> otherwise.
+ ++std::vector<std::vector<int>> myIntTable; +
SWIG correctly parses the keyword explicit for operators in addition to constructors now. +For example:
+ +
+class U {
+public:
+ int u;
+};
+
+class V {
+public:
+ int v;
+};
+
+class TestClass {
+public:
+ //implicit converting constructor
+ TestClass(U const &val) { t=val.u; }
+
+ // explicit constructor
+ explicit TestClass(V const &val) { t=val.v; }
+
+ int t;
+};
+
+struct Testable {
+ // explicit conversion operator
+ explicit operator bool() const {
+ return false;
+ }
+};
++The effect of explicit constructors and operators has little relevance for the proxy classes as target +languages don't have the same concepts of implicit conversions as C++. +Conversion operators either with or without explicit need renaming to a valid identifier name in order to make +them available as a normal proxy method. +
+ ++The following is an example of an alias template: + +
+template< typename T1, typename T2, int >
+class SomeType {
+ T1 a;
+ T2 b;
+ int c;
+};
+
+template< typename T2 >
+using TypedefName = SomeType<char*, T2, 5>;
++These are partially supported as SWIG will parse these and identify them, however, they are ignored as they are not added to the type system. A warning such as the following is issued: +
+ ++example.i:13: Warning 342: The 'using' keyword in template aliasing is not fully supported yet. ++
+Similarly for non-template type aliasing: +
+ ++using PFD = void (*)(double); // New introduced syntax +
+A warning will be issued: +
+ ++example.i:17: Warning 341: The 'using' keyword in type aliasing is not fully supported yet. ++
The equivalent old style typedefs can be used as a workaround:
+ ++typedef void (*PFD)(double); // The old style +
SWIG fully supports any type inside a union even if it does not +define a trivial constructor. For example, the wrapper for the following +code correctly provides access to all members in the union:
+ +
+struct point {
+ point() {}
+ point(int x, int y) : x_(x), y_(y) {}
+ int x_, y_;
+};
+
+#include <new> // For placement 'new' in the constructor below
+union P {
+ int z;
+ double w;
+ point p; // Illegal in C++03; legal in C++11.
+ // Due to the point member, a constructor definition is required.
+ P() {
+ new(&p) point();
+ }
+} p1;
+SWIG supports the variadic templates syntax (inside the <> +block, variadic class inheritance and variadic constructor and +initializers) with some limitations. The following code is correctly parsed:
+ +
+template <typename... BaseClasses> class ClassName : public BaseClasses... {
+public:
+ ClassName (BaseClasses &&... baseClasses) : BaseClasses(baseClasses)... {}
+}
++For now however, the %template directive only accepts one parameter substitution +for the variable template parameters. +
+ ++%template(MyVariant1) ClassName<> // zero argument not supported yet +%template(MyVariant2) ClassName<int> // ok +%template(MyVariant3) ClassName<int, int> // too many arguments not supported yet +
Support for the variadic sizeof() function is correctly parsed:
+ ++const int SIZE = sizeof...(ClassName<int, int>); +
+In the above example SIZE is of course wrapped as a constant. +
+ +SWIG supports wide string and Unicode string constants and raw string literals.
+ ++// New string literals +wstring aa = L"Wide string"; +const char *bb = u8"UTF-8 string"; +const char16_t *cc = u"UTF-16 string"; +const char32_t *dd = U"UTF-32 string"; + +// Raw string literals +const char *xx = ")I'm an \"ascii\" \\ string."; +const char *ee = R"XXX()I'm an "ascii" \ string.)XXX"; // same as xx +wstring ff = LR"XXX(I'm a "raw wide" \ string.)XXX"; +const char *gg = u8R"XXX(I'm a "raw UTF-8" \ string.)XXX"; +const char16_t *hh = uR"XXX(I'm a "raw UTF-16" \ string.)XXX"; +const char32_t *ii = UR"XXX(I'm a "raw UTF-32" \ string.)XXX"; +
+Non-ASCII string support varies quite a bit among the various target languages though. +
+ ++Note: There is a bug currently where SWIG's preprocessor incorrectly parses an odd number of double quotes +inside raw string literals. +
+ ++SWIG parses the declaration of user-defined literals, that is, the operator "" _mysuffix() function syntax. +
+ ++Some examples are the raw literal: +
++OutputType operator "" _myRawLiteral(const char * value); +
+numeric cooked literals: +
++OutputType operator "" _mySuffixIntegral(unsigned long long); +OutputType operator "" _mySuffixFloat(long double); +
+and cooked string literals: +
++OutputType operator "" _mySuffix(const char * string_values, size_t num_chars); +OutputType operator "" _mySuffix(const wchar_t * string_values, size_t num_chars); +OutputType operator "" _mySuffix(const char16_t * string_values, size_t num_chars); +OutputType operator "" _mySuffix(const char32_t * string_values, size_t num_chars); +
+Like other operators that SWIG parses, a warning is given about renaming the operator in order for it to be wrapped: +
+ ++example.i:27: Warning 503: Can't wrap 'operator "" _myRawLiteral' unless renamed to a valid identifier. +
+If %rename is used, then it can be called like any other wrapped method. +Currently you need to specify the full declaration including parameters for %rename: +
+ ++%rename(MyRawLiteral) operator"" _myRawLiteral(const char * value); +
+Or if you just wish to ignore it altogether: +
+ ++%ignore operator "" _myRawLiteral(const char * value); +
+Note that use of user-defined literals such as the following still give a syntax error: +
+ ++OutputType var1 = "1234"_suffix; +OutputType var2 = 1234_suffix; +OutputType var3 = 3.1416_suffix; +
SWIG correctly parses the thread_local keyword. For example, variables +reachable by the current thread can be defined as:
+ +
+struct A {
+ static thread_local int val;
+};
+thread_local int global_val;
++The use of the thread_local storage specifier does not affect the wrapping process; it does not modify +the wrapper code compared to when it is not specified. +A variable will be thread local if accessed from different threads from the target language in the +same way that it will be thread local if accessed from C++ code. +
+ +SWIG handles explicitly defaulted functions, that is, = default added to a function declaration. Deleted definitions, which are also called deleted functions, have = delete added to the function declaration. +For example:
+ +
+struct NonCopyable {
+ NonCopyable & operator=(const NonCopyable &) = delete; /* Removes operator= */
+ NonCopyable(const NonCopyable &) = delete; /* Removes copy constructor */
+ NonCopyable() = default; /* Explicitly allows the empty constructor */
+};
++Wrappers for deleted functions will not be available in the target language. +Wrappers for defaulted functions will of course be available in the target language. +Explicitly defaulted functions have no direct effect for SWIG wrapping as the declaration is handled +much like any other method declaration parsed by SWIG. +
+ ++Deleted functions are also designed to prevent implicit conversions when calling the function. +For example, the C++ compiler will not compile any code which attempts to use an int as the type of the parameter passed to f below: +
+ +
+struct NoInt {
+ void f(double i);
+ void f(int) = delete;
+};
++This is a C++ compile time check and SWIG does not make any attempt to detect if the target language is using an int instead of a double though, +so in this case it is entirely possible to pass an int instead of a double to f from Java, Python etc. +
+ +SWIG correctly parses and uses the new long long type already introduced in C99 some time ago.
+ ++SWIG correctly parses the new static_assert declarations. +This is a C++ compile time directive so there isn't anything useful that SWIG can do with it. +
+ +
+template <typename T>
+struct Check {
+ static_assert(sizeof(int) <= sizeof(T), "not big enough");
+};
++SWIG can parse the new sizeof() on types as well as on objects. For example: +
+ +
+struct A {
+ int member;
+};
+
+const int SIZE = sizeof(A::member); // does not work with C++03. Okay with C++11
+In Python:
++>>> SIZE +8 +
+C++11 added in the noexcept specification to exception specifications to indicate that a function simply may or may not throw an exception, without actually naming any exception. +SWIG understands these, although there isn't any useful way that this information can be taken advantage of by target languages, +so it is as good as ignored during the wrapping process. +Below are some examples of noexcept in function declarations: +
+ ++static void noex1() noexcept; +int noex2(int) noexcept(true); +int noex3(int, bool) noexcept(false); +
+An alignof operator is used mostly within C++ to return alignment in number of bytes, but could be used to initialize a variable as shown below. +The variable's value will be available for access by the target language as any other variable's compile time initialised value. + +
+const int align1 = alignof(A::member); +
+The alignas specifier for variable alignment is not yet supported. +Example usage: +
+ +
+struct alignas(16) S {
+ int num;
+};
+alignas(double) unsigned char c[sizeof(double)];
++Use the preprocessor to work around this for now: +
+ ++#define alignas(T) +
+Attributes such as those shown below, are not yet supported and will give a syntax error. +
+ ++int [[attr1]] i [[attr2, attr3]]; + +[[noreturn, nothrow]] void f [[noreturn]] (); +
SWIG does not currently wrap or use any of the new threading +classes introduced (thread, mutex, locks, condition variables, task). The main reason is that +SWIG target languages offer their own threading facilities so there is limited use for them. +
+ ++SWIG does not provide library files for the new tuple types yet. +Variadic template support requires further work to provide substantial tuple wrappers. +
+ ++The new hash tables in the STL are unordered_set, unordered_multiset, unordered_map, unordered_multimap. +These are not available in SWIG, but in principle should be easily implemented by adapting the current STL containers. +
+ ++While SWIG could provide wrappers for the new C++11 regular expressions classes, there is little need as the target languages have their own regular expression facilities. +
+ ++SWIG provides special smart pointer handling for std::shared_ptr in the same way it has support for boost::shared_ptr. +Please see the shared_ptr smart pointer library section. +There is no special smart pointer handling available for std::weak_ptr and std::unique_ptr yet. +
+ +This feature extends and standardizes the standard library only and does not effect the C++ language nor SWIG.
+ ++Wrapper references are similar to normal C++ references but are copy-constructible and copy-assignable. +They could conceivably be used in public APIs. +There is no special support for std::reference_wrapper in SWIG though. +Users would need to write their own typemaps if wrapper references are being used and these would be similar to the plain C++ reference typemaps. +
+ + ++SWIG supports functor classes in a few languages in a very natural way. +However nothing is provided yet for the new std::function template. +SWIG will parse usage of the template like any other template. +
+ +
+%rename(__call__) Test::operator(); // Default renaming used for Python
+
+struct Test {
+ bool operator()(int x, int y); // function object
+};
+
+#include <functional>
+std::function<void (int, int)> pF = Test; // function template wrapper
+
++Example of supported usage of the plain functor from Python is shown below. +It does not involve std::function. +
+ ++t = Test() +b = t(1,2) # invoke C++ function object +
The type_traits functions to support C++ metaprogramming is useful at compile time and is aimed specifically at C++ development:
+ +
+#include <type_traits>
+
+// First way of operating.
+template< bool B > struct algorithm {
+ template< class T1, class T2 > static int do_it(T1 &, T2 &) { /*...*/ return 1; }
+};
+
+// Second way of operating.
+template<> struct algorithm<true> {
+ template< class T1, class T2 > static int do_it(T1, T2) { /*...*/ return 2; }
+};
+
+// Instantiating 'elaborate' will automatically instantiate the correct way to operate, depending on the types used.
+template< class T1, class T2 > int elaborate(T1 A, T2 B) {
+ // Use the second way only if 'T1' is an integer and if 'T2' is a floating point,
+ // otherwise use the first way.
+ return algorithm< std::is_integral<T1>::value && std::is_floating_point<T2>::value >::do_it(A, B);
+}
++SWIG correctly parses the template specialization, template types etc. +However, metaprogramming and the additional support in the type_traits header is really for compile time and is not much use at runtime for the target languages. +For example, as SWIG requires explicit instantiation of templates via %template, there isn't much that std::is_integral<int> is going to provide by itself. +However, template functions using such metaprogramming techniques might be useful to wrap. +For example, the following instantiations could be made: +
+ ++%template(Elaborate) elaborate<int, int>; +%template(Elaborate) elaborate<int, double>; +
+Then the appropriate algorithm can be called for the subset of types given by the above %template instantiations from a target language, such as Python: +
+ ++>>> Elaborate(0, 0) +1 +>>> Elaborate(0, 0.0) +2 +
+The new std::result_of class introduced in the <functional> header provides a generic way to obtain the return type of a function type via std::result_of::type. +There isn't any library interface file to support this type. +With a bit of work, SWIG will deduce the return type of functions when used in std::result_of using the approach shown below. +The technique basically forward declares the std::result_of template class, then partially specializes it for the function types of interest. +SWIG will use the partial specialization and hence correctly use the std::result_of::type provided in the partial specialization. +
+ +
+%inline %{
+#include <functional>
+typedef double(*fn_ptr)(double);
+%}
+
+namespace std {
+ // Forward declaration of result_of
+ template<typename Func> struct result_of;
+ // Add in a partial specialization of result_of
+ template<> struct result_of< fn_ptr(double) > {
+ typedef double type;
+ };
+}
+
+%template() std::result_of< fn_ptr(double) >;
+
+%inline %{
+
+double square(double x) {
+ return (x * x);
+}
+
+template<class Fun, class Arg>
+typename std::result_of<Fun(Arg)>::type test_result_impl(Fun fun, Arg arg) {
+ return fun(arg);
+}
+%}
+
+%template(test_result) test_result_impl< fn_ptr, double >;
+%constant double (*SQUARE)(double) = square;
++Note the first use of %template which SWIG requires to instantiate the template. +The empty template instantiation suffices as no proxy class is required for std::result_of<Fun(Arg)>::type as this type is really just a double. +The second %template instantiates the template function which is being wrapped for use as a callback. +The %constant can then be used for any callback function as described in Pointers to functions and callbacks. +
+ ++Example usage from Python should give the not too surprising result: +
+ ++>>> test_result(SQUARE, 5.0) +25.0 +
+Phew, that is a lot of hard work to get a callback working. +You could just go with the more attractive option of just using double as the return type in the function declaration instead of result_of! +
+ + + diff --git a/Doc/Manual/CSharp.html b/Doc/Manual/CSharp.html index 6df2594c4..7f53423fc 100644 --- a/Doc/Manual/CSharp.html +++ b/Doc/Manual/CSharp.html @@ -5,11 +5,14 @@ -@@ -69,7 +72,14 @@ The Microsoft Developer Network (MSDN) h Monodoc, available from the Mono project, has a very useful section titled Interop with native libraries.
-+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 using directives in generated code. This breaks backwards compatibility with typemaps, pragmas, etc written for use with SWIG 2 that assume the presence of using System; or using System.Runtime.InteropServices; directives in the intermediate class imports, module imports, or proxy imports. SWIG 3 supports backwards compatibility though the use of the SWIG2_CSHARP macro. If SWIG2_CSHARP is defined, SWIG 3 generates using 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 -DSWIG2_CSHARP commandline parameter when executing swig. +
+ +@@ -262,7 +272,7 @@ An example shows that char * could be marshalled in different ways,
-%typemap(imtype, out="IntPtr") char * "string" +%typemap(imtype, out="global::System.IntPtr") char * "string" char * function(char *);
-public static extern IntPtr function(string jarg1); +public static extern global::System.IntPtr function(string jarg1);
%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) {}
@@ -310,12 +320,12 @@ The intermediary class will then have the marshalling as specified by everything
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);
}
[ThreadSafe]
-public class AClass : IDisposable {
+public class AClass : global::System.IDisposable {
...
[ThreadSafe(false)]
public AClass(double a) ...
@@ -392,9 +402,9 @@ An example for attaching attributes to the enum and enum values is shown below.
-%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 };
%}
@@ -407,12 +417,12 @@ which will result in the following C# enum:
-[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
}
@@ -482,7 +492,7 @@ Windows users can also get the examples working using a
Cygwin or MinGW 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.
-19.3 Void pointers
+20.3 Void pointers
@@ -500,7 +510,7 @@ void * f(void *v);
-19.4 C# Arrays
+20.4 C# Arrays
@@ -512,7 +522,7 @@ with one of the following three approaches; namely the SWIG C arrays library, P/
pinned arrays.
-19.4.1 The SWIG C arrays library
+20.4.1 The SWIG C arrays library
@@ -549,7 +559,7 @@ example.print_array(c.cast()); // Pass to C
-19.4.2 Managed arrays using P/Invoke default array marshalling
+20.4.2 Managed arrays using P/Invoke default array marshalling
@@ -618,9 +628,9 @@ marshalling for the arrays:
-[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);
@@ -668,15 +678,15 @@ and intermediary class method
- [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);
-19.4.3 Managed arrays using pinning
+20.4.3 Managed arrays using pinning
@@ -743,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);
}
}
@@ -764,14 +774,14 @@ example - the method is expecting an IntPtr as the parameter type.
-[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);
-19.5 C# Exceptions
+20.5 C# Exceptions
@@ -868,11 +878,11 @@ set so should only be used when a C# exception is not created.
-19.5.1 C# exception example using "check" typemap
+20.5.1 C# exception example using "check" typemap
-Lets say we have the following simple C++ method:
+Let's say we have the following simple C++ method:
@@ -1050,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 SWIG_CSharpSetPendingException.
-19.5.2 C# exception example using %exception
+20.5.2 C# exception example using %exception
@@ -1115,7 +1125,7 @@ The managed code generated does check for the pending exception as mentioned ear
@@ -1172,7 +1182,7 @@ SWIGEXPORT void SWIGSTDCALL CSharp_evensonly(int jarg1) { Multiple catch handlers are generated should there be more than one exception specifications declared.
-
@@ -1220,7 +1230,7 @@ the C# code can be generated into the intermediary class using the 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);
@@ -1264,7 +1274,7 @@ The boiler plate code above must be used in addition to a handcrafted Custom
// Custom C# Exception
-class CustomApplicationException : System.ApplicationException {
+class CustomApplicationException : global::System.ApplicationException {
public CustomApplicationException(string message)
: base(message) {
}
@@ -1306,7 +1316,7 @@ try {
19.6 C# Directors
+20.6 C# Directors
@@ -1319,7 +1329,7 @@ The following sections provide information on the C# director implementation and However, the Java directors section should also be read in order to gain more insight into directors.
-@@ -1440,7 +1450,7 @@ CSharpDerived - UIntMethod(123)
@@ -1457,20 +1467,17 @@ Below is the generated C# Base director class.
-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() {
@@ -1479,12 +1486,12 @@ public class Base : IDisposable {
public virtual void Dispose() {
lock(this) {
- if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
+ if(swigCPtr.Handle != global::System.IntPtr.Zero && 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);
}
}
@@ -1511,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;
@@ -1521,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) };
}
@@ -1674,7 +1681,7 @@ However, a call from C# to CSharpDefaults.DefaultMethod() will of cours should pass the call on to CSharpDefaults.DefaultMethod(int)using the C++ default value, as shown above.
-@@ -1709,7 +1716,7 @@ the [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrows if you don't want users to easily stumble upon these so called 'internal workings' of the wrappers.
-@@ -1755,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); @@ -1795,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& 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); } @@ -1813,7 +1820,7 @@ The code in the second typemap constitutes the bulk of the code in the generated
-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;
@@ -1822,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);
}
@@ -1841,7 +1848,7 @@ public class Bike : IDisposable {
Note the addReference call.
-19.8.2 Memory management for objects passed to the C++ layer
+20.8.2 Memory management for objects passed to the C++ layer
@@ -1904,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);
-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);
}
@@ -1951,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);
}
@@ -1960,7 +1967,7 @@ The 'cscode' typemap simply adds in the specified code into the C# proxy class.
@@ -2000,7 +2007,7 @@ First let's look at the code that is generated by default, where the C# proxy cl
-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) {
@@ -2081,7 +2088,7 @@ The resulting generated proxy code in the Action class follows:
-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);
@@ -2099,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 {
@@ -2246,7 +2253,7 @@ public class example {
-19.8.4 A date example demonstrating marshalling of C# properties
+20.8.4 A date example demonstrating marshalling of C# properties
@@ -2299,8 +2306,8 @@ The typemap type required is thus CDate *. 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);
} %}
@@ -2322,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);
}
@@ -2346,7 +2353,7 @@ Some points to note:
@@ -2389,7 +2396,7 @@ The generated proxy class code will then contain the following wrapper for calli
...
- private void SwigDirectorsomeCallback(IntPtr date) {
+ private void SwigDirectorsomeCallback(global::System.IntPtr date) {
System.DateTime tempdate = new System.DateTime();
try {
someCallback(out tempdate);
@@ -2408,7 +2415,7 @@ Pay special attention to the memory management issues, using these attributes.
-19.8.6 Turning wrapped classes into partial classes
+20.8.6 Turning wrapped classes into partial classes
@@ -2432,7 +2439,7 @@ The default C# proxy class generated is:
-public class ExtendMe : IDisposable {
+public class ExtendMe : global::System.IDisposable {
...
public int Part1() {
...
@@ -2468,7 +2475,7 @@ The C# proxy class becomes a partial class:
-public partial class ExtendMe : IDisposable {
+public partial class ExtendMe : global::System.IDisposable {
...
public int Part1() {
...
@@ -2483,7 +2490,7 @@ You can then of course declare another part of the partial class elsewhere, for
-public partial class ExtendMe : IDisposable {
+public partial class ExtendMe : global::System.IDisposable {
public int Part2() {
return 2;
}
@@ -2508,7 +2515,7 @@ demonstrating that the class contains methods calling both unmanaged code -
The following example is an alternative approach to adding managed code to the generated proxy class.
-19.8.7 Extending proxy classes with additional C# code
+20.8.7 Extending proxy classes with additional C# code
@@ -2535,7 +2542,7 @@ The generated C# proxy class will instead be:
-public class ExtendMe : IDisposable {
+public class ExtendMe : global::System.IDisposable {
...
public int Part3() {
return 3;
@@ -2547,7 +2554,7 @@ public class ExtendMe : IDisposable {
-19.8.8 Underlying type for enums
+20.8.8 Underlying type for enums
diff --git a/Doc/Manual/Chicken.html b/Doc/Manual/Chicken.html
index 4e43b9b90..82861c31c 100644
--- a/Doc/Manual/Chicken.html
+++ b/Doc/Manual/Chicken.html
@@ -8,7 +8,7 @@
-20 SWIG and Chicken
+21 SWIG and Chicken
@@ -72,7 +72,7 @@
-20.1 Preliminaries
+21.1 Preliminaries
@@ -89,7 +89,7 @@
directory for the basic steps to run SWIG CHICKEN.
-20.1.1 Running SWIG in C mode
+21.1.1 Running SWIG in C mode
@@ -122,7 +122,7 @@
object files and linked into your project.
-20.1.2 Running SWIG in C++ mode
+21.1.2 Running SWIG in C++ mode
@@ -151,10 +151,10 @@
object files and linked into your project.
-20.2 Code Generation
+21.2 Code Generation
-20.2.1 Naming Conventions
+21.2.1 Naming Conventions
@@ -170,7 +170,7 @@
%rename SWIG directive in the SWIG interface file.
-20.2.2 Modules
+21.2.2 Modules
@@ -192,7 +192,7 @@
(uses modulename)) CHICKEN Scheme form.
-20.2.3 Constants and Variables
+21.2.3 Constants and Variables
@@ -229,7 +229,7 @@
for info on how to apply the %feature.
-20.2.4 Functions
+21.2.4 Functions
@@ -248,7 +248,7 @@
parameters). The return values can then be accessed with (call-with-values).
-20.2.5 Exceptions
+21.2.5 Exceptions
The SWIG chicken module has support for exceptions thrown from
@@ -290,7 +290,7 @@
-20.3 TinyCLOS
+21.3 TinyCLOS
@@ -333,7 +333,7 @@
-20.4 Linkage
+21.4 Linkage
@@ -354,7 +354,7 @@
-20.4.1 Static binary or shared library linked at compile time
+21.4.1 Static binary or shared library linked at compile time
We can easily use csc to build a static binary.
@@ -395,7 +395,7 @@ in which case the test script does not need to be linked with example.so. The t
be run with csi.
-20.4.2 Building chicken extension libraries
+21.4.2 Building chicken extension libraries
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.
See the Examples/chicken/egg directory in the SWIG source for an example that builds
two eggs, one using the first method and one using the second method.
-20.4.3 Linking multiple SWIG modules with TinyCLOS
+21.4.3 Linking multiple SWIG modules with TinyCLOS
Linking together multiple modules that share type information using the %import
@@ -477,7 +477,7 @@ with (declare (uses ...)).
To create an extension library or an egg, just create a module_load.scm file that (declare (uses ...))
all the modules.
-20.5 Typemaps
+21.5 Typemaps
@@ -486,7 +486,7 @@ all the modules.
Lib/chicken/chicken.swg.
-20.6 Pointers
+21.6 Pointers
@@ -519,7 +519,7 @@ all the modules.
type. flags is either zero or SWIG_POINTER_DISOWN (see below).
-20.6.1 Garbage collection
+21.6.1 Garbage collection
If the owner flag passed to SWIG_NewPointerObj is 1, NewPointerObj will add a
@@ -550,7 +550,7 @@ all the modules.
must be called manually.
-20.7 Unsupported features and known problems
+21.7 Unsupported features and known problems
@@ -560,7 +560,7 @@ all the modules.
%feature(compactdefaultargs).
-20.7.1 TinyCLOS problems with Chicken version <= 1.92
+21.7.1 TinyCLOS problems with Chicken version <= 1.92
In Chicken versions equal to or below 1.92, TinyCLOS has a limitation such that generic methods do not properly work on methods
diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html
index 77280c8bc..4dd454352 100644
--- a/Doc/Manual/Contents.html
+++ b/Doc/Manual/Contents.html
@@ -262,7 +262,61 @@
-7 Preprocessing
+7 SWIG and C++11
+
+
+
+
+- Introduction
+
- Core language changes
+
+- Rvalue reference and move semantics
+
- Generalized constant expressions
+
- Extern template
+
- Initializer lists
+
- Uniform initialization
+
- Type inference
+
- Range-based for-loop
+
- Lambda functions and expressions
+
- Alternate function syntax
+
- Object construction improvement
+
- Explicit overrides and final
+
- Null pointer constant
+
- Strongly typed enumerations
+
- Double angle brackets
+
- Explicit conversion operators
+
- Alias templates
+
- Unrestricted unions
+
- Variadic templates
+
- New string literals
+
- User-defined literals
+
- Thread-local storage
+
- Explicitly defaulted functions and deleted functions
+
- Type long long int
+
- Static assertions
+
- Allow sizeof to work on members of classes without an explicit object
+
- Exception specifications and noexcept
+
- Control and query object alignment
+
- Attributes
+
+ - Standard library changes
+
+
+
+
+
+8 Preprocessing
@@ -285,7 +339,7 @@
-8 SWIG library
+9 SWIG library
@@ -311,6 +365,7 @@
std::vector
STL exceptions
shared_ptr smart pointer
+ auto_ptr smart pointer
Utility Libraries
@@ -320,7 +375,7 @@
-9 Argument Handling
+10 Argument Handling
@@ -343,7 +398,7 @@
-10 Typemaps
+11 Typemaps
@@ -431,7 +486,7 @@
-11 Customization Features
+12 Customization Features
@@ -459,7 +514,7 @@
-12 Contracts
+13 Contracts
@@ -472,7 +527,7 @@
-13 Variable Length Arguments
+14 Variable Length Arguments
@@ -490,7 +545,7 @@
-14 Warning Messages
+15 Warning Messages
@@ -518,7 +573,7 @@
-15 Working with Modules
+16 Working with Modules
@@ -534,7 +589,7 @@
-16 Using SWIG with ccache - ccache-swig(1) manpage
+17 Using SWIG with ccache - ccache-swig(1) manpage
@@ -560,7 +615,7 @@
-17 SWIG and Allegro Common Lisp
+18 SWIG and Allegro Common Lisp
@@ -644,7 +699,7 @@
-18 SWIG and Android
+19 SWIG and Android
@@ -662,12 +717,15 @@
-19 SWIG and C#
+20 SWIG and C#
- Introduction
+
- Differences to the Java module
- Void pointers
- C# Arrays
@@ -705,7 +763,7 @@
-20 SWIG and Chicken
+21 SWIG and Chicken
@@ -743,7 +801,7 @@
-21 SWIG and D
+22 SWIG and D
@@ -777,7 +835,7 @@
-22 SWIG and Go
+23 SWIG and Go
@@ -808,7 +866,7 @@
-23 SWIG and Guile
+24 SWIG and Guile
@@ -843,7 +901,7 @@
-24 SWIG and Java
+25 SWIG and Java
@@ -926,6 +984,7 @@
Simple directors example
Director threading issues
Director performance tuning
+ Java exceptions from directors
Accessing protected members
Common customization features
@@ -987,7 +1046,49 @@
-25 SWIG and Common Lisp
+26 SWIG and Javascript
+
+
+
+
+- Overview
+
- Preliminaries
+
+
- Integration
+
+
- Examples
+
+
- Implementation
+
+
+
+
+
+27 SWIG and Common Lisp
@@ -1010,7 +1111,7 @@
-26 SWIG and Lua
+28 SWIG and Lua
@@ -1029,8 +1130,11 @@
Functions
Global variables
Constants and enums
+
Pointers
- Structures
+ Structures
C++ classes
C++ inheritance
Pointers, references, values, and arrays
@@ -1041,17 +1145,23 @@
C++ templates
C++ Smart Pointers
C++ Exceptions
+ Namespaces
+
Typemaps
- Writing typemaps
+ Writing typemaps
Customization of your Bindings
@@ -1069,7 +1179,7 @@
-27 SWIG and Modula-3
+29 SWIG and Modula-3
@@ -1107,7 +1217,7 @@
-28 SWIG and MzScheme/Racket
+30 SWIG and MzScheme/Racket
@@ -1119,7 +1229,7 @@
-29 SWIG and Ocaml
+31 SWIG and Ocaml
@@ -1170,7 +1280,7 @@
-30 SWIG and Octave
+32 SWIG and Octave
@@ -1206,7 +1316,7 @@
-31 SWIG and Perl5
+33 SWIG and Perl5
@@ -1269,11 +1379,20 @@
Modifying the proxy methods
Adding additional Perl code
+ Cross language polymorphism
+
-32 SWIG and PHP
+34 SWIG and PHP
@@ -1313,7 +1432,7 @@
-33 SWIG and Pike
+35 SWIG and Pike
@@ -1337,7 +1456,7 @@
-34 SWIG and Python
+36 SWIG and Python
-35 SWIG and R
+37 SWIG and R
@@ -1463,7 +1589,7 @@
-36 SWIG and Ruby
+38 SWIG and Ruby
@@ -1597,7 +1723,7 @@
-37 SWIG and Tcl
+39 SWIG and Tcl
@@ -1663,7 +1789,7 @@
-38 Extending SWIG to support new languages
+40 Extending SWIG to support new languages
diff --git a/Doc/Manual/Contract.html b/Doc/Manual/Contract.html
index de390fba4..35bc874ef 100644
--- a/Doc/Manual/Contract.html
+++ b/Doc/Manual/Contract.html
@@ -6,7 +6,7 @@
-12 Contracts
+13 Contracts
-12.2 %contract and classes
+13.2 %contract and classes
@@ -173,7 +173,7 @@ specified for the derived class all must hold. In the above example,
this means that both the arguments to Spam::bar must be positive.
-12.3 Constant aggregation and %aggregate_check
+13.3 Constant aggregation and %aggregate_check
@@ -262,7 +262,7 @@ Regrettably, there is no automatic way to perform similar checks with enums valu
release.
-12.4 Notes
+13.4 Notes
diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html
index f420f42d6..a0a89c042 100644
--- a/Doc/Manual/Customization.html
+++ b/Doc/Manual/Customization.html
@@ -6,7 +6,7 @@
-11 Customization Features
+12 Customization Features
@@ -45,7 +45,7 @@ of exception handling is presented. Then, a more general-purpose
customization mechanism known as "features" is described.
-11.1 Exception handling with %exception
+12.1 Exception handling with %exception
@@ -100,7 +100,7 @@ for exception handling. That directive is deprecated--%exception
provides the same functionality, but is substantially more flexible.
-11.1.1 Handling exceptions in C code
+12.1.1 Handling exceptions in C code
@@ -166,7 +166,7 @@ Each target language has its own approach to creating a runtime error/exception
and for Perl it is the croak method shown above.
-11.1.2 Exception handling with longjmp()
+12.1.2 Exception handling with longjmp()
@@ -240,7 +240,7 @@ Note: This implementation is only intended to illustrate the general idea. To m
modify it to handle nested try declarations.
-11.1.3 Handling C++ exceptions
+12.1.3 Handling C++ exceptions
@@ -275,7 +275,7 @@ class OutOfMemory {};
-11.1.4 Exception handlers for variables
+12.1.4 Exception handlers for variables
@@ -300,7 +300,7 @@ The %allowexception feature works like any other feature and so can be
-11.1.5 Defining different exception handlers
+12.1.5 Defining different exception handlers
@@ -437,7 +437,7 @@ declarations. However, it never really worked that well and the new
%exception directive is much better.
-11.1.6 Special variables for %exception
+12.1.6 Special variables for %exception
@@ -540,7 +540,7 @@ Below shows the expansions for the 1st of the overloaded something wrap
-11.1.7 Using The SWIG exception library
+12.1.7 Using The SWIG exception library
@@ -595,7 +595,7 @@ SWIG_NullReferenceError
The SWIG_exception() function can also be used in typemaps.
-11.2 Object ownership and %newobject
+12.2 Object ownership and %newobject
@@ -752,7 +752,7 @@ char *strdup(const char *s);
The results might not be what you expect.
-11.3 Features and the %feature directive
+12.3 Features and the %feature directive
@@ -834,7 +834,7 @@ The following are all equivalent:
The syntax in the first variation will generate the { } delimiters used whereas the other variations will not.
-11.3.1 Feature attributes
+12.3.1 Feature attributes
@@ -875,7 +875,7 @@ In the following example, MyExceptionClass is the name of the Java clas
Further details can be obtained from the Java exception handling section.
-11.3.2 Feature flags
+12.3.2 Feature flags
@@ -973,7 +973,7 @@ in the swig.swg Library file. The following shows the alternative synta
The concept of clearing features is discussed next.
-11.3.3 Clearing features
+12.3.3 Clearing features
@@ -1066,7 +1066,7 @@ The three macros below show this for the "except" feature:
-11.3.4 Features and default arguments
+12.3.4 Features and default arguments
@@ -1141,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.
-11.3.5 Feature example
+12.3.5 Feature example
diff --git a/Doc/Manual/D.html b/Doc/Manual/D.html
index 43fa69196..47dab50f1 100644
--- a/Doc/Manual/D.html
+++ b/Doc/Manual/D.html
@@ -6,7 +6,7 @@
-21 SWIG and D
+22 SWIG and D
@@ -41,7 +41,7 @@
-21.1 Introduction
+22.1 Introduction
From the D Programming Language web site: 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. As such, it is not very surprising that D is able to directly interface with C libraries. Why would a SWIG module for D be needed then in the first place?
@@ -53,7 +53,7 @@
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 C# (and also on Java, since the C# module was in turn forked from it).
-21.2 Command line invocation
+22.2 Command line invocation
To activate the D module, pass the -d 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:
@@ -83,10 +83,10 @@
-21.3 Typemaps
+22.3 Typemaps
-21.3.1 C# <-> D name comparison
+22.3.1 C# <-> D name comparison
If you already know the SWIG C# module, you might find the following name comparison table useful:
@@ -112,7 +112,7 @@
-21.3.2 ctype, imtype, dtype
+22.3.2 ctype, imtype, dtype
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.
@@ -120,7 +120,7 @@
The ctype typemap is used to determine the types to use in the C wrapper functions. The types from the imtype typemap are used in the extern(C) declarations of these functions in the intermediary D module. The dtype typemap contains the D types used in the D proxy module/class.
-21.3.3 in, out, directorin, directorout
+22.3.3 in, out, directorin, directorout
Used for converting between the types for C/C++ and D when generating the code for the wrapper functions (on the C++ side).
@@ -130,7 +130,7 @@
The directorin typemap is used to convert parameters to the type used in the D director callback function, its return value is processed by directorout (see below).
-21.3.4 din, dout, ddirectorin, ddirectorout
+22.3.4 din, dout, ddirectorin, ddirectorout
Typemaps for code generation in D proxy and type wrapper classes.
@@ -157,13 +157,13 @@
dtype DClass.method(dtype a)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).
-These typemaps are used for generating the skeleton of proxy classes for C++ types.
@@ -175,7 +175,7 @@dconstructor, ddestructor, ddispose and ddispose_derived are used to generate the class constructor, destructor and dispose() method, respectively. The auxiliary code for handling the pointer to the C++ object is stored in dbody and dbody_derived. You can override them for specific types.
-The standard SWIG special variables are available for use within typemaps as described in the Typemaps documentation, for example $1, $input, $result etc.
@@ -295,7 +295,7 @@ $importtype(AnotherInterface) -The D module defines a number of directives which modify the SWIG features set globally or for a specific declaration:
@@ -325,7 +325,7 @@ struct A { -There are a few SWIG pragmas specific to the D module, which you can use to influence the D code SWIG generates:
@@ -364,7 +364,7 @@ struct A { -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.
@@ -374,7 +374,7 @@ struct A {As this feature is implemented in exactly the same way it is for C#, please see the C# documentation for a more detailed explanation.
-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++.
@@ -383,16 +383,16 @@ struct A { -By default, SWIG flattens all C++ namespaces into a single target language namespace, but as for Java and C#, the nspace 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, free variables and functions are not supported yet; currently, they are all allows written to the main proxy D module.
-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 primitive type below.
@@ -404,7 +404,7 @@ struct A {To determine if a type should be considered primitive, the cprimitive attribute on its dtype attribute is used. For example, the dtype typemap for float has cprimitive="1", so the code from the nativepointer attribute is taken into account e.g. for float ** or the function pointer float (*)(float *).
-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:
@@ -416,7 +416,7 @@ struct A {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, [], in combination with assignments - while operator [] in C++ simply returns a reference which is then written to, D resorts to a separate opIndexAssign method -, or implicit casting (which was introduced in D2 via alias this). Despite the lack of automatic support, manually handling these cases should be perfectly possible.
-As with any other language, the SWIG test-suite can be built for D using the *-d-test-suite targets of the top-level Makefile. By default, D1 is targeted, to build it with D2, use the optional D_VERSION variable, e.g. make check-d-test-suite D_VERSION=2.
@@ -424,14 +424,14 @@ struct A {Note: If you want to use GDC on Linux or another platform which requires you to link libdl for dynamically loading the shared library, you might have to add -ldl manually to the d_compile target in Examples/Makefile, because GDC does not currently honor the pragma(lib,...) statement.
-There are no D-specific typemap examples yet. However, with the above name comparison table, you should be able to get an idea what can be done by looking at the corresponding C# section.
-There are a couple of features which are not implemented yet, but would be very useful and might be added in the near future:
diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html index 5ea4e51f4..00302d7b5 100644 --- a/Doc/Manual/Extending.html +++ b/Doc/Manual/Extending.html @@ -6,7 +6,7 @@ -@@ -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.
-@@ -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.
-@@ -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.
-@@ -203,7 +203,7 @@ latter stage of compilation. The next few sections briefly describe some of these stages.
-@@ -284,7 +284,7 @@ been expanded as well as everything else that goes into the low-level construction of the wrapper code.
-@@ -385,7 +385,7 @@ returning a foo and taking types a and b as arguments).
-@@ -640,7 +640,7 @@ $ swig -c++ -python -debug-module 4 example.i
@@ -659,7 +659,7 @@ that matches the name of the target language. For example, python:foo perl:foo.
-@@ -750,7 +750,7 @@ example.i:5. Previous declaration is foo_i(int )
@@ -806,7 +806,7 @@ For example, the exception code above is simply stored without any modifications.
-@@ -928,7 +928,7 @@ public : The role of these functions is described shortly.
-@@ -941,7 +941,7 @@ internal data structures, it may be useful to keep XML in the back of your mind as a model.
-@@ -987,7 +987,7 @@ typedef Hash Typetab; -
@@ -1128,7 +1128,7 @@ Returns the number of replacements made (if any). -
@@ -1205,7 +1205,7 @@ Returns the list of hash table keys. -
@@ -1294,7 +1294,7 @@ If t is not a standard object, it is assumed to be a char * and is used to create a String object. -
-int Close(String_or_FILE *f) +There's no explicit function to close a file, just call Delete(f) - +this decreases the reference count, and the file will be closed when the +reference count reaches zero.
-Closes a file. Has no effect on strings.
-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.
-@@ -1782,7 +1779,7 @@ the attribute is optional. Swig_restore() must always be called after function. -
@@ -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.
-@@ -1892,7 +1889,7 @@ make the final type, the two parts are just joined together using string concatenation.
-@@ -2061,7 +2058,7 @@ Returns the prefix of a type. For example, if ty is ty is unmodified. -
@@ -2148,7 +2145,7 @@ Checks if ty is a varargs type. Checks if ty is a templatized type. -
@@ -2250,7 +2247,7 @@ Fully reduces ty according to typedef rules. Resulting datatype will consist only of primitive typenames. -
@@ -2287,7 +2284,7 @@ Literal y; // type = 'Literal', ltype='p.char' -
@@ -2349,7 +2346,7 @@ SWIG, but is most commonly associated with type-descriptor objects that appear in wrappers (e.g., SWIGTYPE_p_double). -
@@ -2448,7 +2445,7 @@ included. Used to emit prototypes. Returns the number of required (non-optional) arguments in p. -
@@ -2463,7 +2460,7 @@ describes the creation of a minimal Python module. You should be able to extra this to other languages.
-@@ -2473,7 +2470,7 @@ the parsing of command line options, all aspects of code generation are controll different methods of the Language that must be defined by your module.
-@@ -2581,7 +2578,7 @@ that activates your module. For example, swig -python foo.i. The messages from your new module should appear.
-@@ -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.
-@@ -2689,7 +2686,7 @@ an implementation file python.cxx and a configuration file python.swg.
-@@ -2747,7 +2744,7 @@ int Python::top(Node *n) { -
@@ -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) -
@@ -3203,7 +3199,7 @@ Discuss the kinds of functions typically needed for SWIG runtime support (e.g. the SWIG files that implement those functions.
-@@ -3222,7 +3218,7 @@ The following are the minimum that are usually supported: Please copy these and modify for any new language.
-@@ -3251,7 +3247,7 @@ during this process, see the section on .
-@@ -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.
-@@ -3350,10 +3346,10 @@ Note that if a runtime test is available, a message "(with run test)" is display
$ 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)
@@ -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" -
+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 make check-errors-test-suite. +The test cases used and the way it works is described in Examples/test-suite/errors/Makefile.in. +
+ +@@ -3528,7 +3530,7 @@ Some topics that you'll want to be sure to address include: if available. -
@@ -3585,7 +3587,7 @@ should be added should there be an area not already covered by the existing tests.
-@@ -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.
-@@ -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 swig -help.
-@@ -4044,7 +4046,7 @@ extern "X" { ... } declaration. -
diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html index 7a55a4364..93b87a4a4 100644 --- a/Doc/Manual/Go.html +++ b/Doc/Manual/Go.html @@ -5,7 +5,7 @@
-@@ -55,7 +55,7 @@ there is no convenient way to call C++ code. SWIG fills this gap.
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.
-@@ -76,11 +76,11 @@ default SWIG will generate code for the gc compilers. To generate code for gccgo, you should also use the -gccgo option.
--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:
@@ -94,9 +94,9 @@ swig -go -help-soname option passed to the linker.-soname option passed to the linker. Using this
+ option implies the -use-shlib option.
+When generating Go code, SWIG will generate the following @@ -165,28 +174,59 @@ may be helpful to include it in your code, compiled with the usual C or C++ compiler.
-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. +
+ ++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:
% 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 +
+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: +
+ ++% 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
@@ -196,7 +236,7 @@ modifications have to occur. This section briefly covers the essential aspects of this wrapping.
-@@ -206,7 +246,7 @@ directive. You may override this by using SWIG's -package command line option.
-@@ -238,7 +278,7 @@ followed by that name, and the destructor will be named Delete followed by that name.
-@@ -246,7 +286,7 @@ C/C++ constants created via #define or the %constant directive become Go constants, declared with a const declaration. -
@@ -256,7 +296,7 @@ usual). The values of the enumeration will become variables in Go; code should avoid modifying those variables.
-@@ -334,7 +374,7 @@ returns a go interface. If the returned pointer can be null, you can check for this by calling the Swigcptr() method.
-@@ -346,7 +386,7 @@ Doing the reverse will require an explicit type assertion, which will be checked dynamically.
-@@ -354,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 %template directive. -
@@ -397,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++.
-@@ -454,12 +494,12 @@ uses a given C/C++ type.
Because of limitations in the way output arguments are processed in swig, @@ -557,7 +597,7 @@ void f(char *output); -
Often the APIs generated by swig are not very natural in go, especially if @@ -626,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.
-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.
+If you need to import other go packages, you can do this with
+%go_import. For example,
+%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!")
+}
+
+%}
+
+This section details guile-specific support in SWIG. -
@@ -61,7 +61,7 @@ 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. -
@@ -69,7 +69,7 @@ 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". -
Guile 1.8 and older could be interfaced using two different api's, the SCM @@ -80,7 +80,7 @@ or the GH API. The GH interface to guile is deprecated. Read more about why in 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. -
@@ -88,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 linkage. -
@@ -193,7 +193,7 @@ placed between the define-module form and the
SWIG_init via a preprocessor define to avoid symbol
clashes. For this case, however, passive linkage is available.
-
Passive linkage is just like simple linkage, but it generates an @@ -203,7 +203,7 @@ package name (see below).
You should use passive linkage rather than simple linkage when you are using multiple modules. -
SWIG can also generate wrapper code that does all the Guile module @@ -244,7 +244,7 @@ Newer Guile versions have a shorthand procedure for this:
Guile used to support an autoloading facility for object-code @@ -270,7 +270,7 @@ option, SWIG generates an exported module initialization function with an appropriate name. -
@@ -295,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.
-
@@ -307,7 +307,7 @@ complained so far.
%rename to specify the Guile name of the wrapped
functions and variables (see CHANGES).
-
@@ -399,7 +399,7 @@ constant will appear as a scheme variable. See Features and the %feature directive for info on how to apply the %feature.
-
@@ -420,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 wrong-type-arg exception is raised.
-
@@ -439,7 +439,7 @@ structure describing this type. If a generated GOOPS module has been loaded, sm the corresponding GOOPS class.
-Garbage collection is a feature of Guile since version 1.6. As SWIG now requires Guile > 1.8, @@ -453,7 +453,7 @@ is exactly like described in 23.8 Exception Handling +
@@ -479,7 +479,7 @@ mapping: The default when not specified here is to use "swig-error". See Lib/exception.i for details. -
If invoked with the command-line option For global variables, SWIG creates a single wrapper procedure
@@ -542,7 +542,7 @@ struct members, the procedures SWIG can also generate classes and generic functions for use with
@@ -688,7 +688,7 @@ Notice that <Foo> is used before it is defined. The fix is to just put th
As you can see in the example above, there are potential naming conflicts. The default exported
@@ -725,7 +725,7 @@ guile-modules. For example, The guile-modules generated above all need to be linked together. GOOPS support requires
diff --git a/Doc/Manual/Introduction.html b/Doc/Manual/Introduction.html
index a8d15a5c2..19d59a4df 100644
--- a/Doc/Manual/Introduction.html
+++ b/Doc/Manual/Introduction.html
@@ -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:
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
-
@@ -191,7 +192,7 @@ Various customisation tips and techniques using SWIG directives are covered.
The latter sections cover the advanced techniques of using typemaps for complete control of the wrapping process.
@@ -211,7 +212,7 @@ This is the commonly used method to load JNI code so your system will more than
Android uses Java JNI and also works with SWIG. Please read the Android chapter in conjunction with this one if you are targeting Android.
@@ -270,7 +271,7 @@ The following sections have further practical examples and details on how you mi
compiling and using the generated files.
@@ -307,7 +308,7 @@ swig -java -help
Their use will become clearer by the time you have finished reading this section on SWIG and Java.
@@ -322,7 +323,7 @@ They are usually in directories like this:
The exact location may vary on your machine, but the above locations are typical.
@@ -331,8 +332,8 @@ Assuming you have code you need to link to in a file called example.c,
@@ -394,7 +395,7 @@ $
If it doesn't work have a look at the following section which discusses problems loading the shared library.
@@ -481,7 +482,7 @@ The following section also contains some C++ specific linking problems and solut
@@ -492,8 +493,7 @@ compiler. For example:
@@ -543,7 +543,7 @@ You will want to produce a DLL that can be loaded by the Java Virtual Machine.
This section covers the process of using SWIG with Microsoft Visual C++ 6 although the procedure may be similar with other compilers.
In order for everything to work, you will need to have a JDK installed on your machine in order to read the JNI header files.
@@ -582,7 +582,7 @@ To run the native code in the DLL (example.dll), make sure that it is in your pa
If the library fails to load have a look at Dynamic linking problems.
@@ -641,7 +641,7 @@ Of course you may want to make changes for it to work for C++ by adding in the -
@@ -651,7 +651,7 @@ variables are wrapped with JavaBean type getters and setters and so forth.
This section briefly covers the essential aspects of this wrapping.
@@ -687,7 +687,7 @@ swig -java -package com.bloggs.swig -outdir com/bloggs/swig example.i
SWIG won't create the directory, so make sure it exists beforehand.
@@ -721,7 +721,7 @@ System.out.println(example.fact(4));
@@ -808,7 +808,7 @@ extern char *path; // Read-only (due to %immutable)
-
@@ -948,7 +948,7 @@ Or if you decide this practice isn't so bad and your own class implements ex
@@ -962,7 +962,7 @@ The final two approaches use simple integers for each enum item.
Before looking at the various approaches for wrapping named C/C++ enums, anonymous enums are considered.
@@ -1025,7 +1025,7 @@ As in the case of constants, you can access them through either the module class
@@ -1119,7 +1119,7 @@ When upgrading to JDK 1.5 or later, proper Java enums could be used instead, wit
The following section details proper Java enum generation.
@@ -1172,7 +1172,7 @@ The additional support methods need not be generated if none of the enum items h
Simpler Java enums for enums without initializers section.
@@ -1220,7 +1220,7 @@ Note that unlike typesafe enums, this approach requires users to mostly use diff
Thus the upgrade path to proper enums provided in JDK 1.5 is more painful.
@@ -1239,7 +1239,7 @@ SWIG-1.3.21 and earlier versions wrapped all enums using this approach.
The type unsafe approach is preferable to this one and this simple approach is only included for backwards compatibility with these earlier versions of SWIG.
@@ -1327,7 +1327,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return
a NULL pointer if the conversion can't be performed.
@@ -1495,7 +1495,7 @@ x.setA(3); // Modify x.a - this is the same as b.f.a
-
@@ -1558,7 +1558,7 @@ int bar = Spam.getBar();
-
@@ -1619,7 +1619,7 @@ Note that Java does not support multiple inheritance so any multiple inheritance
A warning is given when multiple inheritance is detected and only the first base class is used.
@@ -1674,7 +1674,7 @@ to hold the result and a pointer is returned (Java will release this memory
when the returned object's finalizer is run by the garbage collector).
@@ -1698,7 +1698,7 @@ For spam1 and spam4 above the Java null gets translat
The converse also occurs, that is, NULL pointers are translated into null Java objects when returned from a C/C++ function.
@@ -1813,7 +1813,7 @@ void spam(unsigned short); // Ignored
-
@@ -1856,7 +1856,7 @@ Further details on default arguments and how to restore this approach are given
@@ -1946,7 +1946,7 @@ If the resulting use of the nspace feature and hence packages results in a proxy
you will need to open up the visibility for the pointer constructor and getCPtr method from the default 'protected' to 'public' with the SWIG_JAVABODY_PROXY macro. See Java code typemaps.
@@ -1995,7 +1995,7 @@ Obviously, there is more to template wrapping than shown in this example.
More details can be found in the SWIG and C++ chapter.
@@ -2079,7 +2079,7 @@ Foo f = p.__deref__(); // Returns underlying Foo *
-
@@ -2094,7 +2094,7 @@ Finally enum classes are covered.
First, the crucial intermediary JNI class is considered.
@@ -2214,7 +2214,7 @@ If name is the same as modulename then the module class name g
from modulename to modulenameModule.
@@ -2296,7 +2296,7 @@ For example, let's change the intermediary JNI class access to just the default
All the methods in the intermediary JNI class will then not be callable outside of the package as the method modifiers have been changed from public access to default access. This is useful if you want to prevent users calling these low level functions.
@@ -2327,7 +2327,7 @@ example.egg(new Foo());
The primary reason for having the module class wrapping the calls in the intermediary JNI class is to implement static type checking. In this case only a Foo can be passed to the egg function, whereas any long can be passed to the egg function in the intermediary JNI class.
@@ -2378,7 +2378,7 @@ See The intermediary JNI class pragmas secti
@@ -2454,7 +2454,7 @@ int y = f.spam(5, new Foo());
-
@@ -2616,7 +2616,7 @@ and
@@ -2732,7 +2732,7 @@ However, true cross language polymorphism can be achieved using the 24.4.3.3 Proxy classes and garbage collection
+
@@ -2815,7 +2815,7 @@ The section on Java typemaps details how to specify
See the How to Handle Java Finalization's Memory-Retention Issues article for alternative approaches to managing memory by avoiding finalizers altogether.
@@ -2937,7 +2937,7 @@ For example:
Compatibility note: The generation of this additional parameter did not occur in versions prior to SWIG-1.3.30.
@@ -3025,7 +3025,7 @@ for (int i=0; i<100000; i++) {
-
@@ -3112,7 +3112,7 @@ public static void spam(SWIGTYPE_p_int x, SWIGTYPE_p_int y, int z) { ... }
-
@@ -3121,7 +3121,7 @@ The Enumerations section discussed these but om
The following sub-sections detail the various types of enum classes that can be generated.
@@ -3205,7 +3205,7 @@ The swigValue method is used for marshalling in the other direction.
The toString method is overridden so that the enum name is available.
@@ -3283,7 +3283,7 @@ These needn't be generated if the enum being wrapped does not have any initializ
Simpler Java enums for enums without initializers section describes how typemaps can be used to achieve this.
@@ -3314,7 +3314,7 @@ public final class Beverage {
-
@@ -3336,7 +3336,7 @@ The upshot is that C++ classes can be extended in Java and from C++ these extens
Neither C++ code nor Java code needs to know where a particular method is implemented: the combination of proxy classes, director classes, and C wrapper functions transparently takes care of all the cross-language method routing.
@@ -3404,7 +3404,7 @@ public:
-
@@ -3431,7 +3431,7 @@ If the correct implementation is in Java, the Java API is used to call the metho
@@ -3449,7 +3449,7 @@ This situation can be optimized by selectively enabling director methods (using
@@ -3514,7 +3514,7 @@ DirectorDerived::upcall_method() invoked.
-
@@ -3534,7 +3534,7 @@ Macros can be defined on the commandline when compiling your C++ code, or altern
-
@@ -3555,8 +3555,315 @@ However, if all director methods are expected to usually be overridden by Java s
The disadvantage is that invocation of director methods from C++ when Java doesn't actually override the method will require an additional call up into Java and back to C++. As such, this option is only useful when overrides are extremely common and instantiation is frequent enough that its performance is critical.
+With directors routing method calls to Java, and proxies routing them
+to C++, the handling of exceptions is an important concern.
+The default behavior from SWIG 3.0
+onwards is to convert the thrown Java exception into a SWIG defined
+
+Converting Java exceptions into C++ exceptions can be done in two different ways using
+the
+This approach allows a flexible mapping of Java exceptions thrown by director methods into
+C++ exceptions expected by a C++ caller. There
+need not be any C++ exception specifications on the C++ method. The
+utility function
+Using the above approach to
+write handlers for a large number of methods will require
+repetitive duplication of the
+The "directorthrows" typemap is then used in conjunction with the
+ The code generated using the
+Consider the following director method:
+
+When combined with the default
+Note: Beware of using exception specifications as the SWIG director methods
+will be generated with the same exception specifications and if the
+director method throws an exception that is not specified it is likely
+to terminate your program. See the C++ standard for more details.
+Using the %catches feature instead to define the handled exceptions does not suffer
+this potential fate.
+ Because the default code generation maps any unhandled Java exceptions to
+ Alternatively an exception compatible with the existing director
+method exception specifications can be thrown. Assuming that all
+methods allow std::runtime_error to be thrown,
+the In more complex situations, a separate Below is a complete example demonstrating the use
+of the "directorthrows" typemaps. In this example, a
+generic "directorthrows" typemap is appropriate for all three exceptions - all
+take single string constructors. If the exceptions had different constructors,
+it would be neccessary to have separate typemaps for each exception type.
+
+
+
+
+In this case the three different "directorthrows" typemaps will be used
+to generate the three different exception handlers for
+ Note that the "directorthrows" typemaps are important
+only if it is important for the the exceptions passed through the C++
+layer to be mapped to distinct C++ exceptions. If director methods
+are being called by C++ code that is itself wrapped in a
+SWIG generated Java wrapper and access is always through this wrapper,
+the default
+See the Exception handling with %exception and %javaexception
+section for more on converting C++ exceptions to Java exceptions.
+
@@ -3652,7 +3959,7 @@ class MyProtectedBase extends ProtectedBase
-
@@ -3664,7 +3971,7 @@ be awkward. This section describes some common SWIG features that are used
to improve the interface to existing C/C++ code.
@@ -3730,7 +4037,7 @@ hard to implement. It is possible to improve on this using Java code, typemaps,
customization features as covered in later sections, but sometimes helper functions are a quick and easy solution to difficult cases.
@@ -3793,7 +4100,7 @@ Vector(2,3,4)
in any way---the extensions only show up in the Java interface.
@@ -3952,7 +4259,7 @@ to raise exceptions. See the SWIG Library ch
The typemap example Handling C++ exception specifications as Java exceptions provides further exception handling capabilities.
@@ -3978,7 +4285,7 @@ protected static void protect_me() {
-
@@ -3988,7 +4295,7 @@ strings and arrays. This chapter discusses the common techniques for
solving these problems.
@@ -4162,7 +4469,7 @@ void foo(Bar *OUTPUT);
will not have the intended effect since typemaps.i does not define an OUTPUT rule for Bar.
@@ -4228,7 +4535,7 @@ System.out.println("3 + 4 = " + result);
See the SWIG Library chapter for further details.
@@ -4295,7 +4602,7 @@ Please be aware that the typemaps in this library are not efficient as all the e
There is an alternative approach using the SWIG array library and this is covered in the next section.
@@ -4440,7 +4747,7 @@ well suited for applications in which you need to create buffers,
package binary data, etc.
@@ -4484,7 +4791,7 @@ len: 5 data: 68 69 0 6a 6b
-
@@ -4601,7 +4908,7 @@ model and use these functions in place of malloc and free in your own
code.
@@ -4622,7 +4929,7 @@ Before proceeding, it should be stressed that typemaps are not a required
part of using SWIG---the default wrapping behavior is enough in most cases.
Typemaps are only used if you want to change some aspect of the generated code.
-
@@ -4774,7 +5081,7 @@ However, the mappings allow the full range of values for each C type from Java.
@@ -4789,7 +5096,7 @@ So in summary, the C/C++ pointer to non-primitive types is cast into the 64 bit
The Java type is either the proxy class or type wrapper class.
@@ -4802,7 +5109,7 @@ Unfortunately it won't of course hold true for JNI code.
@@ -4925,7 +5232,7 @@ int c = example.count('e',"Hello World");
-
@@ -5185,7 +5492,7 @@ These are listed below:
-
@@ -5231,7 +5538,7 @@ The "javain" typemap has the optional 'pre', 'post' and 'pgcppname' attributes.
Note that when the 'pre' or 'post' attributes are specified and the associated type is used in a constructor, a constructor helper function is generated. This is necessary as the Java proxy constructor wrapper makes a call to a support constructor using a this call. In Java the this call must be the first statement in the constructor body. The constructor body thus calls the helper function and the helper function instead makes the JNI call, ensuring the 'pre' code is called before the JNI call is made. There is a Date marshalling example showing 'pre', 'post' and 'pgcppname' attributes in action.
@@ -5367,7 +5674,7 @@ can be wrapped with the Java equivalent, that is, static inner proxy classes.
-$jniinput, $javacall and $packagepath
@@ -5419,7 +5726,7 @@ If you do not intend your code to be targeting both C and C++ then your typemaps
@@ -5657,7 +5964,7 @@ to make the method and constructor public:
-
@@ -5701,6 +6008,10 @@ is the package name passed from the SWIG command line and %typemap(directorthrows)
+Conversion of Java exceptions to C++ exceptions in director method's exception handling.
+This typemap is expected to test the $error special variable for a matching Java exception
+and if successful convert and throw it into a C++ exception given by the typemap's type.
+The
+The example below converts a Java
+The utility function %typemap(javapackage)
@@ -5893,7 +6238,7 @@ the SWIG library.
@@ -5972,7 +6317,7 @@ This would be done by using the original versions of these typemaps in "enums.sw
@@ -6097,7 +6442,7 @@ We could alternatively have used %rename to rename what() into
@@ -6252,7 +6597,7 @@ If we were a martyr to the JNI cause, we could replace the succinct code within
If we had, we would have put it in the "in" typemap which, like all JNI and Java typemaps, also supports the 'throws' attribute.
@@ -6396,7 +6741,7 @@ Lastly the "jni", "jtype" and "jstype" typemaps are also required to specify
what Java types to use.
@@ -6478,7 +6823,7 @@ example.foo(new String[]{"red", "green", "blue", "white"});
-
@@ -6524,7 +6869,7 @@ int spam(double a, double b, double *out1, double *out2) {
*out1 = a*10.0;
*out2 = b*100.0;
return status;
-};
+}
%}
/*
@@ -6596,7 +6941,7 @@ $ java runme
1 12.0 340.0
-
@@ -6802,7 +7147,7 @@ SWIG usually generates code which constructs the proxy classes using Java code a
Note that the JNI code above uses a number of string lookups to call a constructor, whereas this would not occur using byte compiled Java code.
@@ -6846,7 +7191,7 @@ System.out.println("foo1? " + foo1.equals(foo2));
-
@@ -6905,7 +7250,7 @@ This example contains some useful functionality which you may want in your code.
@@ -7085,7 +7430,7 @@ The C functional interface has been completely morphed into an object-oriented i
the Butler class would behave much like any pure Java class and feel more natural to Java users.
@@ -7208,7 +7553,7 @@ public class Bike {
Note the addReference call.
@@ -7324,7 +7669,7 @@ The 'javacode' typemap simply adds in the specified code into the Java proxy cla
-
@@ -7501,7 +7846,7 @@ A few things to note:
-
@@ -7682,10 +8027,10 @@ public abstract class UserVisibleFoo extends Foo {
@@ -7741,7 +8086,7 @@ public class Barmy {
-
@@ -7802,7 +8147,7 @@ All destructors have to be called manually for example the delete_Foo(foo)
@@ -7852,7 +8197,7 @@ This directive is only really useful if you want to mix your own hand crafted JN
@@ -7873,7 +8218,7 @@ However, you will have to be careful about memory management and make sure that
This method normally calls the C++ destructor or free() for C code.
@@ -7895,7 +8240,7 @@ The -verbose:jni and -verbose:gc are also useful options for monitoring code beh
diff --git a/Doc/Manual/Javascript.html b/Doc/Manual/Javascript.html
new file mode 100644
index 000000000..fc24e29c7
--- /dev/null
+++ b/Doc/Manual/Javascript.html
@@ -0,0 +1,976 @@
+
+
+ This chapter describes SWIG's support of Javascript. It does not cover SWIG basics, but only information that is specific to this module. Javascript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. Its arguably the most popular language for web development.
+Javascript has gone beyond being a browser-based scripting language and with node.js, it is also used as a backend development language. Native Javascript extensions can be used for applications that embed a web-browser view or that embed a Javascript engine (such as node.js). Extending a general purpose web-browser is not possible as this would be a severe security issue. SWIG Javascript currently supports JavascriptCore, the Javascript engine used by WebKit is a modern browser implementation available as open-source which can be embedded into an application.
+With node-webkit there is a platform which uses Google's Suppose that you defined a SWIG module such as the following: To build a Javascript module, run SWIG using the If building a C++ extension, add the -c++ option: This creates a C/C++ source file The name of the wrapper file is derived from the name of the input file. For example, if the input file is and for v8:
+Note: be aware that The configuration for tests and examples currently supports Linux and Mac only and not MinGW (Windows) yet. The default interpreter is Running the examples with JavascriptCore requires Running with Examples can be run using The test-suite can be run using At the moment, the Javascript generators pass all tests syntactically, i.e., the generated source code compiles. However, there are still remaining runtime issues. Default optional arguments do not work for all targeted interpreters Multiple output arguments do not work for JSC C89 incompatibily: the JSC generator might still generate C89 violating code Javascript callbacks are not supported The primary development environment has been Linux (Ubuntu 12.04). Windows and OSX have been tested sporadically. Therefore, the generators might have more issues on those platforms. Please report back any problem you observe to help us improving this module quickly. This chapter gives a short introduction how to use a native Javascript extension: as a To install As You have to install it using First create the wrapper using SWIG: Then run This will create a A more detailed explanation is given in the Examples section. This error happens when Webkit is pre-installed on OSX and available as a library for GTK. There is general information about programming with WebKit on Apple Developer Documentation. Details about An integration of a native extension 'example' would look like this: There is general information about programming GTK at GTK documentation and in the GTK tutorial, and for Webkit there is a Webkit GTK+ API Reference. An integration of a native extension 'example' would look like this: To get started with Similar to
+A simple example would have the following structure:
+
+The configuration file essentially conforms to
+
+The
+
+As known from
+ Some basic examples are shown here in more detail. The common example To make this available as a node extension a Then From a 'nodejs` application the extension would be used like this: First the module Note: ECMAScript 5, the currently implemented Javascript standard, does not have modules. The common example A In Javascript it can be used as follows: Running these commands in an interactive node shell results in the following output:
+Note: In ECMAScript 5 there is no concept for classes. Instead each function can be used as a constructor function which is executed by the 'new' operator. Furthermore, during construction the key property The Javascript Module implementation has taken a very different approach compared to other language modules in order to support different Javascript interpreters. The Javascript module is implemented in All generated code is created on the basis of code templates. The templates for JavascriptCore can be found in To track the originating code template for generated code you can run which wraps generated code with a descriptive comment The Template class is used like this: A code template is registered with the JSEmitter via The Javascript module delegates code generation to a The module calls The methods In For storing information during the AST traversal the emitter provides a When entering a scope, such as in State information can be retrieved using Applications with an embedded JavascriptCore should be able to present detailed exception messages that occur in the Javascript engine. Below is an example derived from code provided by Brian Barnes on how these exception details can be extracted. It would be used in the following way:
@@ -90,7 +91,7 @@ Set the environment variable to hold an alternative library directory.
The directories that are searched are displayed when using -verbose commandline option.
@@ -102,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.
@@ -318,7 +319,7 @@ In this example, the function int_to_uint() would be used to cast type
Note: When working with simple pointers, typemaps can often be used to provide more seamless operation.
@@ -496,7 +497,7 @@ you should consider using a special array object rather than a bare pointer.
used with types of char or char *.
@@ -657,7 +658,7 @@ Now, in a script:
@@ -759,7 +760,7 @@ char *cdata_name(type* ptr, int nitems)
Clearly they are unsafe.
@@ -779,7 +780,7 @@ morality. The modules in this section provide basic functionality
for manipulating raw C strings.
@@ -820,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.
@@ -862,7 +863,7 @@ In the wrapper function, the passed string will be expanded to a pointer and len
The (char *STRING, int LENGTH) multi-argument typemap is also available in addition to (char *STRING, size_t LENGTH).
@@ -903,7 +904,7 @@ however, you may need to provide your own "newfree" typemap for other types.
See Object ownership and %newobject for more details.
@@ -1363,7 +1364,7 @@ structure or class instead.
-
@@ -1383,6 +1384,7 @@ The following table shows which C++ classes are supported and the equivalent SWI
-procdoc
@@ -514,7 +514,7 @@ like this:
typemap argument doc. See Lib/guile/typemaps.i for
details.
-23.10 Procedures with setters
+24.10 Procedures with setters
(struct-member-get
pointer) and (struct-member-set pointer
value) are not generated.
-23.11 GOOPS Proxy Classes
+24.11 GOOPS Proxy Classes
%import "foo.h" before the %inline block.
23.11.1 Naming Issues
+24.11.1 Naming Issues
23.11.2 Linking
+24.11.2 Linking
24 SWIG and Java
+25 SWIG and Java
@@ -87,6 +87,7 @@
24.1 Overview
+25.1 Overview
24.2 Preliminaries
+25.2 Preliminaries
24.2.1 Running SWIG
+25.2.1 Running SWIG
24.2.2 Additional Commandline Options
+25.2.2 Additional Commandline Options
24.2.3 Getting the right header files
+25.2.3 Getting the right header files
24.2.4 Compiling a dynamic module
+25.2.4 Compiling a dynamic module
$ swig -java example.i
-$ gcc -c example_wrap.c -I/usr/java/include -I/usr/java/include/solaris
-$ gcc -c example.c
+$ gcc -fPIC -c example_wrap.c -I/usr/java/include -I/usr/java/include/solaris
+$ gcc -fPIC -c example.c
$ ld -G example_wrap.o example.o -o libexample.so
24.2.5 Using your module
+25.2.5 Using your module
24.2.6 Dynamic linking problems
+25.2.6 Dynamic linking problems
24.2.7 Compilation problems and compiling with C++
+25.2.7 Compilation problems and compiling with C++
% swig -c++ -java example.i
% g++ -c -fpic example.cxx
-% g++ -c -fpic example_wrap.cxx -I/usr/java/j2sdk1.4.1/include -I/usr/java/
-j2sdk1.4.1/include/linux
+% g++ -c -fpic example_wrap.cxx -I/usr/java/j2sdk1.4.1/include -I/usr/java/j2sdk1.4.1/include/linux
% g++ -shared example.o example_wrap.o -o libexample.so
24.2.8 Building on Windows
+25.2.8 Building on Windows
24.2.8.1 Running SWIG from Visual Studio
+25.2.8.1 Running SWIG from Visual Studio
24.2.8.2 Using NMAKE
+25.2.8.2 Using NMAKE
24.3 A tour of basic C/C++ wrapping
+25.3 A tour of basic C/C++ wrapping
24.3.1 Modules, packages and generated Java classes
+25.3.1 Modules, packages and generated Java classes
24.3.2 Functions
+25.3.2 Functions
24.3.3 Global variables
+25.3.3 Global variables
24.3.4 Constants
+25.3.4 Constants
24.3.5 Enumerations
+25.3.5 Enumerations
24.3.5.1 Anonymous enums
+25.3.5.1 Anonymous enums
24.3.5.2 Typesafe enums
+25.3.5.2 Typesafe enums
24.3.5.3 Proper Java enums
+25.3.5.3 Proper Java enums
24.3.5.4 Type unsafe enums
+25.3.5.4 Type unsafe enums
24.3.5.5 Simple enums
+25.3.5.5 Simple enums
24.3.6 Pointers
+25.3.6 Pointers
24.3.7 Structures
+25.3.7 Structures
24.3.8 C++ classes
+25.3.8 C++ classes
24.3.9 C++ inheritance
+25.3.9 C++ inheritance
24.3.10 Pointers, references, arrays and pass by value
+25.3.10 Pointers, references, arrays and pass by value
24.3.10.1 Null pointers
+25.3.10.1 Null pointers
24.3.11 C++ overloaded functions
+25.3.11 C++ overloaded functions
24.3.12 C++ default arguments
+25.3.12 C++ default arguments
24.3.13 C++ namespaces
+25.3.13 C++ namespaces
24.3.14 C++ templates
+25.3.14 C++ templates
24.3.15 C++ Smart Pointers
+25.3.15 C++ Smart Pointers
24.4 Further details on the generated Java classes
+25.4 Further details on the generated Java classes
24.4.1 The intermediary JNI class
+25.4.1 The intermediary JNI class
24.4.1.1 The intermediary JNI class pragmas
+25.4.1.1 The intermediary JNI class pragmas
24.4.2 The Java module class
+25.4.2 The Java module class
24.4.2.1 The Java module class pragmas
+25.4.2.1 The Java module class pragmas
24.4.3 Java proxy classes
+25.4.3 Java proxy classes
24.4.3.1 Memory management
+25.4.3.1 Memory management
24.4.3.2 Inheritance
+25.4.3.2 Inheritance
25.4.3.3 Proxy classes and garbage collection
24.4.3.4 The premature garbage collection prevention parameter for proxy class marshalling
+25.4.3.4 The premature garbage collection prevention parameter for proxy class marshalling
24.4.3.5 Single threaded applications and thread safety
+25.4.3.5 Single threaded applications and thread safety
24.4.4 Type wrapper classes
+25.4.4 Type wrapper classes
24.4.5 Enum classes
+25.4.5 Enum classes
24.4.5.1 Typesafe enum classes
+25.4.5.1 Typesafe enum classes
24.4.5.2 Proper Java enum classes
+25.4.5.2 Proper Java enum classes
24.4.5.3 Type unsafe enum classes
+25.4.5.3 Type unsafe enum classes
24.5 Cross language polymorphism using directors
+25.5 Cross language polymorphism using directors
24.5.1 Enabling directors
+25.5.1 Enabling directors
24.5.2 Director classes
+25.5.2 Director classes
24.5.3 Overhead and code bloat
+25.5.3 Overhead and code bloat
24.5.4 Simple directors example
+25.5.4 Simple directors example
24.5.5 Director threading issues
+25.5.5 Director threading issues
24.5.6 Director performance tuning
+25.5.6 Director performance tuning
25.5.7 Java exceptions from directors
-24.6 Accessing protected members
+
+DirectorException C++ exception.
+SWIG 2.0 and earlier versions didn't provide any mechanism to handle the Java director method exceptions in C++.
+director:except feature.
+In the simplest approach, a code block is attached to each director method to
+handle the mapping of Java exceptions into C++ exceptions.
+
+%feature("director:except") MyClass::method(int x) {
+ jthrowable $error = jenv->ExceptionOccurred();
+ if ($error) {
+ jenv->ExceptionClear();
+ if (Swig::ExceptionMatches(jenv, $error, "java/lang/IndexOutOfBoundsException"))
+ throw std::out_of_range(Swig::JavaExceptionMessage(jenv, $error).message());
+ if (Swig::ExceptionMatches(jenv, $error, "$packagepath/MyJavaException"))
+ throw MyCppException(Swig::JavaExceptionMessage(jenv, $error).message());
+ throw std::runtime_error("Unexpected exception thrown in MyClass::method");
+ }
+}
+
+class MyClass {
+ /** Throws either a std::out_of_range or MyCppException on error */
+ void method(int x);
+}
+
+Swig::ExceptionMatches
+and class Swig::JavaExceptionMessage are provided to simplify
+writing code for wrappers that use the director:except feature. The
+function Swig::ExceptionMatches matches the type of the
+jthrowable thrown against a fully qualified JNI style class
+name, such as "java/lang/IOError". If the throwable class is the same
+type, or derives from the given type, Swig::ExceptionMatches will return true. Care must be taken to
+provide the correct fully qualified name, since for wrapped exceptions the
+generated proxy class will have additional package qualification, depending on
+the '-package' argument and use of the nspace
+ feature. The special variable $error is expanded by SWIG into a unique variable name and
+should be used for the
+assignment of the exception that occurred. The special variable $packagepath is
+replaced by the outer package provided for SWIG generation by the -package
+option. The utility class Swig::JavaExceptionMessage is a holder
+providing access to the message from the thrown Java exception.
+The message() method returns the exception message as a const char *,
+which is only valid during the lifetime of the holder. Any code using this message
+needs to copy it, for example into a std::string or a newly constructed C++ exception.
+director:except feature code.
+To mitigate this, an alternative approach is provided via typemaps in a
+fashion analagous to
+the "throws" typemap. The
+"throws" typemap provides an approach to automatically map all the C++
+exceptions listed in a method's defined exceptions (either from
+a C++ exception specification or a %catches
+feature) into Java exceptions.
+The "directorthrows" typemap provides the inverse mapping and should contain
+code to convert a suitably matching Java exception into a C++ exception.
+The example below converts a Java java.lang.IndexOutOfBoundsException exception
+to the typemap's type, that is std::out_of_range:
+
+
+%typemap(directorthrows) std::out_of_range %{
+ if (Swig::ExceptionMatches(jenv, $error, "java/lang/IndexOutOfBoundsException")) {
+ throw std::out_of_range(Swig::JavaExceptionMessage(jenv, $error).message());
+ }
+%}
+
+director:except feature if the $directorthrowshandlers special variable
+is used in the feature code. Consider the following, which also happens to be the default:
+
+%feature("director:except") %{
+ jthrowable $error = jenv->ExceptionOccurred();
+ if ($error) {
+ jenv->ExceptionClear();
+ $directorthrowshandlers
+ throw Swig::DirectorException(jenv, $error);
+ }
+%}
+
+director:except feature
+replaces the $directorthrowshandlers special variable with the code in
+the "directorthrows" typemaps, for each and every exception defined for the method.
+The possible exceptions can be defined either with a C++ exception
+specification or %catches as described for the
+"throws" typemap.
+
+ ...
+ virtual void doSomething(int index) throw (std::out_of_range);
+ ...
+
+director:except feature and the "directorthrows" typemap above,
+the resulting code generated in the director method after calling up to Java will be:
+
+jthrowable swigerror = jenv->ExceptionOccurred();
+if (swigerror) {
+ jenv->ExceptionClear();
+ if (Swig::ExceptionMatches(jenv, swigerror, "java/lang/IndexOutOfBoundsException")) {
+ throw std::out_of_range(Swig::JavaExceptionMessage(jenv, swigerror).message());
+ }
+
+ throw Swig::DirectorException(jenv, swigerror);
+}
+
+Swig::DirectorException, any director methods that have exception
+specifications may cause program termination. To simply ignore
+unexpected exceptions, the default handling can be changed with:
+
+%feature("director:except") %{
+ jthrowable $error = jenv->ExceptionOccurred();
+ if ($error) {
+ jenv->ExceptionClear();
+ $directorthrowshandlers
+ return $null; // exception is ignored
+ }
+%}
+
+return $null; could be changed to:
+
+ throw std::runtime_error(Swig::JavaExceptionMessage(jenv, $error).message());
+
+director:except feature
+may need to be attached to specific methods.
+
+%module(directors="1") example
+
+%{
+ #include <string>
+ #include <stdexcept>
+%}
+
+// Define exceptions in header section using std::runtime_error
+%define DEFINE_EXCEPTION(NAME)
+%{
+ namespace MyNS {
+ struct NAME : public std::runtime_error { NAME(const std::string &what) : runtime_error(what) {} };
+ }
+%}
+%enddef
+
+// Expose C++ exceptions as Java Exceptions by changing the Java base class and providing a getMessage()
+%define DECLARE_EXCEPTION(NAME)
+%typemap(javabase) MyNS::NAME "java.lang.Exception";
+%rename(getMessage) MyNS::NAME::what;
+namespace MyNS {
+ struct NAME {
+ NAME(const std::string& what);
+ const char * what();
+ };
+}
+%enddef
+
+DEFINE_EXCEPTION(ExceptionA)
+DEFINE_EXCEPTION(ExceptionB)
+DEFINE_EXCEPTION(Unexpected)
+
+// Mark three methods to map director thrown exceptions.
+%feature("director:except") MyClass::meth1(int);
+%feature("director:except") MyClass::meth2;
+%feature("director:except") meth3;
+
+%typemap(directorthrows) MyNS::ExceptionA, MyNS::ExceptionB, MyNS::Unexpected %{
+ if (Swig::ExceptionMatches(jenv, $error, "$packagepath/$javaclassname"))
+ throw $1_type(Swig::JavaExceptionMessage(jenv, $error).message());
+%}
+
+DECLARE_EXCEPTION(ExceptionA)
+DECLARE_EXCEPTION(ExceptionB)
+DECLARE_EXCEPTION(Unexpected)
+
+%catches(MyNS::ExceptionA, MyNS::ExceptionB, MyNS::Unexpected) MyClass::meth2();
+
+%inline {
+ class MyClass {
+ public:
+ virtual void meth1(int x) throw(MyNS::ExceptionA, MyNS::ExceptionB) = 0;
+ virtual void meth2() = 0; /* throws MyNS::ExceptionA, MyNS::ExceptionB, MyNS::Unexpected */
+ virtual void meth3(float x) throw(MyNS::Unexpected) = 0;
+ virtual ~MyClass() {}
+ };
+}
+
+meth1, meth2 and meth3. The generated
+handlers will have "if" blocks for each exception type specified, in
+the exception specification or %catches feature.
+Swig::DirectorException class provides enough information
+to reconstruct the original exception. In this case removing the
+$directorthrowshandlers special variable from the
+default director:except feature and simply always
+throwing a Swig::DirectorException will achieve the desired result.
+Along with this a generic exception feature is added to convert any
+caught Swig::DirectorExceptions back into the underlying
+Java exceptions via the Swig::DirectorException::raiseJavaException method,
+as demonstrated with %javaexception below:
+
+%javaexception("Exception") MyClass::myMethod %{
+ try {
+ $action
+ } catch (Swig::DirectorException &e) {
+ // raise/throw the Java exception that originally caused the DirectorException
+ e.raiseJavaException(jenv);
+ return $null;
+ }
+%}
+
+25.6 Accessing protected members
24.7 Common customization features
+25.7 Common customization features
24.7.1 C/C++ helper functions
+25.7.1 C/C++ helper functions
24.7.2 Class extension with %extend
+25.7.2 Class extension with %extend
24.7.3 Exception handling with %exception and %javaexception
+25.7.3 Exception handling with %exception and %javaexception
24.7.4 Method access with %javamethodmodifiers
+25.7.4 Method access with %javamethodmodifiers
24.8 Tips and techniques
+25.8 Tips and techniques
24.8.1 Input and output parameters using primitive pointers and references
+25.8.1 Input and output parameters using primitive pointers and references
24.8.2 Simple pointers
+25.8.2 Simple pointers
24.8.3 Wrapping C arrays with Java arrays
+25.8.3 Wrapping C arrays with Java arrays
24.8.4 Unbounded C Arrays
+25.8.4 Unbounded C Arrays
24.8.5 Binary data vs Strings
+25.8.5 Binary data vs Strings
24.8.6 Overriding new and delete to allocate from Java heap
+25.8.6 Overriding new and delete to allocate from Java heap
24.9 Java typemaps
+25.9 Java typemaps
24.9.1 Default primitive type mappings
+25.9.1 Default primitive type mappings
24.9.2 Default typemaps for non-primitive types
+25.9.2 Default typemaps for non-primitive types
24.9.3 Sixty four bit JVMs
+25.9.3 Sixty four bit JVMs
24.9.4 What is a typemap?
+25.9.4 What is a typemap?
24.9.5 Typemaps for mapping C/C++ types to Java types
+25.9.5 Typemaps for mapping C/C++ types to Java types
24.9.6 Java typemap attributes
+25.9.6 Java typemap attributes
24.9.7 Java special variables
+25.9.7 Java special variables
+$error, $jniinput, $javacall and $packagepath
These special variables are used in the directors typemaps. See Director specific typemaps for details.
24.9.8 Typemaps for both C and C++ compilation
+25.9.8 Typemaps for both C and C++ compilation
24.9.9 Java code typemaps
+25.9.9 Java code typemaps
24.9.10 Director specific typemaps
+25.9.10 Director specific typemaps
$javaclassname
If the -package commandline option is not used to specify the package, then '$packagepath/' will be removed from the resulting output JNI field descriptor.
Do not forget the terminating ';' for JNI field descriptors starting with 'L'.
If the ';' is left out, Java will generate a "method not found" runtime error.
+Note that the $packagepath substitution always uses the path separator '/' when expanded.
+The $javaclassname expansion can be confusing as it is normally expanded using the '.' separator.
+However, $javaclassname is expanded using the path separator '/' in typemap's "descriptor" attribute
+as well as in the "directorthrows" typemap.
$error special variable is of type jthrowable and is
+substituted with a unique variable name in the generated code.
+java.lang.IndexOutOfBoundsException exception
+to the typemap's type, that is std::out_of_range:
+
+%typemap(directorthrows) std::out_of_range %{
+ if (Swig::ExceptionMatches(jenv, $error, "java/lang/IndexOutOfBoundsException")) {
+ throw std::out_of_range(Swig::JavaExceptionMessage(jenv, $error).message());
+ }
+%}
+
+Swig::ExceptionMatches
+and class Swig::JavaExceptionMessage are helpers available when using directors and are described
+in the Java Exceptions from Directors section.
+24.10 Typemap Examples
+25.10 Typemap Examples
24.10.1 Simpler Java enums for enums without initializers
+25.10.1 Simpler Java enums for enums without initializers
24.10.2 Handling C++ exception specifications as Java exceptions
+25.10.2 Handling C++ exception specifications as Java exceptions
24.10.3 NaN Exception - exception handling for a particular type
+25.10.3 NaN Exception - exception handling for a particular type
24.10.4 Converting Java String arrays to char **
+25.10.4 Converting Java String arrays to char **
24.10.5 Expanding a Java object to multiple arguments
+25.10.5 Expanding a Java object to multiple arguments
24.10.6 Using typemaps to return arguments
+25.10.6 Using typemaps to return arguments
24.10.7 Adding Java downcasts to polymorphic return types
+25.10.7 Adding Java downcasts to polymorphic return types
24.10.8 Adding an equals method to the Java classes
+25.10.8 Adding an equals method to the Java classes
24.10.9 Void pointers and a common Java base class
+25.10.9 Void pointers and a common Java base class
24.10.10 Struct pointer to pointer
+25.10.10 Struct pointer to pointer
24.10.11 Memory management when returning references to member variables
+25.10.11 Memory management when returning references to member variables
24.10.12 Memory management for objects passed to the C++ layer
+25.10.12 Memory management for objects passed to the C++ layer
24.10.13 Date marshalling using the javain typemap and associated attributes
+25.10.13 Date marshalling using the javain typemap and associated attributes
24.11 Living with Java Directors
+25.11 Living with Java Directors
24.12 Odds and ends
+25.12 Odds and ends
-24.12.1 JavaDoc comments
+25.12.1 JavaDoc comments
24.12.2 Functional interface without proxy classes
+25.12.2 Functional interface without proxy classes
24.12.3 Using your own JNI functions
+25.12.3 Using your own JNI functions
24.12.4 Performance concerns and hints
+25.12.4 Performance concerns and hints
24.12.5 Debugging
+25.12.5 Debugging
24.13 Java Examples
+25.13 Java Examples
26 SWIG and Javascript
+
+
+
+26.1 Overview
+
+
+Safari/Webkit, and v8, which is used by Chromium and node.js.Chromium as Web-Browser widget and node.js for javascript extensions.
+26.2 Preliminaries
+
+
+26.2.1 Running SWIG
+
+
+
+%module example
+%{
+#include "example.h"
+%}
+int gcd(int x, int y);
+extern double Foo;
+-javascript option and a desired target engine -jsc, -v8, or -node. The generator for node is essentially delegating to the v8 generator and adds some necessary preprocessor definitions.
+$ swig -javascript -jsc example.i
+
+$ swig -c++ -javascript -jsc example.i
+example_wrap.c or example_wrap.cxx. The generated C source file contains the low-level wrappers that need to be compiled and linked with the rest of your C/C++ application to create an extension module.example.i, the name of the wrapper file is example_wrap.c. To change this, you can use the -o option. The wrapped module will export one function which must be called to register the module with the Javascript interpreter. For example, if your module is named example the corresponding initializer for JavascriptCore would be
+bool example_initialize(JSGlobalContextRef context, JSObjectRef *exports)
+
+void example_initialize(v8::Handle<v8::Object> exports)
+v8 has a C++ API, and thus, the generated modules must be compiled as C++.
+26.2.2 Running Tests and Examples
+
+
+node.js as it is available on all platforms and convenient to use.libjavascriptcoregtk-1.0 to be installed, e.g., under Ubuntu with
+$ sudo apt-get install libjavascriptcoregtk-1.0-dev
+V8 requires libv8:
+$ sudo apt-get install libv8-dev
+
+$ make check-javascript-examples ENGINE=jsc
+ENGINE can be node, jsc, or v8.
+$ make check-javascript-test-suite ENGINE=jsc
+26.2.3 Known Issues
+
+
+
+
+
+long long is not supported%native is not supportedinstanceOf does not work under JSC26.3 Integration
+
+
+node.js module, and as an extension for an embedded Webkit.26.3.1 Creating node.js Extensions
+
+
+node.js you can download an installer from their web-site for OSX and Windows. For Linux you can either build the source yourself and run sudo checkinstall or keep to the (probably stone-age) packaged version. For Ubuntu there is a PPA available.
+$ sudo add-apt-repository ppa:chris-lea/node.js
+$ sudo apt-get update
+$ sudo apt-get install nodejs
+v8 is written in C++ and comes as a C++ library it is crucial to compile your module using the same compiler flags as used for building v8. To make things easier, node.js provides a build tool called node-gyp.npm:
+$ sudo npm install -g node-gyp
+node-gyp expects a configuration file named binding.gyp which is basically in JSON format and conforms to the same format that is used with Google's build-tool gyp.binding.gyp:
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
+
+$ swig -javascript -node -c++ example.cxx
+node-gyp
+$ node-gyp
+build folder containing the native module. To use the extension you need to 'require' it in your Javascript source file:
+require("./build/Release/example")
+26.3.1.1 Troubleshooting
+
+
+
+
+gyp is installed as a distribution package. It seems to be outdated. Removing it resolves the problem.
+$ sudo apt-get remove gyp
+26.3.2 Embedded Webkit
+
+
+26.3.2.1 OSX
+
+
+Cocoa programming are not covered here.
+#import "appDelegate.h"
+
+extern bool example_initialize(JSGlobalContextRef context, JSObjectRef* exports);
+
+
+@implementation ExampleAppDelegate
+
+@synthesize webView;
+
+- (void)addGlobalObject:(JSContextRef) context:(NSString *)objectName:(JSObjectRef) theObject {
+ JSObjectRef global = JSContextGetGlobalObject(context);
+ JSStringRef objectJSName = JSStringCreateWithCFString( (CFStringRef) objectName )
+ if ( objectJSName != NULL ) {
+ JSObjectSetProperty(context, global, objectJSName, theObject, kJSPropertyAttributeReadOnly, NULL);
+ JSStringRelease( objectJSName );
+ }
+}
+
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
+
+ // Start a webview with the bundled index.html file
+ NSString *path = [[NSBundle mainBundle] bundlePath];
+ NSString *url = [NSString stringWithFormat: @"file://%@/Contents/Assets/index.html", path];
+
+ WebFrame *webframe = [webView mainFrame];
+ JSGlobalContextRef context = [webframe globalContext];
+
+ JSObjectRef example;
+ example_initialize(context, &example);
+ [self addGlobalObject:context:@"example":example]
+
+ JSObjectSetProperty(context, global, JSStringRef propertyName, example, JSPropertyAttributes attributes, NULL);
+
+ [ [webView mainFrame] loadRequest:
+ [NSURLRequest requestWithURL: [NSURL URLWithString:url] ]
+ ];
+}
+
+@end
+26.3.2.2 GTK
+
+
+
+#include <gtk/gtk.h>
+#include <webkit/webkit.h>
+
+extern bool example_initialize(JSGlobalContextRef context);
+
+int main(int argc, char* argv[])
+{
+ // Initialize GTK+
+ gtk_init(&argc, &argv);
+
+ ...
+
+ // Create a browser instance
+ WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
+ WebFrame *webframe = webkit_web_view_get_main_frame(webView);
+ JSGlobalContextRef context = webkit_web_frame_get_global_context(webFrame);
+ JSObjectRef global = JSContextGetGlobalObject(context);
+
+ JSObjectRef exampleModule;
+ example_initialize(context, &exampleModule);
+ JSStringRef jsName = JSStringCreateWithUTF8CString("example");
+ JSObjectSetProperty(context, global, jsName, exampleModule, kJSPropertyAttributeReadOnly, NULL);
+ JSStringRelease(jsName);
+
+ ...
+
+ // Load a web page into the browser instance
+ webkit_web_view_load_uri(webView, "http://www.webkitgtk.org/");
+
+ ...
+
+ // Run the main GTK+ event loop
+ gtk_main();
+
+ return 0;
+}
+26.3.3 Creating Applications with node-webkit
+
+
+node-webkit there is a very informative set of wiki pages.node.js, node-webkit is started from command line within a node.js project directory.
+Native extensions are created in the very same way as for node.js, except that a customized gyp derivate has to be used: nw-gyp.
+
+- package.json
+- app.html
+- app.js
+- node_modules
+ / example
+ ... (as known from node.js)
+
+node.js syntax.
+It has some extras to configure node-webkit. See the Manifest specification for more details.
+package.json:
+
+{
+ "name": "example"
+ "main": "app.html"
+ "window": {
+ "show": true,
+ "width": 800,
+ "height": 600
+ }
+}
+'main' property of package.json specifies a web-page to be rendered in
+the main window.app.html:
+
+<html>
+ <head>
+ <script src="app.js"></script>
+ </head>
+ <body>
+ <div>
+ The greatest common divisor of
+ <span id="x"></span> and
+ <span id="y"></span> is
+ <span id="z"></span>.
+ </div>
+ </body>
+</html>
+node.js one can use require to load javascript modules.
+Additionally, node-webkit provides an API that allows to manipulate the window's menu,
+open new windows, and many more things.
+app.js:
+window.onload = function() {
+ var example = require("example");
+ var x = 18;
+ var y = 24;
+ var z = example.gcd(x,y);
+ document.querySelector('#x').innerHTML = x;
+ document.querySelector('#y').innerHTML = y;
+ document.querySelector('#z').innerHTML = z;
+};
+26.4 Examples
+
+
+26.4.1 Simple
+
+
+simple looks like this:
+/* File : example.i */
+%module example
+
+%inline %{
+extern int gcd(int x, int y);
+extern double Foo;
+%}
+binding.gyp has to be created:
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
+node-gyp is used to build the extension:
+$ node-gyp configure build
+
+// import the extension via require
+var example = require("./build/Release/example");
+
+// calling the global method
+var x = 42;
+var y = 105;
+var g = example.gcd(x,y);
+
+// Accessing the globak variable
+var f = example.Foo;
+example.Foo = 3.1415926;
+example is loaded from the previously built extension. Global methods and variables are available in the scope of the module.node.js and other implementations provide this mechanism defined by the CommonJS group. For browsers this is provided by Browserify, for instance.26.4.2 Class
+
+
+class defines three classes, Shape, Circle, and Square:
+class Shape {
+public:
+ Shape() {
+ nshapes++;
+ }
+ virtual ~Shape() {
+ nshapes--;
+ };
+ double x, y;
+ void move(double dx, double dy);
+ virtual double area(void) = 0;
+ virtual double perimeter(void) = 0;
+ static int nshapes;
+};
+
+class Circle : public Shape {
+private:
+ double radius;
+public:
+ Circle(double r) : radius(r) { };
+ virtual double area(void);
+ virtual double perimeter(void);
+};
+
+class Square : public Shape {
+private:
+ double width;
+public:
+ Square(double w) : width(w) { };
+ virtual double area(void);
+ virtual double perimeter(void);
+};
+Circle and Square inherit from Shape. Shape has a static variable nshapes, a function move that can't be overridden (non-virtual), and two abstract functions area and perimeter (pure virtual) that must be overridden by the sub-classes.nodejs extension is built the same way as for the simple example.
+var example = require("./build/Release/example");
+
+// local aliases for convenience
+var Shape = example.Shape;
+var Circle = example.Circle;
+var Square = example.Square;
+
+// creating new instances using the 'new' operator
+var c = new Circle(10);
+var s = new Square(10);
+
+// accessing a static member
+Shape.nshapes;
+
+// accessing member variables
+c.x = 20;
+c.y = 30;
+s.x = -10;
+s.y = 5;
+
+// calling some methods
+c.area();
+c.perimeter();
+s.area();
+s.perimeter();
+
+// instantiation of Shape is not permitted
+new Shape();
+
+$ node -i
+& var example = require("./build/Release/example");
+undefined
+& var Shape = example.Shape;
+undefined
+& var Circle = example.Circle;
+undefined
+& var Square = example.Square;
+undefined
+& var c = new Circle(10);
+undefined
+& var s = new Square(10);
+undefined
+& Shape.nshapes;
+2
+& c.x = 20;
+20
+& c.y = 30;
+30
+& s.x = -10;
+-10
+& s.y = 5;
+5
+& c.area();
+314.1592653589793
+& c.perimeter();
+62.83185307179586
+& s.area();
+100
+& s.perimeter();
+40
+& c.move(40, 40)
+undefined
+& c.x
+60
+& c.y
+70
+& new Shape()
+Error: Class Shape can not be instantiated
+at repl:1:2
+at REPLServer.self.eval (repl.js:110:21)
+at Interface.<anonymous> (repl.js:239:12)
+at Interface.EventEmitter.emit (events.js:95:17)
+at Interface._onLine (readline.js:202:10)
+at Interface._line (readline.js:531:8)
+at Interface._ttyWrite (readline.js:760:14)
+at ReadStream.onkeypress (readline.js:99:10)
+at ReadStream.EventEmitter.emit (events.js:98:17)
+at emitKey (readline.js:1095:12)
+prototype of the constructor function is used to attach a prototype instance to the created object. A prototype is essentially an object itself that is the first-class delegate of a class used whenever the access to a property of an object fails. The very same prototype instance is shared among all instances of one type. Prototypal inheritance is explained in more detail on in Inheritance and the prototype chain, for instance.
+26.5 Implementation
+
+
+26.5.1 Source Code
+
+
+Source/Modules/javascript.cxx. It dispatches the code generation to a JSEmitter instance, V8Emitter or JSCEmitter. Additionally there are some helpers: Template, for templated code generation, and JSEmitterState, which is used to manage state information during AST traversal. This rough map shall make it easier to find a way through this huge source file:
+// module wide defines
+
+#define NAME "name"
+...
+
+// ###############################
+// # Helper class declarations
+
+class JSEmitterState { ... };
+
+class Template { ... };
+
+// ###############################
+// # JSEmitter declaration
+
+class JSEmitter { ... };
+
+// Emitter factory declarations
+
+JSEmitter *swig_javascript_create_JSCEmitter();
+JSEmitter *swig_javascript_create_V8Emitter();
+
+// ###############################
+// # Javascript module
+
+// Javascript module declaration
+
+class JAVASCRIPT:public Language { ... };
+
+// Javascript module implementation
+
+int JAVASCRIPT::functionWrapper(Node *n) { ... }
+...
+
+// Module factory implementation
+
+static Language *new_swig_javascript() { ... }
+
+extern "C" Language *swig_javascript(void) { ... }
+
+// ###############################
+// # JSEmitter base implementation
+
+JSEmitter::JSEmitter() { ... }
+
+Template JSEmitter::getTemplate(const String *name) { ... }
+...
+
+// ###############################
+// # JSCEmitter
+
+// JSCEmitter declaration
+
+class JSCEmitter: public JSEmitter { ... };
+
+// JSCEmitter implementation
+
+JSCEmitter::JSCEmitter() { ... }
+
+void JSCEmitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, MarshallingMode mode, bool is_member, bool is_static) { ... }
+...
+
+// JSCEmitter factory
+
+JSEmitter *swig_javascript_create_JSCEmitter() { ... }
+
+
+// ###############################
+// # V8Emitter
+
+// V8Emitter declaration
+
+class V8Emitter: public JSEmitter { ... };
+
+// V8Emitter implementation
+
+V8Emitter::V8Emitter() { ... }
+
+int V8Emitter::initialize(Node *n) { ... }
+
+// V8Emitter factory
+
+JSEmitter *swig_javascript_create_V8Emitter() { ... }
+
+
+// ###############################
+// # Helper implementation (JSEmitterState, Template)
+
+JSEmitterState::JSEmitterState() { ... }
+...
+
+Template::Template(const String *code_) { ... }
+...
+26.5.2 Code Templates
+
+
+Lib/javascript/jsc/javascriptcode.swg, for v8 in Lib/javascript/v8/javascriptcode.swg.
+$ swig -javascript -jsc -debug-codetemplates
+
+/* begin fragment("template_name") */
+
+...generated code ...
+
+/* end fragment("template_name") */
+
+Template t_register = getTemplate("jsv8_register_static_variable");
+t_register.replace("$jsparent", state.clazz(NAME_MANGLED))
+ .replace("$jsname", state.variable(NAME))
+ .replace("$jsgetter", state.variable(GETTER))
+ .replace("$jssetter", state.variable(SETTER))
+ .trim().
+ print(f_init_static_wrappers);
+fragment(name, "template"), e.g.,
+%fragment ("jsc_variable_declaration", "templates")
+%{
+ {"$jsname", $jsgetter, $jssetter, kJSPropertyAttributeNone},
+%}
+Template creates a copy of that string and Template::replace uses Swig's Replaceall to replace variables in the template. Template::trim can be used to eliminate leading and trailing whitespaces. Template::print is used to write the final template string to a Swig DOH (based on Printv). All methods allow chaining.26.5.3 Emitter
+
+
+JSEmitter instance. The following extract shows the essential interface:
+class JSEmitter {
+ ...
+
+ /**
+ * Opens output files and temporary output DOHs.
+ */
+ virtual int initialize(Node *n);
+
+ /**
+ * Writes all collected code into the output file(s).
+ */
+ virtual int dump(Node *n) = 0;
+
+ /**
+ * Cleans up all open output DOHs.
+ */
+ virtual int close() = 0;
+
+ ...
+
+ /**
+ * Invoked at the beginning of the classHandler.
+ */
+ virtual int enterClass(Node *);
+
+ /**
+ * Invoked at the end of the classHandler.
+ */
+ virtual int exitClass(Node *) {
+ return SWIG_OK;
+ };
+
+ /**
+ * Invoked at the beginning of the variableHandler.
+ */
+ virtual int enterVariable(Node *);
+
+ /**
+ * Invoked at the end of the variableHandler.
+ */
+ virtual int exitVariable(Node *) {
+ return SWIG_OK;
+ };
+
+ /**
+ * Invoked at the beginning of the functionHandler.
+ */
+ virtual int enterFunction(Node *);
+
+ /**
+ * Invoked at the end of the functionHandler.
+ */
+ virtual int exitFunction(Node *) {
+ return SWIG_OK;
+ };
+
+ /**
+ * Invoked by functionWrapper callback after call to Language::functionWrapper.
+ */
+ virtual int emitWrapperFunction(Node *n);
+
+ /**
+ * Invoked from constantWrapper after call to Language::constantWrapper.
+ **/
+ virtual int emitConstant(Node *n);
+
+ /**
+ * Registers a given code snippet for a given key name.
+ *
+ * This method is called by the fragmentDirective handler
+ * of the JAVASCRIPT language module.
+ **/
+ int registerTemplate(const String *name, const String *code);
+
+ /**
+ * Retrieve the code template registered for a given name.
+ */
+ Template getTemplate(const String *name);
+
+ State &getState();
+
+ ...
+
+}
+initialize, dump, and close from within the top method:
+int JAVASCRIPT::top(Node *n) {
+ emitter->initialize(n);
+
+ Language::top(n);
+
+ emitter->dump(n);
+ emitter->close();
+
+ return SWIG_OK;
+}
+enterClass and exitClass are called from within the classHandler method:
+int JAVASCRIPT::classHandler(Node *n) {
+
+ emitter->enterClass(n);
+ Language::classHandler(n);
+ emitter->exitClass(n);
+
+ return SWIG_OK;
+}
+enterClass the emitter stores state information that is necessary when processing class members. In exitClass the wrapper code for the whole class is generated.26.5.4 Emitter states
+
+
+JSEmitterState with different slots to store data representing the scopes global, class, function, and variable.
+class JSEmitterState {
+
+public:
+
+ JSEmitterState();
+
+ ~JSEmitterState();
+
+ DOH *global();
+
+ DOH *global(const char* key, DOH *initial = 0);
+
+ DOH *clazz(bool reset = false);
+
+ DOH *clazz(const char* key, DOH *initial = 0);
+
+ DOH *function(bool reset = false);
+
+ DOH *function(const char* key, DOH *initial = 0);
+
+ DOH *variable(bool reset = false);
+
+ DOH *variable(const char* key, DOH *initial = 0);
+
+ static int IsSet(DOH *val);
+
+ ...
+};
+enterClass, the corresponding state is reset and new data is stored:
+state.clazz(RESET);
+state.clazz(NAME, Getattr(n, "sym:name"));
+state.clazz(NAME) or with Getattr on state.clazz() which actually returns a Hash instance.26.5.5 Handling Exceptions in JavascriptCore
+
+
+
+void script_exception_to_string(JSContextRef js_context,JSValueRef exception_value_ref,char* return_error_string, int return_error_string_max_length)
+{
+ JSObjectRef exception_object;
+ JSValueRef value_ref;
+ JSStringRef jsstring_property_name = NULL;
+ JSValueRef temporary_exception = NULL;
+ JSStringRef js_return_string = NULL;
+ size_t bytes_needed;
+ char* c_result_string = NULL;
+ exception_object = JSValueToObject(js_context, exception_value_ref, NULL);
+
+ /* source url */
+ strcpy(return_error_string,"[");
+ jsstring_property_name = JSStringCreateWithUTF8CString("sourceURL");
+ value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &temporary_exception);
+ JSStringRelease(jsstring_property_name);
+ js_return_string = JSValueToStringCopy(js_context, value_ref, NULL);
+ bytes_needed = JSStringGetMaximumUTF8CStringSize(js_return_string);
+ c_result_string = (char*)calloc(bytes_needed, sizeof(char));
+ JSStringGetUTF8CString(js_return_string, c_result_string, bytes_needed);
+ JSStringRelease(js_return_string);
+ strncat(return_error_string, c_result_string, return_error_string_max_length-1);
+ free(c_result_string);
+
+ strncat(return_error_string, ":", return_error_string_max_length-1);
+
+ /* line number */
+
+ jsstring_property_name = JSStringCreateWithUTF8CString("line");
+ value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &temporary_exception);
+ JSStringRelease(jsstring_property_name);
+ js_return_string = JSValueToStringCopy(js_context, value_ref, NULL);
+ bytes_needed = JSStringGetMaximumUTF8CStringSize(js_return_string);
+ c_result_string = (char*)calloc(bytes_needed, sizeof(char));
+ JSStringGetUTF8CString(js_return_string, c_result_string, bytes_needed);
+ JSStringRelease(js_return_string);
+ strncat(return_error_string, c_result_string, return_error_string_max_length-1);
+ free(c_result_string);
+
+ strncat(return_error_string, "]", return_error_string_max_length-1);
+
+ /* error message */
+
+ jsstring_property_name = JSStringCreateWithUTF8CString("message");
+ value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &temporary_exception);
+ JSStringRelease(jsstring_property_name);
+ if(NULL == value_ref)
+ {
+ strncat(return_error_string, "Unknown Error", return_error_string_max_length-1);
+ }
+ else
+ {
+ js_return_string = JSValueToStringCopy(js_context, value_ref, NULL);
+ bytes_needed = JSStringGetMaximumUTF8CStringSize(js_return_string);
+ c_result_string = (char*)calloc(bytes_needed, sizeof(char));
+ JSStringGetUTF8CString(js_return_string, c_result_string, bytes_needed);
+ JSStringRelease(js_return_string);
+ strncat(return_error_string, c_result_string, return_error_string_max_length-1);
+ free(c_result_string);
+ }
+}
+
+if(js_exception)
+{
+ char return_error_string[256];
+ script_exception_to_string(js_context, js_exception, return_error_string, 256);
+ printf("Compile error is %s", return_error_string);
+}
+8 SWIG library
+9 SWIG library
@@ -31,6 +31,7 @@
@@ -58,7 +59,7 @@ Alternative libraries provide similar functionality. Please read this chapter
carefully if you used the old libraries.
-
8.1 The %include directive and library search path
+9.1 The %include directive and library search path
8.2 C Arrays and Pointers
+9.2 C Arrays and Pointers
8.2.1 cpointer.i
+9.2.1 cpointer.i
8.2.2 carrays.i
+9.2.2 carrays.i
8.2.3 cmalloc.i
+9.2.3 cmalloc.i
8.2.4 cdata.i
+9.2.4 cdata.i
8.3 C String Handling
+9.3 C String Handling
8.3.1 Default string handling
+9.3.1 Default string handling
8.3.2 Passing binary data
+9.3.2 Passing binary data
8.3.3 Using %newobject to release memory
+9.3.3 Using %newobject to release memory
8.3.4 cstring.i
+9.3.4 cstring.i
8.4 STL/C++ Library
+9.4 STL/C++ Library
SWIG Interface library file
@@ -1484,7 +1486,7 @@ void foo(string s, const String &t); // std_string typemaps still applie
@@ -1663,7 +1665,7 @@ if you want to make their head explode. details and the public API exposed to the interpreter vary.
-@@ -1713,13 +1715,28 @@ The %exception directive can be used by placing the following code befo Any thrown STL exceptions will then be gracefully handled instead of causing a crash.
--Some target languages have support for handling the widely used boost::shared_ptr smart pointer. -This smart pointer is also available as std::tr1::shared_ptr before it becomes fully standardized as std::shared_ptr. -The boost_shared_ptr.i library provides support for boost::shared_ptr and std_shared_ptr.i provides support for std::shared_ptr, but if the following macro is defined as shown, it can be used for std::tr1::shared_ptr: +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 std::shared_ptr. +It was also in TR1 as std::tr1::shared_ptr before it was fully standardized. +Support for the widely used boost::shared_ptr is also available. +
+ ++In order to use std::shared_ptr, the std_shared_ptr.i library file should be included: +
+ ++%include <std_shared_ptr.i> ++
+The pre-standard std::tr1::shared_ptr can be used by including the following macro before including the std_shared_ptr.i library file:
+In order to use boost::shared_ptr, the boost_shared_ptr.i library file should be included: +
+ ++%include <boost_shared_ptr.i> ++
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 %shared_ptr(T) macro, @@ -1872,12 +1899,64 @@ Adding the missing %shared_ptr macros will fix this: +
Note: There is currently no support for %shared_ptr and the director feature. - -
+While std::auto_ptr is deprecated in C++11, some existing code may +still be using it, so SWIG provides limited support for this class: +std_auto_ptr.i defines the typemaps which apply to the functions +returning objects of this type. Any other use of std_auto_ptr.i is not +directly supported. +
+ ++A typical example of use would be +
+
+%include <std_auto_ptr.i>
+
+%auto_ptr(Klass)
+%inline %{
+class Klass {
+public:
+ // Factory function creating objects of this class:
+ static std::auto_ptr<Klass> Create(int value) {
+ return std::auto_ptr<Klass>(new Klass(value));
+ }
+
+ int getValue() const { return m_value; }
+
+private:
+ DerivedIntValue(int value) : m_value(value) {}
+ int m_value;
+};
+%}
+
++The returned objects can be used naturally from the target language, e.g. from +C#: +
+ ++Klass k = Klass.Create(17); +int value = k.getValue(); ++
diff --git a/Doc/Manual/Lisp.html b/Doc/Manual/Lisp.html index 01ff3a3ec..0b8d47846 100644 --- a/Doc/Manual/Lisp.html +++ b/Doc/Manual/Lisp.html @@ -6,7 +6,7 @@
-@@ -50,7 +50,7 @@ here
-@@ -77,7 +77,7 @@ swig -cffi -module module-name file-name files and the various things which you can do with them.
-@@ -118,11 +118,11 @@ swig -cffi -help -
@@ -392,7 +392,7 @@ The feature intern_function ensures that all C names are
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. -
@@ -608,7 +608,7 @@ Note that the block %{ ... %} is effectively a shortcut for
-@@ -638,7 +638,7 @@ swig -clisp -module module-name file-name interface file for the CLISP module. The CLISP module tries to produce code which is both human readable and easily modifyable.
-
@@ -671,7 +671,7 @@ and global variables will be created otherwise only definitions for
-
@@ -795,7 +795,7 @@ struct bar {
-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'.
-@@ -128,7 +137,7 @@ $ swig -lua -eluac example.i The -elua 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 -eluac 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 -eluac. To access any value from eLua, one must directly call the wrapper function associated with that value.
-@@ -159,9 +168,17 @@ swig -lua -help
@@ -232,7 +249,7 @@ LUALIB_API int ( luaopen_mod )(lua_State *L ); More information on building and configuring eLua can be found here: http://www.eluaproject.net/doc/v0.8/en_building.html
-@@ -240,8 +257,8 @@ Most, but not all platforms support the dynamic loading of modules (Windows &
$ 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
@@ -300,7 +317,7 @@ Is quite obvious (Go back and consult the Lua documents on how to enable loadlib -
@@ -318,19 +335,19 @@ $ ./my_lua >
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.
-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.
-@@ -349,7 +366,10 @@ creates a built-in function example.fact(n) that works exactly like you >
-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.
> 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
@@ -456,7 +476,7 @@ If you have used the -eluac option for your eLua module, you will have In general, functions of the form "variable_get()" and "variable_set()" are automatically generated by SWIG for use with -eluac.
-@@ -490,7 +510,64 @@ If you're using eLua and have used -elua or -eluac to generate > print(example.const.SCONST) Hello World -
+Enums are exported into a class table. For example, given some enums: +
+%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
+};
++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: +
++> print(example.SUNDAY) +0 +> print(example.Test.TEST1) +10 +> print(example.Test.ICONST) +12 +
Enums within a C struct are in the global namespace and are used as follows from Lua
++> print(example.SUNDAY) +0 +> -- See the difference here +> print(example.TEST1) +10 +
+Compatibility Note: 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: +
++> print(example.Test_TEST1) +10 +> print(example.Test_ICONST) +12 +
+The old-style bindings are still generated in addition to the new ones. +If the -no-old-metatable-bindings option is used, then these old-style bindings are not generated. +
++It is worth mentioning, that example.Test.TEST1 and example.Test_TEST1 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. +
+@@ -528,7 +605,7 @@ Lua enforces the integrity of its userdata, so it is virtually impossible to cor nil -
@@ -551,7 +628,7 @@ is used as follows:
Similar access is provided for unions and the data members of C++ classes.
-C structures are created using a function new_Point(), but for C++ classes are created using just the name Point().
+C structures can be created using a function new_Point(), and both C structures and C++ classes can be created using just the name Point().
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 -eluac option, structure manipulation has to be perfo In general, functions of the form "new_struct()", "struct_member_get()", "struct_member_set()" and "free_struct()" are automatically generated by SWIG for each structure defined in C. (Please note: This doesn't apply for modules generated with the -elua option)
-@@ -676,12 +753,12 @@ public: };
-In Lua, the static members can be accessed as follows: +In Lua, C++ static members can be accessed as follows:
-> example.Spam_foo() -- calling Spam::foo() -> a=example.Spam_bar -- reading Spam::bar -> example.Spam_bar=b -- writing to Spam::bar +> example.Spam.foo() -- calling Spam::foo() +> a=example.Spam.bar -- reading Spam::bar +> example.Spam.bar=b -- writing to Spam::bar
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 -
+Compatibility Note: In versions prior to SWIG-3.0.0 only the following names would work: +
+ ++> example.Spam_foo() -- calling Spam::foo() +> a=example.Spam_bar -- reading Spam::bar +> example.Spam_bar=b -- writing to Spam::bar +
+Both style names are generated by default now. +However, if the -no-old-metatable-bindings option is used, then the backward compatible names are not generated in addition to ordinary ones. +
+ +@@ -717,7 +809,7 @@ then the function spam() accepts a Foo pointer or a pointer to any clas
It is safe to use multiple inheritance with SWIG.
-@@ -748,7 +840,7 @@ Foo spam7();
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.
-@@ -834,7 +926,7 @@ Please refer to the "SWIG and C++" chapter for more information about overloadin
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.
-@@ -898,10 +990,10 @@ The current list of operators which can be overloaded (and the alternative funct
+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):
+No other lua metafunction is inherited. For example, __gc is not inherited and must be redefined in every class. __tostring is subject to a special handling. If absent in class and in class bases, a default one will be provided by SWIG. +
+@@ -981,7 +1095,7 @@ Now we extend it with some new code return tmp; } bool operator==(const Complex& c) - { return ($self->re()==c.re() && $self->im()==c.im();} + { return ($self->re()==c.re() && $self->im()==c.im());} };
@@ -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).
-If you have a function that allocates memory like this,
@@ -1026,7 +1140,7 @@ char *foo();This will release the allocated memory.
-@@ -1061,7 +1175,7 @@ In Lua:
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.
-
@@ -1113,7 +1227,7 @@ If you ever need to access the underlying pointer returned by operator->(
> f = p:__deref__() -- Returns underlying Foo *
-26.3.16 C++ Exceptions
+28.3.16 C++ Exceptions
@@ -1256,13 +1370,164 @@ and the "Exception handling add exception specification to functions or globally (respectively).
++Since SWIG-3.0.0 C++ namespaces are supported via the %nspace feature. +
+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: +
+%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; }
+ };
+ }
+}
++Now, from Lua usage is as follows: +
+ ++> print(example.module_function()) +7 +> print(example.module_variable) +9 +> print(example.MyWorld.World():create_world()) +17 +> print(example.MyWorld.World.world_max_count) +9 +> print(example.MyWorld.Nested.Dweller.MALE) +0 +> print(example.MyWorld.Nested.Dweller.count()) +19 +> +
+If SWIG is running in a backwards compatible way, i.e. without the -no-old-metatable-bindings option, then additional old-style names are generated (notice the underscore): +
++9 +> print(example.MyWorld.Nested.Dweller_MALE) +0 +> print(example.MyWorld.Nested.Dweller_count()) +11 +> +
If SWIG is launched without -no-old-metatable-bindings 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 $classname_$symbolname 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.
+Consider the following C++ code
+%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;
+}
+When in backward compatible mode, in addition to the usual names, the following ones will be generated (notice the underscore):
++9 +> print(example.MyWorld.Test_TEST1) -- Test has %nspace enabled +10 +> print(example.MyWorld.Test_ICONST) -- Test has %nspace enabled +12 +> print(example.Test2_TEST3) -- Test2 doesn't have %nspace enabled +20 +> print(example.Test2_ICONST2) -- Test2 doesn't have %nspace enabled +23 +> +
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:
++> print(example.TEST3) -- NOT Test2_TEST3 +20 +> +
The internal organization of inheritance has changed. +Consider the following C++ code:
+%module example
+class Base {
+ public:
+ int base_func()
+};
+class Derived : public Base {
+ public:
+ int derived_func()
+}
+Lets assume for a moment that class member functions are stored in .fn table. Previously, when classes +were exported to Lua during module initialization, for every derived class all service tables ST(i.e. ".fn") +were squashed and added to corresponding derived class ST: Everything from .fn table of class Base +was copied to .fn 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.
+That means that any changes done to class Base after module initialization wouldn't affect class Derived:
++base = example.Base() +der = example.Derived() +> print(base.base_func) +function: 0x1367940 +> getmetatable(base)[".fn"].new_func = function (x) return x -- Adding new function to class Base (to class, not to an instance!) +> print(base.new_func) -- Checking this function +function +> print(der.new_func) -- Wouldn't work. Derived doesn't check Base any more. +nil +> +
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. +
+> print(der.new_func) -- Now it works +function +> +
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
-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:
@@ -1290,7 +1555,7 @@ Received an integer : 6 720 -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.
@@ -1343,7 +1608,7 @@ void swap(int *sx, int *sy);Note: C++ references must be handled exactly the same way. However SWIG will automatically wrap a const int& as an input parameter (since that it obviously input).
-Arrays present a challenge for SWIG, because like pointers SWIG does not know whether these are input or output values, nor @@ -1407,7 +1672,7 @@ and Lua tables to be 1..N, (the indexing follows the norm for the language). In
Note: SWIG also can support arrays of pointers in a similar manner.
-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:
@@ -1441,7 +1706,7 @@ int Create_Math(iMath** pptr); // its creator (assume it mallocs) ptr=nil -- the iMath* will be GC'ed as normal -This section describes how you can modify SWIG's default wrapping behavior for various C/C++ datatypes using the %typemap directive. This is an advanced topic that assumes familiarity with the Lua C API as well as the material in the "Typemaps" chapter.
@@ -1450,7 +1715,7 @@ ptr=nil -- the iMath* will be GC'ed as normalBefore 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).
-There are many different types of typemap that can be written, the full list can be found in the "Typemaps" chapter. However the following are the most commonly used ones.
@@ -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).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.
@@ -1512,7 +1777,7 @@ This macro, when called within the context of a SWIG wrapped function, will disp@@ -1521,7 +1786,7 @@ This section covers adding of some small extra bits to your module to add the la -
@@ -1540,7 +1805,7 @@ int native_function(lua_State*L) // my native code The %native directive in the above example, tells SWIG that there is a function int native_function(lua_State*L); which is to be added into the module under the name 'my_func'. 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.
-@@ -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.
-@@ -1589,7 +1854,7 @@ See Examples/lua/arrays for an example of this code.
-@@ -1649,7 +1914,7 @@ end
That way when you call 'a=example.Foo', 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 'example.Foo=10', 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)'.
-@@ -1729,7 +1994,7 @@ Note: Both the opaque structures (like the FILE*) and normal wrapped classes/str
Note: Operator overloads are basically done in the same way, by adding functions such as '__add' & '__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.
-diff --git a/Doc/Manual/Makefile b/Doc/Manual/Makefile index 42149ba3a..5112afa33 100644 --- a/Doc/Manual/Makefile +++ b/Doc/Manual/Makefile @@ -75,4 +75,3 @@ linkchecker: @echo Note linkchecker versions prior to 6.1 do not work properly wrt anchors @echo ----------------------------------------------------------------------- linkchecker --config=./linkchecker.config index.html - diff --git a/Doc/Manual/Modula3.html b/Doc/Manual/Modula3.html index 065313fa2..ffbf6132d 100644 --- a/Doc/Manual/Modula3.html +++ b/Doc/Manual/Modula3.html @@ -5,7 +5,7 @@
--This chapter describes SWIG's support of +This chapter describes SWIG's support for Modula-3. You should be familiar with the basics @@ -54,7 +54,7 @@ especially typemaps.
-@@ -84,7 +84,7 @@ FFTW -
@@ -109,7 +109,7 @@ into exceptions.
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.
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.
-@@ -283,7 +283,7 @@ and the principal type must be renamed (%typemap).
-@@ -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.
-@@ -400,7 +400,7 @@ For testing examples I use Critical Mass cm3.
-@@ -477,10 +477,10 @@ Instead generate templates for some basic typemaps. -
@@ -694,7 +694,7 @@ consist of the following parts: -
@@ -746,7 +746,7 @@ that I'd like to automate.
-@@ -759,7 +759,7 @@ is not really useful, yet.
-@@ -792,7 +792,7 @@ IMPORT M3toC;
@@ -816,7 +816,7 @@ you should declare %typemap("m3wrapinconv:throws") blah * %{OSError.E%}.
-@@ -863,10 +863,10 @@ where almost everything is generated by a typemap: -
@@ -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.
-@@ -130,7 +130,7 @@ public:
To create the wrapper properly, module derived_module needs to know about the base class and that its interface is covered in another module. The -line %import "base_module.i" lets SWIG know exactly that. Oftentimes +line %import "base_module.i" lets SWIG know exactly that. Often the .h file is passed to %import instead of the .i, 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.
-@@ -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.
-As described in The run-time type checker, @@ -279,7 +279,7 @@ SWIG_TYPE_TABLE to be the same as the module whose types you are trying to access.
-@@ -290,7 +290,7 @@ into it. This is very often NOT 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.
-@@ -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.
-diff --git a/Doc/Manual/Mzscheme.html b/Doc/Manual/Mzscheme.html index 3b49a2974..fadda5fc9 100644 --- a/Doc/Manual/Mzscheme.html +++ b/Doc/Manual/Mzscheme.html @@ -8,7 +8,7 @@
-@@ -166,7 +166,7 @@ Some points of interest:
diff --git a/Doc/Manual/Ocaml.html b/Doc/Manual/Ocaml.html index 127be904d..aa6679f9a 100644 --- a/Doc/Manual/Ocaml.html +++ b/Doc/Manual/Ocaml.html @@ -6,7 +6,7 @@
-@@ -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.
-@@ -122,7 +122,7 @@ you will compile the file example_wrap.c with ocamlc or the resulting .ml and .mli files as well, and do the final link with -custom (not needed for native link).
-@@ -158,12 +158,12 @@ the user more freedom with respect to custom typing.
The camlp4 module (swigp4.ml -> 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 "swig -ocaml -co swigp4.ml". You should compile the file with @@ -234,7 +234,7 @@ let b = C_string (getenv "PATH") -
@@ -248,7 +248,7 @@ When linking any ocaml bytecode with your module, use the -custom option is not needed when you build native code.
-@@ -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.
-@@ -310,7 +310,7 @@ type c_obj =
@@ -394,7 +394,7 @@ it describes the output SWIG will generate for class definitions. -
@@ -457,7 +457,7 @@ val x : Enum_test.c_obj = C_enum `a
@@ -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.
-@@ -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.
-@@ -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.
-@@ -521,7 +521,7 @@ Consider writing an object when the ending condition of your array is complex, such as using a required sentinel, etc.
-@@ -572,7 +572,7 @@ void printfloats( float *tab, int len ); -
@@ -615,7 +615,7 @@ the underlying pointer, so using create_[x]_from_ptr alters the returned value for the same object.
-@@ -695,7 +695,7 @@ baz # -
@@ -725,7 +725,7 @@ public: }; -
@@ -743,7 +743,7 @@ bash-2.05a$ ocamlmktop -custom swig.cmo -I `camlp4 -where` \ -L$QTPATH/lib -cclib -lqt
@@ -770,10 +770,10 @@ Assuming you have a working installation of QT, you will see a window containing the string "hi" in a button. -29.2.5 Director Classes
+31.2.5 Director Classes
-29.2.5.1 Director Introduction
+31.2.5.1 Director Introduction
@@ -800,7 +800,7 @@ class foo { };
@@ -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.
-The "arginit" typemap is used to set the initial value of a @@ -2794,7 +2802,7 @@ applications. For example:
} -The "default" typemap is used to turn an argument into a @@ -2819,7 +2827,7 @@ arguments that follow must have default values. See the 36.7.6.6 "check" typemap +
The "check" typemap is used to supply value checking code @@ -2834,7 +2842,7 @@ arguments have been converted. For example:
} -The "argout" typemap is used to return values from arguments. @@ -2888,7 +2896,7 @@ some function like SWIG_Ruby_AppendOutput.
See the typemaps.i library for examples.
-The "freearg" typemap is used to cleanup argument data. It is @@ -2915,7 +2923,7 @@ This code is also placed into a special variable $cleanup that may be used in other typemaps whenever a wrapper function needs to abort prematurely.
-The "newfree" typemap is used in conjunction with the %newobject @@ -2939,7 +2947,7 @@ string *foo();
See Object ownership and %newobject for further details.
-The "memberin" typemap is used to copy data from an @@ -2957,21 +2965,21 @@ example:
already provides a default implementation for arrays, strings, and other objects. -The "varin" typemap is used to convert objects in the target language to C for the purposes of assigning to a C/C++ global variable. This is implementation specific.
-The "varout" typemap is used to convert a C/C++ object to an object in the target language when reading a C/C++ global variable. This is implementation specific.
-The "throws" typemap is only used when SWIG parses a C++ @@ -3012,7 +3020,7 @@ specification yet they do throw exceptions, SWIG cannot know how to deal with them. For a neat way to handle these, see the Exception handling with %exception section.
-Converts C++ objects in director @@ -3071,7 +3079,7 @@ referring to the class itself. -
Converts Ruby objects in director @@ -3144,7 +3152,7 @@ exception.
-Output argument processing in director @@ -3202,19 +3210,19 @@ referring to the instance of the class itself -
Cleanup of function return values
-Setting of C global variables
-@@ -3264,7 +3272,7 @@ so that their values can be properly assigned.
When you write a typemap, you usually have to work directly @@ -3279,7 +3287,7 @@ stick to the swig functions instead of the native Ruby functions. That should help you avoid having to rewrite a lot of typemaps across multiple languages.
-Here, while the Ruby versions return the value directly, the SWIG @@ -3389,7 +3397,7 @@ versions do not, but return a status value to indicate success (SWIG_OK -
RSTRING_LEN(str)
@@ -3412,7 +3420,7 @@ versions do not, but return a status value to indicate success (SWIG_OK void rb_raise(VALUE exception, const char *fmt,
@@ -3491,7 +3499,7 @@ message to standard error if Ruby was invoked with the -w
flag. The given format string fmt and remaining
arguments are interpreted as with printf().
-36.7.8.5 Iterators
+38.7.8.5 Iterators
void rb_iter_break()
@@ -3537,14 +3545,14 @@ VALUE), VALUE value)This section includes a few examples of typemaps. For more examples, you might look at the examples in the Example/ruby directory.
-A common problem in many C programs is the processing of @@ -3609,7 +3617,7 @@ array. Since dynamic memory allocation is used to allocate memory for the array, the "freearg" typemap is used to later release this memory after the execution of the C function.
-Ruby's solution to the "keyword arguments" capability of some @@ -3823,7 +3831,7 @@ memory leak. Fortunately, this typemap is a lot easier to write:
program that uses the extension, can be found in the Examples/ruby/hashargs directory of the SWIG distribution. -Occasionally, it might be necessary to convert pointer values @@ -3882,7 +3890,7 @@ For example:
} - VALUE Data_Wrap_Struct(VALUE class, void
@@ -3909,7 +3917,7 @@ as above.
type c-type from the data object obj
and assigns that pointer to ptr.
-36.7.13 Example: STL Vector to Ruby Array
+38.7.13 Example: STL Vector to Ruby Array
Another use for macros and type maps is to create a Ruby array @@ -4001,7 +4009,7 @@ STL with ruby, you are advised to use the standard swig STL library, which does much more than this. Refer to the section called the C++ Standard Template Library. -
@@ -4035,7 +4043,7 @@ generate ri documentation from a c wrap file, you could do:
$ rdoc -r file_wrap.c -@@ -4065,7 +4073,7 @@ layout of controls on a panel, etc. to be loaded from an XML file." %module(docstring=DOCSTRING) xrc -
Since SWIG does know everything about the function it wraps, @@ -4086,7 +4094,7 @@ several options for autodoc controlled by the value given to the feature, described below.
-@@ -4110,7 +4118,7 @@ Then Ruby code like this will be generated: ... -
@@ -4130,7 +4138,7 @@ this: ... -
@@ -4142,7 +4150,7 @@ parameter types with the "2" option will result in Ruby code like this:
-@@ -4163,7 +4171,7 @@ Parameters: bar - Bar -
@@ -4179,7 +4187,7 @@ generated string. For example: void GetPosition(int* OUTPUT, int* OUTPUT); -
@@ -4190,10 +4198,10 @@ docstring associated with classes, function or methods are output. If an item already has an autodoc string then it is combined with the docstring and they are output together.
-SWIG allows operator overloading with, by using the %extend @@ -4374,7 +4382,7 @@ separate method for handling inequality since Ruby parses the expression a != b as !(a == b).
- The chapter on Working
@@ -4500,7 +4508,7 @@ irb(main):005:0> c.getX()
5.0
- The Ruby language doesn't support multiple inheritance, but
@@ -4567,7 +4575,7 @@ matching rules used for other kinds of features apply (see the chapter
on "Customization
Features") for more details). One of the most common issues in generating SWIG bindings for
@@ -4590,7 +4598,7 @@ to C++ (or vice versa) depending on what function or methods are
invoked. Clearly, developing a SWIG wrapper requires a thorough
understanding of how the underlying library manages memory. Ruby uses a mark and sweep garbage collector. When the garbage
@@ -4622,7 +4630,7 @@ any memory has been allocated in creating the underlying C struct or
C++ struct, then a "free" function must be defined that deallocates
this memory. As described above, memory management depends on clearly
@@ -4682,7 +4690,7 @@ public:
C++ constructor, thus creating a new foo object.
By default, SWIG will assign the new Ruby object a "free" function.
When the Ruby object is garbage collected, the "free" function will be
-called. It in turn will call Foo's destructor.36.9.3 Specifying Mixin Modules
+38.9.3 Specifying Mixin Modules
36.10 Memory Management
+38.10 Memory Management
36.10.1 Mark and Sweep Garbage Collector
+38.10.1 Mark and Sweep Garbage Collector
36.10.2 Object Ownership
+38.10.2 Object Ownership
Next, consider this code:
@@ -4767,7 +4775,7 @@ public:This code can be seen in swig/examples/ruby/tracking.
-The remaining parts of this section will use the class library @@ -4992,7 +5000,7 @@ However, if you implement your own free functions (see below) you may also have to call the SWIG_RubyRemoveTracking and RubyUnlinkObjects methods.
-With a bit more testing, we see that our class library still @@ -5121,7 +5129,7 @@ irb(main):016:0>
This code can be seen in swig/examples/ruby/mark_function.
-By default, SWIG creates a "free" function that is called when @@ -5288,7 +5296,7 @@ been freed, and thus raises a runtime exception.
This code can be seen in swig/examples/ruby/free_function.
-As has been said, the Ruby GC runs and marks objects before diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index f9ea5b2ef..bd929f7d4 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -224,7 +224,7 @@ $ swig -c++ -python -o example_wrap.cpp example.i
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.
-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 -outdir option. For example: @@ -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.
-#define F_CONST (double) 5 // A floating pointer constant with cast +#define F_CONST (double) 5 // A floating point constant with cast
The %constant 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, %constant 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 char *, 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.
@@ -1483,7 +1483,7 @@ void transpose(double (*a)[20]);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.
@@ -1888,11 +1888,22 @@ and a more descriptive one, but the two functions are otherwise equivalent: pattern part is a regular expression in Perl syntax (as supported by the Perl Compatible Regular Expressions (PCRE)) library and the subst string - can contain back-references introduced by '\' or, as backslashes need - to be escaped in C strings, rather by "\\". For example, to remove - any alphabetic prefix before an underscore you could use the following directive: - %rename("regex:/(\\w+)_(.*)/\\2/") -
Notice that when the function is used as a callback, special names -such as add_cb is used instead. To call the function +such as add_cb are used instead. To call the function normally, just use the original function name such as add().
@@ -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 : @@ -2423,7 +2434,7 @@ vector_struct, SWIG knows that this is the same as Structures involving character strings require some care. SWIG assumes that all members of type char * have been dynamically allocated using malloc() 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 :
@@ -2508,7 +2519,7 @@ typedef struct Bar {
When a structure member is wrapped, it is handled as a pointer, unless the %naturalvar directive
is used where it is handled more like a C++ reference (see C++ Member data).
-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:
@@ -2645,8 +2656,8 @@ struct Bar { // Default constructor generated.
-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 %nodefaultdtor
@@ -2676,7 +2687,7 @@ has now been enabled as the default behavior.
Note: There are also the -nodefault option and
%nodefault 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.
@@ -3269,7 +3280,7 @@ initialization on module loading, you could write this:
-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.
@@ -3284,9 +3295,9 @@ of steps you can follow to make an interface for a C program :
- 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.
- Create a new interface file to describe the scripting language
@@ -3331,7 +3342,7 @@ to the swig-devel mailing list or to
-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 :
@@ -3425,7 +3436,7 @@ include certain header files by using a %{,%} block like this:
#include <GL/glu.h>
%}
-// Put rest of declarations here
+// Put the rest of the declarations here
...
@@ -3467,7 +3478,7 @@ program that is more interactive. In many cases, the old
or Tcl script.
-Note: If some cases, you might be inclined to create a
+Note: In some cases, you might be inclined to create a
scripting language wrapper for main(). 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
diff --git a/Doc/Manual/SWIGPlus.html b/Doc/Manual/SWIGPlus.html
index 2713725d7..f9558994b 100644
--- a/Doc/Manual/SWIGPlus.html
+++ b/Doc/Manual/SWIGPlus.html
@@ -185,7 +185,6 @@ The following C++ features are not currently supported:
- Overloaded versions of certain operators (new, delete, etc.)
-
- Nested classes, see Nested classes for workarounds.
@@ -217,7 +216,7 @@ to use the C++ compiler. For example:
$ swig -c++ -tcl example.i
-$ c++ -c example_wrap.cxx
+$ c++ -fPIC -c example_wrap.cxx
$ c++ example_wrap.o $(OBJS) -o example.so
@@ -960,8 +959,9 @@ Similarly, all data attributes declared as const are wrapped as read-on
+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,
@@ -974,7 +974,8 @@ public:
-then the low-level accessor to the items member actually uses pointers. For example:
+then the low-level accessor to the items member actually uses pointers.
+For example:
@@ -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 %naturalvar directive and is used as follows:
-
-
-
-
-// All List variables will use const List& typemaps
-%naturalvar List;
-
-// Only Foo::myList will use const List& typemaps
-%naturalvar Foo::myList;
-struct Foo {
- List myList;
-};
-
-// All variables will use const reference typemaps
-%naturalvar;
-
-
-
-
-The observant reader will notice that %naturalvar works like any other
-feature flag directive,
-except it can also be attached to class types.
-The first of the example usages above show %naturalvar attaching to the List 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:
@@ -1038,15 +1015,45 @@ void Foo_items_set(Foo *self, const List &value) {
-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 %naturalvar directive is a macro for, and hence equivalent to, %feature("naturalvar"). It can be used as follows:
+
+
+
+
+// All List variables will use const List& typemaps
+%naturalvar List;
+
+// Only Foo::myList will use const List& typemaps
+%naturalvar Foo::myList;
+struct Foo {
+ List myList;
+};
+
+// All non-primitive types will use const reference typemaps
+%naturalvar;
+
+
+
+
+The observant reader will notice that %naturalvar works like any other
+feature flag directive but with some extra flexibility.
+The first of the example usages above shows %naturalvar attaching to the myList's variable type, that is the List class.
+The second usage shows %naturalvar 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.
+
+
+
+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 %naturalvar feature will apply to global variables in addition to member variables in some language modules, eg C# and Java.
-Other alternatives for turning this feature on globally are to use the swig -naturalvar commandline option
-or the module mode option, %module(naturalvar=1)
+The naturalvar behavior can also be turned on as a global setting via the -naturalvar commandline option
+or the module mode option, %module(naturalvar=1).
+However, any use of %feature("naturalvar") will override the global setting.
@@ -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.
@@ -4967,141 +4974,55 @@ public:
-There is some support for nested structs and unions when wrapping C code,
-see Nested structures 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.
-
-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 Outer class which contains a nested class Inner.
-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:
-%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::Inner;
-
-class Outer {
-public:
- class Inner {
- public:
- ...
- };
- Inner getInner();
- void useInner(const Inner& inner);
- ...
-};
-
-
-
-
-Note that if Inner 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 getInner() method above, the returned value can then be passed around, such as passed into the
-useInner() method.
-
-
-
-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 Outer class in a header file:
-
-
-
-
-// File outer.h
-class Outer {
-public:
- class Inner {
- public:
- int var;
- Inner(int v = 0) : var(v) {}
- };
- Inner getInner();
- void useInner(const Inner& inner);
-};
-
-
-
-
-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 nestedworkaround
-feature flag 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.
-
-
-
-
-// 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;
-%}
-
-The downside to this approach is a more complex interface file and having to maintain two definitions of Inner,
-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.
-
-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.
+Compatibility Note:
+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:
-
+
-// File outer.h
-class Outer {
-public:
-#ifndef SWIG
- class Inner {
- public:
- ...
- };
-#endif
- ...
-};
+example.i:8: Warning 126: The nestedworkaround feature is deprecated
-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.
-Compatibility Note: SWIG-1.3.40 and earlier versions did not have the nestedworkaround feature
+SWIG-1.3.40 and earlier versions did not have the nestedworkaround feature
and the generated code resulting from parsing nested classes did not always compile.
Nested class warnings could also not be suppressed using %warnfilter.
diff --git a/Doc/Manual/Scripting.html b/Doc/Manual/Scripting.html
index e6a2eee24..c714fa0d7 100644
--- a/Doc/Manual/Scripting.html
+++ b/Doc/Manual/Scripting.html
@@ -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 :
+have the following C++ definition :
class Vector {
@@ -334,12 +334,12 @@ Finally, in Tcl :
Vector v
-v configure -x 3 -y 4 -z 13
+v configure -x 3 -y 4 -z -13
-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.
@@ -364,21 +364,16 @@ added to it.
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:
+for a few common platforms is shown below:
# 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
-
diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html
index 195111424..bcae8139d 100644
--- a/Doc/Manual/Sections.html
+++ b/Doc/Manual/Sections.html
@@ -6,7 +6,7 @@
SWIG-3.0 Documentation
-Last update : SWIG-3.0.0 (in progress)
+Last update : SWIG-3.0.2 (4 Jun 2014)
Sections
@@ -18,6 +18,7 @@ Last update : SWIG-3.0.0 (in progress)
- Scripting
- SWIG Basics (Read this!)
- SWIG and C++
+- SWIG and C++11
- The SWIG preprocessor
- The SWIG library
- Argument handling
@@ -41,6 +42,7 @@ Last update : SWIG-3.0.0 (in progress)
- Go support
- Guile support
- Java support
+- Javascript support
- Common Lisp support
- Lua support
- Modula3 support
diff --git a/Doc/Manual/Tcl.html b/Doc/Manual/Tcl.html
index e6b3b4a43..c12701ac9 100644
--- a/Doc/Manual/Tcl.html
+++ b/Doc/Manual/Tcl.html
@@ -6,7 +6,7 @@
-37 SWIG and Tcl
+39 SWIG and Tcl
@@ -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.
-37.1 Preliminaries
+39.1 Preliminaries
@@ -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.
-37.1.1 Getting the right header files
+39.1.1 Getting the right header files
@@ -127,7 +127,7 @@ this is the case, you should probably make a symbolic link so that tcl.h
-
37.1.2 Compiling a dynamic module
+39.1.2 Compiling a dynamic module
@@ -139,8 +139,8 @@ using commands like this (shown for Linux):
$ 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
@@ -163,7 +163,7 @@ The name of the module is specified using the %module directive or the
-module command line option.
-37.1.3 Static linking
+39.1.3 Static linking
@@ -229,7 +229,7 @@ minimal in most situations (and quite frankly not worth the extra
hassle in the opinion of this author).
-37.1.4 Using your module
+39.1.4 Using your module
@@ -357,7 +357,7 @@ to the default system configuration (this requires root access and you will need
the man pages).
-37.1.5 Compilation of C++ extensions
+39.1.5 Compilation of C++ extensions
@@ -374,8 +374,8 @@ compiler. For example:
% 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
@@ -387,8 +387,8 @@ Solaris, you often need to add an extra library -lCrun like this:
% 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
@@ -440,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.
-37.1.6 Compiling for 64-bit platforms
+39.1.6 Compiling for 64-bit platforms
@@ -467,7 +467,7 @@ also introduce problems on platforms that support more than one
linking standard (e.g., -o32 and -n32 on Irix).
-37.1.7 Setting a package prefix
+39.1.7 Setting a package prefix
@@ -486,7 +486,7 @@ option will append the prefix to the name when creating a command and
call it "Foo_bar".
-37.1.8 Using namespaces
+39.1.8 Using namespaces
@@ -508,7 +508,7 @@ When the -namespace option is used, objects in the module
are always accessed with the namespace name such as Foo::bar.
-37.2 Building Tcl/Tk Extensions under Windows 95/NT
+39.2 Building Tcl/Tk Extensions under Windows 95/NT
@@ -519,7 +519,7 @@ covers the process of using SWIG with Microsoft Visual C++.
although the procedure may be similar with other compilers.
-37.2.1 Running SWIG from Developer Studio
+39.2.1 Running SWIG from Developer Studio
@@ -577,7 +577,7 @@ MSDOS > tclsh80
%
-37.2.2 Using NMAKE
+39.2.2 Using NMAKE
@@ -640,7 +640,7 @@ to get you started. With a little practice, you'll be making lots of
Tcl extensions.
-37.3 A tour of basic C/C++ wrapping
+39.3 A tour of basic C/C++ wrapping
@@ -651,7 +651,7 @@ classes. This section briefly covers the essential aspects of this
wrapping.
-37.3.1 Modules
+39.3.1 Modules
@@ -685,7 +685,7 @@ To fix this, supply an extra argument to load like this:
-37.3.2 Functions
+39.3.2 Functions
@@ -710,7 +710,7 @@ like you think it does:
%
-37.3.3 Global variables
+39.3.3 Global variables
@@ -790,7 +790,7 @@ extern char *path; // Read-only (due to %immutable)
-37.3.4 Constants and enums
+39.3.4 Constants and enums
@@ -874,7 +874,7 @@ When an identifier name is given, it is used to perform an implicit hash-table l
conversion. This allows the global statement to be omitted.
-37.3.5 Pointers
+39.3.5 Pointers
@@ -970,7 +970,7 @@ C-style cast may return a bogus result whereas as the C++-style cast will return
None if the conversion can't be performed.
-37.3.6 Structures
+39.3.6 Structures
@@ -1252,7 +1252,7 @@ Note: Tcl only destroys the underlying object if it has ownership. See the
memory management section that appears shortly.
-37.3.7 C++ classes
+39.3.7 C++ classes
@@ -1319,7 +1319,7 @@ In Tcl, the static member is accessed as follows:
-37.3.8 C++ inheritance
+39.3.8 C++ inheritance
@@ -1368,7 +1368,7 @@ For instance:
It is safe to use multiple inheritance with SWIG.
-37.3.9 Pointers, references, values, and arrays
+39.3.9 Pointers, references, values, and arrays
@@ -1422,7 +1422,7 @@ to hold the result and a pointer is returned (Tcl will release this memory
when the return value is garbage collected).
-37.3.10 C++ overloaded functions
+39.3.10 C++ overloaded functions
@@ -1545,7 +1545,7 @@ first declaration takes precedence.
Please refer to the "SWIG and C++" chapter for more information about overloading.
-37.3.11 C++ operators
+39.3.11 C++ operators
@@ -1647,7 +1647,7 @@ There are ways to make this operator appear as part of the class using the %
Keep reading.
-37.3.12 C++ namespaces
+39.3.12 C++ namespaces
@@ -1711,7 +1711,7 @@ utilizes thousands of small deeply nested namespaces each with
identical symbol names, well, then you get what you deserve.
-37.3.13 C++ templates
+39.3.13 C++ templates
@@ -1763,7 +1763,7 @@ More details can be found in the SWIG and C++
examples will appear later.
-37.3.14 C++ Smart Pointers
+39.3.14 C++ Smart Pointers
@@ -1847,7 +1847,7 @@ simply use the __deref__() method. For example:
@@ -1860,7 +1860,7 @@ of low-level details were omitted. This section provides a brief overview of how the proxy classes work.
-@@ -1925,7 +1925,7 @@ function. This allows objects to be encapsulated objects that look a lot like as shown in the last section.
-@@ -2113,7 +2113,7 @@ typemaps--an advanced topic discussed later.
-@@ -2301,7 +2301,7 @@ set c [lindex $dim 1] -
@@ -2435,7 +2435,7 @@ Since SWIG's exception handling is user-definable, you are not limited to C++ ex See the chapter on "Customization Features" for more examples.
-@@ -2452,7 +2452,7 @@ Typemaps are only used if you want to change some aspect of the primitive C-Tcl interface.
-@@ -2569,7 +2569,7 @@ parameter is omitted): -
@@ -2707,7 +2707,7 @@ Initialize an argument to a value before any conversions occur. Examples of these methods will appear shortly.
-@@ -2778,7 +2778,7 @@ properly assigned. The Tcl name of the wrapper function being created. -
@@ -2840,7 +2840,7 @@ argv[2] = Larry 3 -
@@ -2882,7 +2882,7 @@ result, a Tcl function using these typemaps will work like this : % -
@@ -2959,7 +2959,7 @@ int Tcl_IsShared(Tcl_Obj *obj); -
@@ -3043,7 +3043,7 @@ work) -
@@ -3119,7 +3119,7 @@ For example: -
@@ -3191,7 +3191,7 @@ As a final note, most SWIG examples do not yet use the to use the load command instead.
-@@ -3290,7 +3290,7 @@ danger of blowing something up (although it is easily accomplished with an out of bounds array access).
-@@ -3411,7 +3411,7 @@ short, but clever Tcl script can be combined with SWIG to do many interesting things.
-diff --git a/Doc/Manual/Typemaps.html b/Doc/Manual/Typemaps.html index 81e3fd1bb..cba524149 100644 --- a/Doc/Manual/Typemaps.html +++ b/Doc/Manual/Typemaps.html @@ -6,7 +6,7 @@
-@@ -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.
-@@ -205,7 +205,7 @@ to read the extension documentation for your favorite language to know how it works (an exercise left to the reader).
-@@ -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.
-@@ -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 $1, $2, and so forth.
-@@ -464,7 +464,7 @@ typedef int size_t; then SWIG already knows that the int typemaps apply. You don't have to do anything.
-@@ -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.
-@@ -639,7 +639,7 @@ void wrap_foo(char *s, int x) {
@@ -657,7 +657,7 @@ SWIG can also be viewed as has having a second set of aspects based around %exception are also cross-cutting concerns as they encapsulate code that can be used to add logging or exception handling to any function.
-@@ -677,14 +677,14 @@ of "The C Programming Language" by Kernighan and Ritchie or "The C++ Programming Language" by Stroustrup before going any further.
-This section describes the behavior of the %typemap directive itself.
-@@ -797,7 +797,7 @@ Admittedly, it's not the most readable syntax at first glance. However, the pur individual pieces will become clear.
-@@ -847,7 +847,7 @@ class Foo { -
@@ -905,7 +905,7 @@ The patterns for %apply follow the same rules as for %typemap. -
@@ -938,7 +938,7 @@ For example: after the clear operation.
-@@ -1018,7 +1018,7 @@ It should be noted that for scoping to work, SWIG has to know that stringclass string.
-@@ -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.
-@@ -1125,7 +1125,7 @@ void F(int x[1000]); // int [ANY] rule (typemap 5) stripped all qualifiers in one step.
-@@ -1300,7 +1300,7 @@ void go(Struct aStruct); -
@@ -1438,7 +1438,7 @@ Finally the best way to view the typemap matching rules in action is via the
-
@@ -1468,7 +1468,7 @@ but all subsequent arguments must match exactly.
@@ -1627,7 +1627,7 @@ are similar to those for specialized template handling.
@@ -1840,7 +1840,7 @@ Also the types may be displayed slightly differently - char const * and
-
@@ -1848,7 +1848,7 @@ This section describes rules by which typemap code is inserted into
the generated wrapper code.
@@ -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.
@@ -2077,7 +2077,7 @@ each type must have its own local variable declaration.
-
@@ -2329,7 +2329,7 @@ Another approach, which only works for arrays is to use the $1_basetype
-
@@ -2341,7 +2341,7 @@ it is done during the SWIG parsing/compilation stages.
The following special variable macros are available across all language modules.
@@ -2352,7 +2352,7 @@ For example, $descriptor(std::vector<int> *) will expand into Run-time type checker usage10.3.4 Multi-arguments typemaps
+11.3.4 Multi-arguments typemaps
10.3.5 Matching rules compared to C++ templates
+11.3.5 Matching rules compared to C++ templates
10.3.6 Debugging typemap pattern matching
+11.3.6 Debugging typemap pattern matching
10.4 Code generation rules
+11.4 Code generation rules
10.4.1 Scope
+11.4.1 Scope
10.4.2 Declaring new local variables
+11.4.2 Declaring new local variables
10.4.3 Special variables
+11.4.3 Special variables
10.4.4 Special variable macros
+11.4.4 Special variable macros
10.4.4.1 $descriptor(type)
+11.4.4.1 $descriptor(type)
@@ -2409,7 +2409,7 @@ The result is the following expansion -
@@ -2417,7 +2417,7 @@ The set of typemaps recognized by a language module may vary. However, the following typemap methods are nearly universal:
-@@ -2477,7 +2477,7 @@ Usually numinputs is not specified, whereupon the default value is 1, t is the same as the old "ignore" typemap.
-@@ -2503,7 +2503,7 @@ If you define new "in" typemaps and your program uses overloaded method "typecheck" typemaps. More details about this follow in the Typemaps and overloading section.
-@@ -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 Optimal code generation when returning by value section.
-@@ -2553,7 +2553,7 @@ For example: -
@@ -2586,7 +2586,7 @@ See the Default/optional arguments sec for further information on default argument wrapping.
-@@ -2605,7 +2605,7 @@ converted. For example: -
@@ -2651,7 +2651,7 @@ return values are often appended to return value of the function. See the typemaps.i library file for examples.
-@@ -2684,7 +2684,7 @@ be used in other typemaps whenever a wrapper function needs to abort prematurely.
-@@ -2713,7 +2713,7 @@ string *foo(); See Object ownership and %newobject for further details.
-@@ -2735,7 +2735,7 @@ It is rarely necessary to write "memberin" typemaps---SWIG already provides a default implementation for arrays, strings, and other objects.
-@@ -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.
-@@ -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.
-@@ -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 Exception handling with %exception section.
-@@ -2805,7 +2805,7 @@ This section contains a few examples. Consult language module documentation for more examples.
-@@ -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.
-@@ -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.
-@@ -3142,7 +3142,7 @@ The example above also shows a common approach of issuing a warning for an as ye %typemap(ruby,in) int "$1 = NUM2INT($input);".
-@@ -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 $1 is within some commented out code.
-@@ -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.
-@@ -3607,7 +3607,7 @@ See the information in the issuing warnings
-@@ -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.
-@@ -3893,7 +3893,7 @@ struct A { -
@@ -3939,7 +3939,7 @@ The interested (or very brave) reader can take a look at the fragments.swg file
-@@ -3956,7 +3956,7 @@ Requirements for the type system:
@@ -4151,7 +4151,7 @@ structures rather than creating new ones. These swig_module_info structures are chained together in a circularly linked list.
-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.
-@@ -4556,7 +4556,7 @@ Subsequent "in" typemaps would then perform more extensive type-checking. -
@@ -4642,7 +4642,7 @@ example: -
@@ -4679,7 +4679,7 @@ sure that the typemaps sharing information have exactly the same types and names
-@@ -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 self.
-diff --git a/Doc/Manual/Varargs.html b/Doc/Manual/Varargs.html index 9564fe00b..dac1ad7bc 100644 --- a/Doc/Manual/Varargs.html +++ b/Doc/Manual/Varargs.html @@ -6,7 +6,7 @@
-@@ -232,7 +232,7 @@ can also support real varargs wrapping (with stack-frame manipulation) if you are willing to get hands dirty. Keep reading.
-@@ -301,7 +301,7 @@ Read on for further solutions.
-@@ -412,7 +412,7 @@ mixed argument types such as printf(). Providing general purpose wrappers to such functions presents special problems (covered shortly).
-@@ -589,7 +589,7 @@ really want to elevate your guru status and increase your job security, continue to the next section.
-@@ -841,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.
-@@ -895,7 +895,7 @@ int my_vprintf(const char *fmt, ...) { -
@@ -964,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.
-diff --git a/Doc/Manual/Warnings.html b/Doc/Manual/Warnings.html index cf4c38d7e..99b89c425 100644 --- a/Doc/Manual/Warnings.html +++ b/Doc/Manual/Warnings.html @@ -6,7 +6,7 @@
-@@ -55,7 +55,7 @@ where the generated wrapper code will probably compile, but it may not work like you expect.
-@@ -147,7 +147,7 @@ your interface. Ignore the warning messages at your own peril.
-@@ -220,7 +220,7 @@ that is, any warnings suppressed or added in %warnfilter, #pragma S or the -w option.
-@@ -274,7 +274,7 @@ example.i:24: Warning 901: You are really going to regret this usage of blah * s
@@ -309,7 +309,7 @@ or -
@@ -326,7 +326,7 @@ no obvious recovery. There is no mechanism for suppressing error messages.
-@@ -335,7 +335,7 @@ option. This will cause SWIG to exit with a non successful exit code if a warning is encountered.
-@@ -354,10 +354,10 @@ $ swig -python -Fmicrosoft example.i example.i(4) : Syntax error in input. -
These numbers can be used by your own application.
-diff --git a/Doc/Manual/Windows.html b/Doc/Manual/Windows.html index c8467c78a..0685242ba 100644 --- a/Doc/Manual/Windows.html +++ b/Doc/Manual/Windows.html @@ -79,8 +79,8 @@ If you want to build your own swig.exe have a look at examples using Cygwin. diff --git a/Doc/Manual/chapters b/Doc/Manual/chapters index 40e227164..c5f655254 100644 --- a/Doc/Manual/chapters +++ b/Doc/Manual/chapters @@ -4,6 +4,7 @@ Windows.html Scripting.html SWIG.html SWIGPlus.html +CPlusPlus11.html Preprocessor.html Library.html Arguments.html @@ -22,6 +23,7 @@ D.html Go.html Guile.html Java.html +Javascript.html Lisp.html Lua.html Modula3.html diff --git a/Doc/Manual/index.html b/Doc/Manual/index.html index 30c69578f..fbe105a7e 100644 --- a/Doc/Manual/index.html +++ b/Doc/Manual/index.html @@ -1,10 +1,10 @@
-diff --git a/Examples/go/variables/Makefile b/Examples/go/variables/Makefile index 452ea2118..d0da605e0 100644 --- a/Examples/go/variables/Makefile +++ b/Examples/go/variables/Makefile @@ -1,16 +1,16 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = example.c +SRCS = variables.c TARGET = example INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' go clean: - $(MAKE) -f $(TOP)/Makefile INTERFACE='$(INTERFACE)' go_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' INTERFACE='$(INTERFACE)' go_clean diff --git a/Examples/go/variables/example.c b/Examples/go/variables/variables.c similarity index 97% rename from Examples/go/variables/example.c rename to Examples/go/variables/variables.c index aa4ffe9b3..05e17c8c5 100644 --- a/Examples/go/variables/example.c +++ b/Examples/go/variables/variables.c @@ -51,7 +51,7 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); + printf("cstrvar = %s\n", cstrvar); printf("iptrvar = %p\n", iptrvar); printf("name = %s\n", name); printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); diff --git a/Examples/guile/class/Makefile b/Examples/guile/class/Makefile index 8de4f292b..48426a8fb 100644 --- a/Examples/guile/class/Makefile +++ b/Examples/guile/class/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile guile_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' guile_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static_cpp clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean diff --git a/Examples/guile/class/example.cxx b/Examples/guile/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/guile/class/example.cxx +++ b/Examples/guile/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -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; } diff --git a/Examples/guile/class/example.h b/Examples/guile/class/example.h index 0d4527e92..0dff185b2 100644 --- a/Examples/guile/class/example.h +++ b/Examples/guile/class/example.h @@ -7,11 +7,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; }; @@ -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(); }; diff --git a/Examples/guile/constants/Makefile b/Examples/guile/constants/Makefile index d8a3cfebd..d3f58ebdc 100644 --- a/Examples/guile/constants/Makefile +++ b/Examples/guile/constants/Makefile @@ -1,15 +1,15 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = my-guile INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_augmented_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_augmented_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_augmented clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean diff --git a/Examples/guile/matrix/Makefile b/Examples/guile/matrix/Makefile index a32210e65..53638c867 100644 --- a/Examples/guile/matrix/Makefile +++ b/Examples/guile/matrix/Makefile @@ -5,11 +5,11 @@ TARGET = matrix INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' GUILE_RUNOPTIONS='-e do-test' guile_augmented_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' GUILE_RUNOPTIONS='-e do-test' guile_augmented_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' LIBS='-lm' guile_augmented clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean diff --git a/Examples/guile/matrix/runme.scm b/Examples/guile/matrix/runme.scm old mode 100755 new mode 100644 diff --git a/Examples/guile/multimap/Makefile b/Examples/guile/multimap/Makefile index 4ca82a3d3..b8f5e9b5a 100644 --- a/Examples/guile/multimap/Makefile +++ b/Examples/guile/multimap/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile guile_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' guile_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean diff --git a/Examples/guile/multivalue/Makefile b/Examples/guile/multivalue/Makefile index 4ca82a3d3..b8f5e9b5a 100644 --- a/Examples/guile/multivalue/Makefile +++ b/Examples/guile/multivalue/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile guile_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' guile_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean diff --git a/Examples/guile/port/Makefile b/Examples/guile/port/Makefile index d6ec0ac24..95a3a479f 100644 --- a/Examples/guile/port/Makefile +++ b/Examples/guile/port/Makefile @@ -5,12 +5,12 @@ TARGET = port INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_augmented_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_augmented_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_augmented clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean rm -f test.out diff --git a/Examples/guile/simple/Makefile b/Examples/guile/simple/Makefile index da4eb9015..517e41c64 100644 --- a/Examples/guile/simple/Makefile +++ b/Examples/guile/simple/Makefile @@ -5,11 +5,11 @@ TARGET = my-guile INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_augmented_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_augmented_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_augmented clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean diff --git a/Examples/guile/std_vector/Makefile b/Examples/guile/std_vector/Makefile index fd7a8439a..d7f5de217 100644 --- a/Examples/guile/std_vector/Makefile +++ b/Examples/guile/std_vector/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile guile_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' guile_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' guile_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='my-guile' INTERFACE='$(INTERFACE)' guile_static_cpp clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' guile_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' guile_clean diff --git a/Examples/java/callback/Makefile b/Examples/java/callback/Makefile index 8f274e7cb..13cfd1708 100644 --- a/Examples/java/callback/Makefile +++ b/Examples/java/callback/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/check.list b/Examples/java/check.list index 9728342f2..825d04a6d 100644 --- a/Examples/java/check.list +++ b/Examples/java/check.list @@ -7,6 +7,7 @@ extend funcptr multimap native +nested pointer reference simple diff --git a/Examples/java/class/Makefile b/Examples/java/class/Makefile index 8f274e7cb..13cfd1708 100644 --- a/Examples/java/class/Makefile +++ b/Examples/java/class/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/class/example.cxx b/Examples/java/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/java/class/example.cxx +++ b/Examples/java/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -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; } diff --git a/Examples/java/class/example.h b/Examples/java/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/java/class/example.h +++ b/Examples/java/class/example.h @@ -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,21 +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(); }; - - - - - diff --git a/Examples/java/class/example.i b/Examples/java/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/java/class/example.i +++ b/Examples/java/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/java/class/index.html b/Examples/java/class/index.html index cf9130c62..b0a5e221d 100644 --- a/Examples/java/class/index.html +++ b/Examples/java/class/index.html @@ -32,8 +32,8 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); virtual double area() = 0; virtual double perimeter() = 0; @@ -44,7 +44,7 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; + Circle(double r) : radius(r) { } virtual double area(); virtual double perimeter(); }; @@ -53,7 +53,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } virtual double area(); virtual double perimeter(); }; @@ -146,50 +146,15 @@ Shape.setNshapes(13); // Set a static data member
- This high-level interface using proxy classes is not the only way to handle C++ code. -A low level interface using c functions to access member variables and member functions is the alternative SWIG -approach. This entails passing around the c pointer or c++ 'this' pointer and as such it is not difficult to crash the JVM. +A low level interface using C functions to access member variables and member functions is the alternative SWIG +approach. This entails passing around the C pointer or C++ 'this' pointer and as such it is not difficult to crash the JVM. The abstraction of the underlying pointer by the java proxy classes far better fits the java programming paradigm.
-
- SWIG *does* know how to properly perform upcasting of objects in an inheritance +
- SWIG does know how to properly perform upcasting of objects in an inheritance hierarchy (including multiple inheritance). However Java classes can only derive from one base class so multiple inheritance is not implemented. Java classes can implement more than one interface so there is scope for improvement in the future. -
-
- A wide variety of C++ features are not currently supported by SWIG. Here is the -short and incomplete list: - -
-
-
- Overloaded methods and functions. SWIG wrappers don't know how to resolve name -conflicts so you must give an alternative name to any overloaded method name using the -%name directive like this: - -
-- --void foo(int a); -%name(foo2) void foo(double a, double b); ---
- Overloaded operators. Not supported at all. The only workaround for this is -to write a helper function. For example: - -
-- --%inline %{ - Vector *vector_add(Vector *a, Vector *b) { - ... whatever ... - } -%} ---
- Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all). - -
diff --git a/Examples/java/constants/Makefile b/Examples/java/constants/Makefile index 97c5b673c..637ce0ead 100644 --- a/Examples/java/constants/Makefile +++ b/Examples/java/constants/Makefile @@ -1,18 +1,18 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/enum/Makefile b/Examples/java/enum/Makefile index 8f274e7cb..13cfd1708 100644 --- a/Examples/java/enum/Makefile +++ b/Examples/java/enum/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/extend/Makefile b/Examples/java/extend/Makefile index 8f274e7cb..13cfd1708 100644 --- a/Examples/java/extend/Makefile +++ b/Examples/java/extend/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/extend/example.h b/Examples/java/extend/example.h index b27ab9711..ca1aed28f 100644 --- a/Examples/java/extend/example.h +++ b/Examples/java/extend/example.h @@ -14,7 +14,7 @@ public: virtual std::string getTitle() { return getPosition() + " " + getName(); } virtual std::string getName() { return name; } virtual std::string getPosition() const { return "Employee"; } - virtual ~Employee() { printf("~Employee() @ %p\n", this); } + virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); } }; diff --git a/Examples/java/funcptr/Makefile b/Examples/java/funcptr/Makefile index e9e29f3a3..c0b1927ca 100644 --- a/Examples/java/funcptr/Makefile +++ b/Examples/java/funcptr/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/multimap/Makefile b/Examples/java/multimap/Makefile index e9e29f3a3..c0b1927ca 100644 --- a/Examples/java/multimap/Makefile +++ b/Examples/java/multimap/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/native/Makefile b/Examples/java/native/Makefile index 29d5a082a..fa67e48a4 100644 --- a/Examples/java/native/Makefile +++ b/Examples/java/native/Makefile @@ -1,18 +1,18 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/nested/Makefile b/Examples/java/nested/Makefile new file mode 100644 index 000000000..13cfd1708 --- /dev/null +++ b/Examples/java/nested/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +SWIGOPT = +JAVASRCS = *.java + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/nested/example.cxx b/Examples/java/nested/example.cxx new file mode 100644 index 000000000..03bb74d9e --- /dev/null +++ b/Examples/java/nested/example.cxx @@ -0,0 +1,62 @@ +#include "example.h" + +int MotorCar::DesignOpinion::AceDesignCount = 0; +int MotorCar::DesignOpinion::TotalDesignCount = 0; + +int MotorCar::DesignOpinion::PercentScore() { + return AceDesignCount*100/TotalDesignCount; +} + +MotorCar::Wheels::Wheels(Shape shape, size_t count) : shape(shape), count(count) {} + +MotorCar::WindScreen::WindScreen(bool opaque) : opaque(opaque) {} + +MotorCar::MotorCar(const std::string &name, const Wheels &wheels, const WindScreen &windscreen) : name(name), wheels(wheels), windscreen(windscreen) {} + +MotorCar MotorCar::DesignFromComponents(const std::string &name, const Wheels &wheels, const WindScreen &windscreen) { + MotorCar car = MotorCar(name, wheels, windscreen); + DesignOpinion::TotalDesignCount++; + if (car.wheels.Opinion().itrocks && car.windscreen.Opinion().itrocks) + DesignOpinion::AceDesignCount++; + return car; +} + +MotorCar::DesignOpinion MotorCar::Wheels::Opinion() { + DesignOpinion opinion; + opinion.itrocks = true; + if (shape == Square) { + opinion.itrocks = false; + opinion.reason = "you'll have a few issues with wheel rotation"; + } + if (count <= 2) { + opinion.reason += opinion.itrocks ? "" : " and "; + opinion.itrocks = false; + opinion.reason += "a few more wheels are needed for stability"; + } + if (opinion.itrocks) + opinion.reason = "your choice of wheels was top notch"; + + return opinion; +} + +MotorCar::DesignOpinion MotorCar::WindScreen::Opinion() { + DesignOpinion opinion; + opinion.itrocks = !opaque; + opinion.reason = opinion.itrocks ? "the driver will have a commanding view out the window" : "you can't see out the windscreen"; + return opinion; +} + +std::string MotorCar::WillItWork() { + DesignOpinion wh = wheels.Opinion(); + DesignOpinion ws = windscreen.Opinion(); + std::string willit; + if (wh.itrocks && ws.itrocks) { + willit = "Great car design because " + wh.reason + " and " + ws.reason; + } else { + willit = "You need a rethink because "; + willit += wh.itrocks ? "" : wh.reason; + willit += (!wh.itrocks && !ws.itrocks) ? " and " : ""; + willit += ws.itrocks ? "" : ws.reason; + } + return willit; +} diff --git a/Examples/java/nested/example.dsp b/Examples/java/nested/example.dsp new file mode 100644 index 000000000..f52544b95 --- /dev/null +++ b/Examples/java/nested/example.dsp @@ -0,0 +1,162 @@ +# Microsoft Developer Studio Project File - Name="example" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=example - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "example.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "example.mak" CFG="example - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "example - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "example - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "example - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(JAVA_INCLUDE)" /I "$(JAVA_INCLUDE)\win32" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "_DEBUG" +# ADD RSC /l 0x809 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /out:"example.dll" /pdbtype:sept +# Begin Special Build Tool +SOURCE="$(InputPath)" +PostBuild_Desc=Java compile post-build step +PostBuild_Cmds=echo on "%JAVA_BIN%\javac" *.java +# End Special Build Tool + +!ELSEIF "$(CFG)" == "example - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "$(JAVA_INCLUDE)" /I "$(JAVA_INCLUDE)\win32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x809 /d "NDEBUG" +# ADD RSC /l 0x809 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386 /out:"example.dll" +# Begin Special Build Tool +SOURCE="$(InputPath)" +PostBuild_Desc=Java compile post-build step +PostBuild_Cmds=echo on "%JAVA_BIN%\javac" *.java +# End Special Build Tool + +!ENDIF + +# Begin Target + +# Name "example - Win32 Debug" +# Name "example - Win32 Release" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\example.cxx +# End Source File +# Begin Source File + +SOURCE=.\example_wrap.cxx +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\example.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# Begin Source File + +SOURCE=.\example.i + +!IF "$(CFG)" == "example - Win32 Debug" + +# Begin Custom Build +InputPath=.\example.i +InputName=example + +"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + echo In order to function correctly, please ensure the following environment variables are correctly set: + echo JAVA_INCLUDE: %JAVA_INCLUDE% + echo JAVA_BIN: %JAVA_BIN% + echo on + ..\..\..\swig.exe -c++ -java "$(InputPath)" + +# End Custom Build + +!ELSEIF "$(CFG)" == "example - Win32 Release" + +# Begin Custom Build +InputPath=.\example.i +InputName=example + +"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + echo In order to function correctly, please ensure the following environment variables are correctly set: + echo JAVA_INCLUDE: %JAVA_INCLUDE% + echo JAVA_BIN: %JAVA_BIN% + echo on + ..\..\..\swig.exe -c++ -java "$(InputPath)" + +# End Custom Build + +!ENDIF + +# End Source File +# End Target +# End Project diff --git a/Examples/java/nested/example.h b/Examples/java/nested/example.h new file mode 100644 index 000000000..4fb107cb5 --- /dev/null +++ b/Examples/java/nested/example.h @@ -0,0 +1,48 @@ +#include+ +/** Design a motor car from various components */ +struct MotorCar { + + /** Information about an opinion of the design of a car component */ + struct DesignOpinion { + bool itrocks; + std::string reason; + static int AceDesignCount; + static int TotalDesignCount; + static int PercentScore(); + }; + + /** Wheels component */ + struct Wheels { + enum Shape { Round, Square }; + Wheels(Shape shape, size_t count); + DesignOpinion Opinion(); + private: + Shape shape; + size_t count; + }; + + /** Windscreen component */ + struct WindScreen { + WindScreen(bool opaque); + DesignOpinion Opinion(); + private: + bool opaque; + }; + + /** Factory method for creating a car */ + static MotorCar DesignFromComponents(const std::string &name, const Wheels &wheels, const WindScreen &windscreen); + + std::string Name() { + return name; + } + + /** Get an overall opinion on the car design */ + std::string WillItWork(); + +private: + MotorCar(const std::string &name, const Wheels &wheels, const WindScreen &windscreen); + std::string name; + Wheels wheels; + WindScreen windscreen; +}; diff --git a/Examples/java/nested/example.i b/Examples/java/nested/example.i new file mode 100644 index 000000000..c07c1521a --- /dev/null +++ b/Examples/java/nested/example.i @@ -0,0 +1,13 @@ +%module example + +// This example shows how wrappers for numerous aspects of C++ nested classes work: +// Nested static and instance variables and methods and nested enums + +%include + +%{ +#include "example.h" +%} + +%include "example.h" + diff --git a/Examples/java/nested/runme.java b/Examples/java/nested/runme.java new file mode 100644 index 000000000..855dbea91 --- /dev/null +++ b/Examples/java/nested/runme.java @@ -0,0 +1,32 @@ +// This example illustrates wrapping of nested C++ classes + +public class runme { + static { + try { + System.loadLibrary("example"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) + { + MotorCar car1 = MotorCar.DesignFromComponents("Bumpy", new MotorCar.Wheels(MotorCar.Wheels.Shape.Square, 4), new MotorCar.WindScreen(false)); + MotorCar car2 = MotorCar.DesignFromComponents("Wobbly", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 2), new MotorCar.WindScreen(false)); + MotorCar car3 = MotorCar.DesignFromComponents("Batty", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 4), new MotorCar.WindScreen(true)); + MotorCar car4 = MotorCar.DesignFromComponents("Spiffing", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 4), new MotorCar.WindScreen(false)); + + System.out.println("Expert opinion on " + car1.Name() + " : \n " + car1.WillItWork()); + System.out.println("Expert opinion on " + car2.Name() + " : \n " + car2.WillItWork()); + System.out.println("Expert opinion on " + car3.Name() + " : \n " + car3.WillItWork()); + System.out.println("Expert opinion on " + car4.Name() + " : \n " + car4.WillItWork()); + + int count = MotorCar.DesignOpinion.getAceDesignCount(); + int total = MotorCar.DesignOpinion.getTotalDesignCount(); + int percent = MotorCar.DesignOpinion.PercentScore(); + System.out.println("Overall opinion rating on car design is " + count + "/" + total + " = " + percent + "%"); + + System.out.println("Single square wheel thoughts: " + new MotorCar.Wheels(MotorCar.Wheels.Shape.Square, 1).Opinion().getReason()); + } +} diff --git a/Examples/java/pointer/Makefile b/Examples/java/pointer/Makefile index e9e29f3a3..c0b1927ca 100644 --- a/Examples/java/pointer/Makefile +++ b/Examples/java/pointer/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/reference/Makefile b/Examples/java/reference/Makefile index 8f274e7cb..13cfd1708 100644 --- a/Examples/java/reference/Makefile +++ b/Examples/java/reference/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/reference/example.cxx b/Examples/java/reference/example.cxx index 8a513bf49..9dbaed2ee 100644 --- a/Examples/java/reference/example.cxx +++ b/Examples/java/reference/example.cxx @@ -19,7 +19,7 @@ Vector operator+(const Vector &a, const Vector &b) { char *Vector::print() { static char temp[512]; - sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z); + sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z); return temp; } diff --git a/Examples/java/simple/Makefile b/Examples/java/simple/Makefile index e9e29f3a3..c0b1927ca 100644 --- a/Examples/java/simple/Makefile +++ b/Examples/java/simple/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/template/Makefile b/Examples/java/template/Makefile index 97c5b673c..637ce0ead 100644 --- a/Examples/java/template/Makefile +++ b/Examples/java/template/Makefile @@ -1,18 +1,18 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/template/index.html b/Examples/java/template/index.html index f4408e568..31dba6d8e 100644 --- a/Examples/java/template/index.html +++ b/Examples/java/template/index.html @@ -16,7 +16,7 @@ This example illustrates how C++ templates can be used from Java using SWIG. The C++ Code
-Lets take a templated function and a templated class as follows: +Let's take a templated function and a templated class as follows:diff --git a/Examples/java/typemap/Makefile b/Examples/java/typemap/Makefile index 29d5a082a..fa67e48a4 100644 --- a/Examples/java/typemap/Makefile +++ b/Examples/java/typemap/Makefile @@ -1,18 +1,18 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/variables/Makefile b/Examples/java/variables/Makefile index e9e29f3a3..c0b1927ca 100644 --- a/Examples/java/variables/Makefile +++ b/Examples/java/variables/Makefile @@ -7,12 +7,12 @@ SWIGOPT = JAVASRCS = *.java check: build - $(MAKE) -f $(TOP)/Makefile java_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java - $(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile clean: - $(MAKE) -f $(TOP)/Makefile java_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean diff --git a/Examples/java/variables/example.c b/Examples/java/variables/example.c index aa4ffe9b3..85685fe72 100644 --- a/Examples/java/variables/example.c +++ b/Examples/java/variables/example.c @@ -51,10 +51,10 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); - printf("iptrvar = %p\n", iptrvar); + printf("cstrvar = %s\n", cstrvar); + printf("iptrvar = %p\n", (void *)iptrvar); printf("name = %s\n", name); - printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); + printf("ptptr = %p (%d, %d)\n", (void *)ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); printf("pt = (%d, %d)\n", pt.x, pt.y); printf("status = %d\n", status); } diff --git a/Examples/javascript/check.list b/Examples/javascript/check.list new file mode 100644 index 000000000..9707e77d4 --- /dev/null +++ b/Examples/javascript/check.list @@ -0,0 +1,13 @@ +class +constant +enum +exception +functor +nspace +operator +overload +pointer +#reference +simple +template +variables diff --git a/Examples/javascript/class/Makefile b/Examples/javascript/class/Makefile new file mode 100644 index 000000000..54a8f7b03 --- /dev/null +++ b/Examples/javascript/class/Makefile @@ -0,0 +1,3 @@ +SRCS = example.cxx + +include $(SRCDIR)../example.mk diff --git a/Examples/javascript/class/binding.gyp.in b/Examples/javascript/class/binding.gyp.in new file mode 100644 index 000000000..cb2b45e8f --- /dev/null +++ b/Examples/javascript/class/binding.gyp.in @@ -0,0 +1,9 @@ +{ + "targets": [ + { + "target_name": "example", + "sources": [ " + +void Foo::enum_test(speed s) { + if (s == IMPULSE) { + printf("IMPULSE speed\n"); + } else if (s == WARP) { + printf("WARP speed\n"); + } else if (s == LUDICROUS) { + printf("LUDICROUS speed\n"); + } else { + printf("Unknown speed\n"); + } +} + +void enum_test(color c, Foo::speed s) { + if (c == RED) { + printf("color = RED, "); + } else if (c == BLUE) { + printf("color = BLUE, "); + } else if (c == GREEN) { + printf("color = GREEN, "); + } else { + printf("color = Unknown color!, "); + } + if (s == Foo::IMPULSE) { + printf("speed = IMPULSE speed\n"); + } else if (s == Foo::WARP) { + printf("speed = WARP speed\n"); + } else if (s == Foo::LUDICROUS) { + printf("speed = LUDICROUS speed\n"); + } else { + printf("speed = Unknown speed!\n"); + } +} diff --git a/Examples/javascript/enum/example.h b/Examples/javascript/enum/example.h new file mode 100644 index 000000000..9119cd9fc --- /dev/null +++ b/Examples/javascript/enum/example.h @@ -0,0 +1,13 @@ +/* File : example.h */ + +enum color { RED, BLUE, GREEN }; + +class Foo { + public: + Foo() { } + enum speed { IMPULSE=10, WARP=20, LUDICROUS=30 }; + void enum_test(speed s); +}; + +void enum_test(color c, Foo::speed s); + diff --git a/Examples/javascript/enum/example.i b/Examples/javascript/enum/example.i new file mode 100644 index 000000000..23ee8a822 --- /dev/null +++ b/Examples/javascript/enum/example.i @@ -0,0 +1,11 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ + +%include "example.h" + diff --git a/Examples/javascript/enum/example.js b/Examples/javascript/enum/example.js new file mode 100644 index 000000000..2e7f83a06 --- /dev/null +++ b/Examples/javascript/enum/example.js @@ -0,0 +1 @@ +module.exports = require("build/Release/example"); diff --git a/Examples/javascript/enum/runme.js b/Examples/javascript/enum/runme.js new file mode 100644 index 000000000..851d43c4b --- /dev/null +++ b/Examples/javascript/enum/runme.js @@ -0,0 +1,34 @@ +var example = require("example"); + +// ----- Object creation ----- + +// Print out the value of some enums +console.log("*** color ***"); +console.log(" RED =" + example.RED); +console.log(" BLUE =" + example.BLUE); +console.log(" GREEN =" + example.GREEN); + +console.log("\n*** Foo::speed ***"); +console.log(" Foo_IMPULSE =" + example.Foo.IMPULSE); +console.log(" Foo_WARP =" + example.Foo.WARP); +console.log(" Foo_LUDICROUS =" + example.Foo.LUDICROUS); + +console.log("\nTesting use of enums with functions\n"); + +example.enum_test(example.RED, example.Foo.IMPULSE); +example.enum_test(example.BLUE, example.Foo.WARP); +example.enum_test(example.GREEN, example.Foo.LUDICROUS); +example.enum_test(1234,5678); + +console.log("\nTesting use of enum with class method"); +f = new example.Foo(); + +f.enum_test(example.Foo.IMPULSE); +f.enum_test(example.Foo.WARP); +f.enum_test(example.Foo.LUDICROUS); + +// enum value BLUE of enum color is accessed as property of cconst +console.log("example.BLUE= " + example.BLUE); + +// enum value LUDICROUS of enum Foo::speed is accessed as as property of cconst +console.log("example.speed.LUDICROUS= " + example.Foo.LUDICROUS); diff --git a/Examples/javascript/example.mk b/Examples/javascript/example.mk new file mode 100644 index 000000000..5a335bba4 --- /dev/null +++ b/Examples/javascript/example.mk @@ -0,0 +1,27 @@ +# Note: as a convention an example must be in a child directory of this. +# These paths are relative to such an example directory + +ifneq (, $(ENGINE)) + JSENGINE=$(ENGINE) +else + JSENGINE=node +endif + +EXAMPLES_TOP=../.. +SWIG_TOP=../../.. +SWIG = $(SWIG_TOP)/preinst-swig +TARGET = example +INTERFACE = example.i +SWIGOPT=-$(JSENGINE) + +check: build + $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' JSENGINE='$(JSENGINE)' TARGET='$(TARGET)' javascript_run + +build: + $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp + $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' JSENGINE='$(JSENGINE)' javascript_build_cpp + +clean: + $(MAKE) -f $(EXAMPLES_TOP)/Makefile SRCDIR='$(SRCDIR)' javascript_clean diff --git a/Examples/javascript/exception/Makefile b/Examples/javascript/exception/Makefile new file mode 100644 index 000000000..54a8f7b03 --- /dev/null +++ b/Examples/javascript/exception/Makefile @@ -0,0 +1,3 @@ +SRCS = example.cxx + +include $(SRCDIR)../example.mk diff --git a/Examples/javascript/exception/binding.gyp.in b/Examples/javascript/exception/binding.gyp.in new file mode 100644 index 000000000..2e97d9757 --- /dev/null +++ b/Examples/javascript/exception/binding.gyp.in @@ -0,0 +1,30 @@ +{ + "targets": [ + { + "target_name": "example", + "sources": [ " +#ifndef SWIG +struct A { +}; +#endif + +class Exc { +public: + Exc(int c, const char *m) { + code = c; + strncpy(msg,m,256); + } + int code; + char msg[256]; +}; + +#if defined(_MSC_VER) + #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) +#endif + +class Test { +public: + int simple() throw(int) { + throw(37); + return 1; + } + int message() throw(const char *) { + throw("I died."); + return 1; + } + int hosed() throw(Exc) { + throw(Exc(42,"Hosed")); + return 1; + } + int unknown() throw(A*) { + static A a; + throw &a; + return 1; + } + int multi(int x) throw(int, const char *, Exc) { + if (x == 1) throw(37); + if (x == 2) throw("Bleah!"); + if (x == 3) throw(Exc(42,"No-go-diggy-die")); + return 1; + } +}; + +#if defined(_MSC_VER) + #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow) +#endif + diff --git a/Examples/javascript/exception/example.i b/Examples/javascript/exception/example.i new file mode 100644 index 000000000..08672c3a8 --- /dev/null +++ b/Examples/javascript/exception/example.i @@ -0,0 +1,12 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +%include "std_string.i" + +/* Let's just grab the original header file here */ +%include "example.h" + diff --git a/Examples/javascript/exception/example.js b/Examples/javascript/exception/example.js new file mode 100644 index 000000000..2e7f83a06 --- /dev/null +++ b/Examples/javascript/exception/example.js @@ -0,0 +1 @@ +module.exports = require("build/Release/example"); diff --git a/Examples/javascript/exception/runme.js b/Examples/javascript/exception/runme.js new file mode 100644 index 000000000..43ce66d6d --- /dev/null +++ b/Examples/javascript/exception/runme.js @@ -0,0 +1,64 @@ +var example = require("example"); + +console.log("Trying to catch some exceptions."); +t = new example.Test(); +try{ + t.unknown(); + throw -1; +} catch(error) +{ + if(error == -1) { + console.log("t.unknown() didn't throw"); + } else { + console.log("successfully catched throw in Test::unknown()."); + } +} + +try{ + t.simple(); + throw -1; +} +catch(error){ + if(error == -1) { + console.log("t.simple() did not throw"); + } else { + console.log("successfully catched throw in Test::simple()."); + } +} + +try{ + t.message(); + throw -1; +} catch(error){ + if(error == -1) { + console.log("t.message() did not throw"); + } else { + console.log("successfully catched throw in Test::message()."); + } +} + +try{ + t.hosed(); + throw -1; +} +catch(error){ + if(error == -1) { + console.log("t.hosed() did not throw"); + } else { + console.log("successfully catched throw in Test::hosed()."); + } +} + +for (var i=1; i<4; i++) { + try{ + t.multi(i); + throw -1; + } + catch(error){ + if(error == -1) { + console.log("t.multi(" + i + ") did not throw"); + } else { + console.log("successfully catched throw in Test::multi()."); + } + } +} diff --git a/Examples/javascript/functor/Makefile b/Examples/javascript/functor/Makefile new file mode 100644 index 000000000..0402f8d09 --- /dev/null +++ b/Examples/javascript/functor/Makefile @@ -0,0 +1,3 @@ +SRCS = + +include $(SRCDIR)../example.mk diff --git a/Examples/javascript/functor/binding.gyp.in b/Examples/javascript/functor/binding.gyp.in new file mode 100644 index 000000000..59779aef4 --- /dev/null +++ b/Examples/javascript/functor/binding.gyp.in @@ -0,0 +1,9 @@ +{ + "targets": [ + { + "target_name": "example", + "sources": [ "example_wrap.cxx" ], + "include_dirs": ["$srcdir"] + } + ] +} diff --git a/Examples/javascript/functor/example.i b/Examples/javascript/functor/example.i new file mode 100644 index 000000000..0450c2124 --- /dev/null +++ b/Examples/javascript/functor/example.i @@ -0,0 +1,25 @@ +/* File : example.i */ +%module example + + +%inline %{ +// From B. Strousjoup, "The C++ Programming Language, Third Edition", p. 514 +templateclass Sum { + T res; +public: + Sum(T i = 0) : res(i) { } + void operator() (T x) { res += x; } + T result() const { return res; } +}; + +%} + +%rename(call) *::operator(); // the fn call operator + +// Instantiate a few versions +%template(intSum) Sum ; +%template(doubleSum) Sum ; + + + + diff --git a/Examples/javascript/functor/example.js b/Examples/javascript/functor/example.js new file mode 100644 index 000000000..2e7f83a06 --- /dev/null +++ b/Examples/javascript/functor/example.js @@ -0,0 +1 @@ +module.exports = require("build/Release/example"); diff --git a/Examples/javascript/functor/runme.js b/Examples/javascript/functor/runme.js new file mode 100644 index 000000000..28dc64320 --- /dev/null +++ b/Examples/javascript/functor/runme.js @@ -0,0 +1,15 @@ +var example = require("example"); + +a = new example.intSum(0); +b = new example.doubleSum(100.0); + +// Use the objects. They should be callable just like a normal +// javascript function. + +for (i=1;i<=100;i++) + a.call(i); // Note: function call + b.call(Math.sqrt(i)); // Note: function call + +console.log(a.result()); +console.log(b.result()); + diff --git a/Examples/javascript/nspace/Makefile b/Examples/javascript/nspace/Makefile new file mode 100644 index 000000000..0402f8d09 --- /dev/null +++ b/Examples/javascript/nspace/Makefile @@ -0,0 +1,3 @@ +SRCS = + +include $(SRCDIR)../example.mk diff --git a/Examples/javascript/nspace/binding.gyp.in b/Examples/javascript/nspace/binding.gyp.in new file mode 100644 index 000000000..59779aef4 --- /dev/null +++ b/Examples/javascript/nspace/binding.gyp.in @@ -0,0 +1,9 @@ +{ + "targets": [ + { + "target_name": "example", + "sources": [ "example_wrap.cxx" ], + "include_dirs": ["$srcdir"] + } + ] +} diff --git a/Examples/javascript/nspace/example.h b/Examples/javascript/nspace/example.h new file mode 100644 index 000000000..53066980a --- /dev/null +++ b/Examples/javascript/nspace/example.h @@ -0,0 +1,23 @@ +#ifndef _example_guardian_ +#define _example_guardian_ + +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; } + }; + } +} + +#endif diff --git a/Examples/javascript/nspace/example.i b/Examples/javascript/nspace/example.i new file mode 100644 index 000000000..c30f87fec --- /dev/null +++ b/Examples/javascript/nspace/example.i @@ -0,0 +1,10 @@ +%module example + +%{ +#include "example.h" +%} + +%nspace MyWorld::Nested::Dweller; +%nspace MyWorld::World; + +%include "example.h" diff --git a/Examples/javascript/nspace/example.js b/Examples/javascript/nspace/example.js new file mode 100644 index 000000000..2e7f83a06 --- /dev/null +++ b/Examples/javascript/nspace/example.js @@ -0,0 +1 @@ +module.exports = require("build/Release/example"); diff --git a/Examples/javascript/nspace/runme.js b/Examples/javascript/nspace/runme.js new file mode 100644 index 000000000..fad73477d --- /dev/null +++ b/Examples/javascript/nspace/runme.js @@ -0,0 +1,50 @@ +// File: runme.js + +// This file illustrates class C++ interface generated +// by SWIG. + +var example = require("example"); + +// Calling a module function ( aka global function ) +if (example.module_function() !== 7) { + throw new Error("example.module_function() should equal 7"); +} +console.log("example.module_function(): " + example.module_function()); + +// Accessing a module (aka global) variable +if (example.module_variable !== 9) { + throw new Error("example.module_variable should equal 9"); +} +console.log("example.module_variable: " + example.module_variable); + +// Creating an instance of the class +var w1 = new example.MyWorld.World(); +console.log("Creating class instance: w1 = new example.MyWorld.World(): " + w1); + +// Accessing class members +if (w1.create_world() !== 17) { + throw new Error("w1.create_world() should equal 17"); +} +console.log("w1.create_world() = " + w1.create_world()); + +if (w1.world_max_count !== 9) { + throw new Error("w1.world_max_count should equal 9"); +} +console.log("w1.world_max_count = " + w1.world_max_count); + +// Accessing enums from class within namespace +if (example.MyWorld.Nested.Dweller.MALE !== 0) { + throw new Error("example.MyWorld.Nested.Dweller.MALE should equal 0"); +} +console.log("Accessing enums: ex.MyWorld.Nested.Dweller.MALE = " + example.MyWorld.Nested.Dweller.MALE); + +if (example.MyWorld.Nested.Dweller.FEMALE !== 1) { + throw new Error("example.MyWorld.Nested.Dweller.FEMALE should equal 1"); +} +console.log("Accessing enums: ex.MyWorld.Nested.Dweller.FEMALE = " + example.MyWorld.Nested.Dweller.FEMALE); + +// Accessing static member function +if (example.MyWorld.Nested.Dweller.count() !== 19) { + throw new Error("example.MyWorld.Nested.Dweller.count() should equal 19"); +} +console.log("Accessing static member function: ex.MyWorld.Nested.Dweller.count() = " + example.MyWorld.Nested.Dweller.count()); diff --git a/Examples/javascript/operator/Makefile b/Examples/javascript/operator/Makefile new file mode 100644 index 000000000..0402f8d09 --- /dev/null +++ b/Examples/javascript/operator/Makefile @@ -0,0 +1,3 @@ +SRCS = + +include $(SRCDIR)../example.mk diff --git a/Examples/javascript/operator/binding.gyp.in b/Examples/javascript/operator/binding.gyp.in new file mode 100644 index 000000000..59779aef4 --- /dev/null +++ b/Examples/javascript/operator/binding.gyp.in @@ -0,0 +1,9 @@ +{ + "targets": [ + { + "target_name": "example", + "sources": [ "example_wrap.cxx" ], + "include_dirs": ["$srcdir"] + } + ] +} diff --git a/Examples/javascript/operator/example.h b/Examples/javascript/operator/example.h new file mode 100644 index 000000000..4da6a2307 --- /dev/null +++ b/Examples/javascript/operator/example.h @@ -0,0 +1,36 @@ +/* File : example.h */ +#include + +class Complex { +private: + double rpart, ipart; +public: + Complex(double r = 0, double i = 0) : rpart(r), ipart(i) { } + Complex(const Complex &c) : rpart(c.rpart), ipart(c.ipart) { } + Complex &operator=(const Complex &c) { + rpart = c.rpart; + ipart = c.ipart; + return *this; + } + Complex operator+(const Complex &c) const { + return Complex(rpart+c.rpart, ipart+c.ipart); + } + Complex operator-(const Complex &c) const { + return Complex(rpart-c.rpart, ipart-c.ipart); + } + Complex operator*(const Complex &c) const { + return Complex(rpart*c.rpart - ipart*c.ipart, + rpart*c.ipart + c.rpart*ipart); + } + Complex operator-() const { + return Complex(-rpart, -ipart); + } + + double re() const { return rpart; } + double im() const { return ipart; } +}; + + + + + diff --git a/Examples/javascript/operator/example.i b/Examples/javascript/operator/example.i new file mode 100644 index 000000000..7a1bd45e1 --- /dev/null +++ b/Examples/javascript/operator/example.i @@ -0,0 +1,34 @@ +/* File : example.i */ +%module example +#pragma SWIG nowarn=SWIGWARN_IGNORE_OPERATOR_EQ +%{ +#include "example.h" +%} + +/* This header file is a little tough to handle because it has overloaded + operators and constructors. We're going to try and deal with that here */ + +/* This turns the copy constructor in a function ComplexCopy() that can + be called */ + +%rename(assign) Complex::operator=; +%rename(plus) Complex::operator+; +%rename(minus) Complex::operator-(const Complex &) const; +%rename(uminus) Complex::operator-() const; +%rename(times) Complex::operator*; + +/* Now grab the original header file */ +%include "example.h" + +/* An output method that turns a complex into a short string */ +%extend Complex { + char *toString() { + static char temp[512]; + sprintf(temp,"(%g,%g)", $self->re(), $self->im()); + return temp; + } + static Complex* copy(const Complex& c) { + return new Complex(c); + } +}; + diff --git a/Examples/javascript/operator/example.js b/Examples/javascript/operator/example.js new file mode 100644 index 000000000..2e7f83a06 --- /dev/null +++ b/Examples/javascript/operator/example.js @@ -0,0 +1 @@ +module.exports = require("build/Release/example"); diff --git a/Examples/javascript/operator/runme.js b/Examples/javascript/operator/runme.js new file mode 100644 index 000000000..f72ca1c28 --- /dev/null +++ b/Examples/javascript/operator/runme.js @@ -0,0 +1,25 @@ +var example = require("example"); + +a = new example.Complex(2,3); +b = new example.Complex(-5,10); + +console.log ("a =" + a); +console.log ("b =" + b); + +c = a.plus(b); + +console.log("c =" + c); +console.log("a*b =" + a.times(b)); +console.log("a-c =" + a.minus(c)); + +e = example.Complex.copy(a.minus(c)); +console.log("e =" + e); + +// Big expression +f = a.plus(b).times(c.plus(b.times(e))).plus(a.uminus()); +console.log("f =" + f); + + + + + diff --git a/Examples/javascript/overload/Makefile b/Examples/javascript/overload/Makefile new file mode 100644 index 000000000..0402f8d09 --- /dev/null +++ b/Examples/javascript/overload/Makefile @@ -0,0 +1,3 @@ +SRCS = + +include $(SRCDIR)../example.mk diff --git a/Examples/javascript/overload/binding.gyp.in b/Examples/javascript/overload/binding.gyp.in new file mode 100644 index 000000000..59779aef4 --- /dev/null +++ b/Examples/javascript/overload/binding.gyp.in @@ -0,0 +1,9 @@ +{ + "targets": [ + { + "target_name": "example", + "sources": [ "example_wrap.cxx" ], + "include_dirs": ["$srcdir"] + } + ] +} diff --git a/Examples/javascript/overload/example.h b/Examples/javascript/overload/example.h new file mode 100644 index 000000000..2f112f1e1 --- /dev/null +++ b/Examples/javascript/overload/example.h @@ -0,0 +1,28 @@ +#include + +void f() { + std::cout << "Called f()." << std::endl; +} + +void f(int val) { + std::cout << "Called f(int)." << std::endl; +} +void f(int val1, int val2) { + std::cout << "Called f(int, int)." << std::endl; +} + +void f(const char* s) { + std::cout << "Called f(const char*)." << std::endl; +} + +void f(bool val) { + std::cout << "Called f(bool)." << std::endl; +} + +void f(long val) { + std::cout << "Called f(long)." << std::endl; +} + +void f(double val) { + std::cout << "Called f(double)." << std::endl; +} diff --git a/Examples/javascript/overload/example.i b/Examples/javascript/overload/example.i new file mode 100644 index 000000000..b86689f8a --- /dev/null +++ b/Examples/javascript/overload/example.i @@ -0,0 +1,16 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* + Note: overloading is implemented in a sloppy way currently + i.e., only the number of arguments is taken into conideration + for dispatching. + To solve the problem one has to rename such conflicting methods. +*/ +%rename(f_double) f(double val); + +%include "example.h" diff --git a/Examples/javascript/overload/example.js b/Examples/javascript/overload/example.js new file mode 100644 index 000000000..2e7f83a06 --- /dev/null +++ b/Examples/javascript/overload/example.js @@ -0,0 +1 @@ +module.exports = require("build/Release/example"); diff --git a/Examples/javascript/overload/runme.js b/Examples/javascript/overload/runme.js new file mode 100644 index 000000000..1c23e3b6b --- /dev/null +++ b/Examples/javascript/overload/runme.js @@ -0,0 +1,9 @@ +var example = require("example"); + +example.f(); +example.f(1); +example.f(1, 2); +example.f("bla"); +example.f(false); +example.f(11111111111); +example.f_double(1.0); diff --git a/Examples/javascript/pointer/Makefile b/Examples/javascript/pointer/Makefile new file mode 100644 index 000000000..54a8f7b03 --- /dev/null +++ b/Examples/javascript/pointer/Makefile @@ -0,0 +1,3 @@ +SRCS = example.cxx + +include $(SRCDIR)../example.mk diff --git a/Examples/javascript/pointer/binding.gyp.in b/Examples/javascript/pointer/binding.gyp.in new file mode 100644 index 000000000..cb2b45e8f --- /dev/null +++ b/Examples/javascript/pointer/binding.gyp.in @@ -0,0 +1,9 @@ +{ + "targets": [ + { + "target_name": "example", + "sources": [ " 0) { + g = x; + x = y % x; + y = g; + } + return g; +} + + diff --git a/Examples/javascript/simple/example.i b/Examples/javascript/simple/example.i new file mode 100644 index 000000000..24093b9bf --- /dev/null +++ b/Examples/javascript/simple/example.i @@ -0,0 +1,7 @@ +/* File : example.i */ +%module example + +%inline %{ +extern int gcd(int x, int y); +extern double Foo; +%} diff --git a/Examples/javascript/simple/example.js b/Examples/javascript/simple/example.js new file mode 100644 index 000000000..2e7f83a06 --- /dev/null +++ b/Examples/javascript/simple/example.js @@ -0,0 +1 @@ +module.exports = require("build/Release/example"); diff --git a/Examples/javascript/simple/runme.js b/Examples/javascript/simple/runme.js new file mode 100644 index 000000000..4abff0e2a --- /dev/null +++ b/Examples/javascript/simple/runme.js @@ -0,0 +1,26 @@ +var example = require("example"); + +/* Call our gcd() function */ + +x = 42; +y = 105; +g = example.gcd(x,y); +console.log("GCD of x and y is=" + g); + +/* Manipulate the Foo global variable */ + +/* Output its current value */ +console.log("Global variable Foo=" + example.Foo); + +/* Change its value */ +example.Foo = 3.1415926; + +/* See if the change took effect */ +console.log("Variable Foo changed to=" + example.Foo); + + + + + + + diff --git a/Examples/javascript/template/Makefile b/Examples/javascript/template/Makefile new file mode 100644 index 000000000..0402f8d09 --- /dev/null +++ b/Examples/javascript/template/Makefile @@ -0,0 +1,3 @@ +SRCS = + +include $(SRCDIR)../example.mk diff --git a/Examples/javascript/template/binding.gyp.in b/Examples/javascript/template/binding.gyp.in new file mode 100644 index 000000000..59779aef4 --- /dev/null +++ b/Examples/javascript/template/binding.gyp.in @@ -0,0 +1,9 @@ +{ + "targets": [ + { + "target_name": "example", + "sources": [ "example_wrap.cxx" ], + "include_dirs": ["$srcdir"] + } + ] +} diff --git a/Examples/javascript/template/example.h b/Examples/javascript/template/example.h new file mode 100644 index 000000000..7401df650 --- /dev/null +++ b/Examples/javascript/template/example.h @@ -0,0 +1,32 @@ +/* File : example.h */ + +// Some template definitions + +template T max(T a, T b) { return a>b ? a : b; } + +template class vector { + T *v; + int sz; + public: + vector(int _sz) { + v = new T[_sz]; + sz = _sz; + } + T &get(int index) { + return v[index]; + } + void set(int index, T &val) { + v[index] = val; + } +#ifdef SWIG + %extend { + T getitem(int index) { + return $self->get(index); + } + void setitem(int index, T val) { + $self->set(index,val); + } + } +#endif +}; + diff --git a/Examples/javascript/template/example.i b/Examples/javascript/template/example.i new file mode 100644 index 000000000..8f94c4da1 --- /dev/null +++ b/Examples/javascript/template/example.i @@ -0,0 +1,17 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ +%include "example.h" + +/* Now instantiate some specific template declarations */ + +%template(maxint) max ; +%template(maxdouble) max ; +%template(vecint) vector ; +%template(vecdouble) vector ; + diff --git a/Examples/javascript/template/example.js b/Examples/javascript/template/example.js new file mode 100644 index 000000000..2e7f83a06 --- /dev/null +++ b/Examples/javascript/template/example.js @@ -0,0 +1 @@ +module.exports = require("build/Release/example"); diff --git a/Examples/javascript/template/runme.js b/Examples/javascript/template/runme.js new file mode 100644 index 000000000..af96ac7f9 --- /dev/null +++ b/Examples/javascript/template/runme.js @@ -0,0 +1,30 @@ +var example = require("example"); + +//Call some templated functions +console.log(example.maxint(3,7)); +console.log(example.maxdouble(3.14,2.18)); + +// Create some class + +iv = new example.vecint(100); +dv = new example.vecdouble(1000); + +for(i=0;i<=100;i++) + iv.setitem(i,2*i); + +for(i=0;i<=1000;i++) + dv.setitem(i, 1.0/(i+1)); + +sum = 0; +for(i=0;i<=100;i++) + sum = sum + iv.getitem(i); + +console.log(sum); + +sum = 0.0; +for(i=0;i<=1000;i++) + sum = sum + dv.getitem(i); +console.log(sum); + +delete iv; +delete dv; diff --git a/Examples/javascript/variables/Makefile b/Examples/javascript/variables/Makefile new file mode 100644 index 000000000..54a8f7b03 --- /dev/null +++ b/Examples/javascript/variables/Makefile @@ -0,0 +1,3 @@ +SRCS = example.cxx + +include $(SRCDIR)../example.mk diff --git a/Examples/javascript/variables/binding.gyp.in b/Examples/javascript/variables/binding.gyp.in new file mode 100644 index 000000000..cb2b45e8f --- /dev/null +++ b/Examples/javascript/variables/binding.gyp.in @@ -0,0 +1,9 @@ +{ + "targets": [ + { + "target_name": "example", + "sources": [ " +#include +#include "example.h" + +int ivar = 0; +short svar = 0; +long lvar = 0; +unsigned int uivar = 0; +unsigned short usvar = 0; +unsigned long ulvar = 0; +signed char scvar = 0; +unsigned char ucvar = 0; +char cvar = 0; +float fvar = 0; +double dvar = 0; +char *strvar = 0; +#ifdef __cplusplus // Note: for v8 this must be linkable with g++, without extern cstrvar is mangled +extern const char cstrvar[] = "Goodbye"; +#else +const char cstrvar[] = "Goodbye"; +#endif +const +int *iptrvar = 0; +char name[256] = "Dave"; +char path[256] = "/home/beazley"; + + +/* Global variables involving a structure */ +Point *ptptr = 0; +Point pt = { 10, 20 }; + +/* A variable that we will make read-only in the interface */ +int status = 1; + +/* A debugging function to print out their values */ + +void print_vars() { + printf("ivar = %d\n", ivar); + printf("svar = %d\n", svar); + printf("lvar = %ld\n", lvar); + printf("uivar = %u\n", uivar); + printf("usvar = %u\n", usvar); + printf("ulvar = %lu\n", ulvar); + printf("scvar = %d\n", scvar); + printf("ucvar = %u\n", ucvar); + printf("fvar = %g\n", fvar); + printf("dvar = %g\n", dvar); + printf("cvar = %c\n", cvar); + printf("strvar = %s\n", strvar ? strvar : "(null)"); + printf("cstrvar = %s\n", cstrvar); + printf("iptrvar = %p\n", (void *)iptrvar); + printf("name = %s\n", name); + printf("ptptr = %p (%d, %d)\n", (void *)ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); + printf("pt = (%d, %d)\n", pt.x, pt.y); + printf("status = %d\n", status); +} + +/* A function to create an integer (to test iptrvar) */ + +int *new_int(int value) { + int *ip = (int *) malloc(sizeof(int)); + *ip = value; + return ip; +} + +/* A function to create a point */ + +Point *new_Point(int x, int y) { + Point *p = (Point *) malloc(sizeof(Point)); + p->x = x; + p->y = y; + return p; +} + +char * Point_print(Point *p) { + static char buffer[256]; + if (p) { + sprintf(buffer,"(%d,%d)", p->x,p->y); + } else { + sprintf(buffer,"null"); + } + return buffer; +} + +void pt_print() { + printf("(%d, %d)\n", pt.x, pt.y); +} diff --git a/Examples/javascript/variables/example.h b/Examples/javascript/variables/example.h new file mode 100644 index 000000000..0f7e89594 --- /dev/null +++ b/Examples/javascript/variables/example.h @@ -0,0 +1,6 @@ +/* File: example.h */ + +typedef struct { + int x,y; +} Point; + diff --git a/Examples/javascript/variables/example.i b/Examples/javascript/variables/example.i new file mode 100644 index 000000000..591b871ed --- /dev/null +++ b/Examples/javascript/variables/example.i @@ -0,0 +1,49 @@ +/* File : example.i */ +%module example +%{ +#include "example.h" +%} + +/* Some global variable declarations */ +%inline %{ +extern int ivar; +extern short svar; +extern long lvar; +extern unsigned int uivar; +extern unsigned short usvar; +extern unsigned long ulvar; +extern signed char scvar; +extern unsigned char ucvar; +extern char cvar; +extern float fvar; +extern double dvar; +extern char *strvar; +extern const char cstrvar[]; +extern int *iptrvar; +extern char name[256]; + +extern Point *ptptr; +extern Point pt; +%} + + +/* Some read-only variables */ + +%immutable; + +%inline %{ +extern int status; +extern char path[256]; +%} + +%mutable; + +/* Some helper functions to make it easier to test */ +%inline %{ +extern void print_vars(); +extern int *new_int(int value); +extern Point *new_Point(int x, int y); +extern char *Point_print(Point *p); +extern void pt_print(); +%} + diff --git a/Examples/javascript/variables/example.js b/Examples/javascript/variables/example.js new file mode 100644 index 000000000..2e7f83a06 --- /dev/null +++ b/Examples/javascript/variables/example.js @@ -0,0 +1 @@ +module.exports = require("build/Release/example"); diff --git a/Examples/javascript/variables/runme.js b/Examples/javascript/variables/runme.js new file mode 100644 index 000000000..a2b5f791c --- /dev/null +++ b/Examples/javascript/variables/runme.js @@ -0,0 +1,68 @@ +var example = require("example"); + +// Try to set the values of some global variables +example.ivar = 42; +example.svar = -31000; +example.lvar = 65537; +example.uivar = 123456; +example.usvar = 61000; +example.ulvar = 654321; +example.scvar = -13; +example.ucvar = 251; +example.cvar = "S"; +example.fvar = 3.14159; +example.dvar = 2.1828; +example.strvar = "Hello World"; +example.iptrvar= example.new_int(37); +example.ptptr = example.new_Point(37,42); +example.name = "Bill"; + +// Now console.log out the values of the variables +console.log("Variables (values printed from Javascript)"); +console.log("ivar = " + example.ivar); +console.log("svar = " + example.svar); +console.log("lvar = " + example.lvar); +console.log("uivar = " + example.uivar); +console.log("usvar = " + example.usvar); +console.log("ulvar = " + example.ulvar); +console.log("scvar = " + example.scvar); +console.log("ucvar = " + example.ucvar); +console.log("fvar = " + example.fvar); +console.log("dvar = " + example.dvar); +console.log("cvar = " + example.cvar); +console.log("strvar = " + example.strvar); +console.log("cstrvar = " + example.cstrvar); +console.log("iptrvar = " + example.iptrvar); +console.log("name = " + example.name); +console.log("ptptr = " + example.ptptr + ": " + example.Point_print(example.ptptr)); +console.log("pt = " + example.pt + ": " + example.Point_print(example.pt)); + + +console.log("\nVariables (values printed from C)"); + +example.print_vars(); + +console.log("\nNow I'm going to try and modify some read only variables"); + +console.log("Tring to set 'path'"); +try{ + example.path = "Whoa!"; + console.log("Hey, what's going on?!?! This shouldn't work"); +} +catch(e){ + console.log("Good."); +} + +console.log("Trying to set 'status'"); +try{ + example.status = 0; + console.log("Hey, what's going on?!?! This shouldn't work"); +} catch(e){ + console.log("Good."); +} + +console.log("\nI'm going to try and update a structure variable."); +example.pt = example.ptptr; +console.log("The new value is: "); +example.pt_print(); +console.log("You should see the value: " + example.Point_print(example.ptptr)); diff --git a/Examples/lua/arrays/Makefile b/Examples/lua/arrays/Makefile index d398dffea..4191f7ec3 100644 --- a/Examples/lua/arrays/Makefile +++ b/Examples/lua/arrays/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile lua_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static clean: - $(MAKE) -f $(TOP)/Makefile lua_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean diff --git a/Examples/lua/arrays/example.c b/Examples/lua/arrays/example.c index ed23738c8..da1bd755a 100644 --- a/Examples/lua/arrays/example.c +++ b/Examples/lua/arrays/example.c @@ -13,7 +13,7 @@ void sort_int(int* arr, int len) qsort(arr, len, sizeof(int), compare_int); } -// ditto doubles +/* ditto doubles */ int compare_double(const void * a, const void * b) { return (int)( *(double*)a - *(double*)b ); diff --git a/Examples/lua/arrays/runme.lua b/Examples/lua/arrays/runme.lua index 7ab6dc42b..d0aa99813 100644 --- a/Examples/lua/arrays/runme.lua +++ b/Examples/lua/arrays/runme.lua @@ -25,7 +25,7 @@ math.randomseed(0) -- init random --[[ version 1: passing a C array to the code -lets test call sort_int() +let's test call sort_int() this requires a C array, so is the hardest to use]] ARRAY_SIZE=10 arr=example.new_int(ARRAY_SIZE) diff --git a/Examples/lua/check.list b/Examples/lua/check.list index 6862e4478..87dfdcd08 100644 --- a/Examples/lua/check.list +++ b/Examples/lua/check.list @@ -11,6 +11,7 @@ funcptr3 functest functor import +nspace owner pointer simple diff --git a/Examples/lua/class/Makefile b/Examples/lua/class/Makefile index c39e8acdf..96308f0df 100644 --- a/Examples/lua/class/Makefile +++ b/Examples/lua/class/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile lua_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile lua_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean diff --git a/Examples/lua/class/example.cxx b/Examples/lua/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/lua/class/example.cxx +++ b/Examples/lua/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -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; } diff --git a/Examples/lua/class/example.h b/Examples/lua/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/lua/class/example.h +++ b/Examples/lua/class/example.h @@ -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,21 +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(); }; - - - - - diff --git a/Examples/lua/class/example.i b/Examples/lua/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/lua/class/example.i +++ b/Examples/lua/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/lua/class/runme.lua b/Examples/lua/class/runme.lua index 2c3ad8ced..5d140defe 100644 --- a/Examples/lua/class/runme.lua +++ b/Examples/lua/class/runme.lua @@ -53,7 +53,6 @@ print("\nGuess I'll clean up now") -- Note: this invokes the virtual destructor c=nil s=nil -s = 3 -- call gc to make sure they are collected collectgarbage() diff --git a/Examples/lua/constants/Makefile b/Examples/lua/constants/Makefile index 51b83be2e..ae33cb182 100644 --- a/Examples/lua/constants/Makefile +++ b/Examples/lua/constants/Makefile @@ -1,20 +1,20 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i -LIBS = +LIBS = check: build - $(MAKE) -f $(TOP)/Makefile lua_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static clean: - $(MAKE) -f $(TOP)/Makefile lua_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean diff --git a/Examples/lua/dual/Makefile b/Examples/lua/dual/Makefile index 12ee00a68..c86152a97 100644 --- a/Examples/lua/dual/Makefile +++ b/Examples/lua/dual/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig TARGET = dual -CXXSRCS = example2_wrap.cxx +GENCXXSRCS = example2_wrap.cxx INTERFACE = dual.i LUA_INTERP = dual.cpp # This is a little different to normal as we need to static link two modules and a custom interpreter # We need the external runtime, then swig examples2, and build the module as normal check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' lua_embed_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' lua_embed_run build: $(SWIG) -lua -external-runtime - $(SWIG) -c++ -lua $(SWIGOPT) example2.i - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(SWIG) -c++ -lua $(SWIGOPT) -o $(GENCXXSRCS) $(SRCDIR)example2.i + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) GENCXXSRCS='$(GENCXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static_cpp clean: - $(MAKE) -f $(TOP)/Makefile lua_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean rm -f swigluarun.h $(TARGET) diff --git a/Examples/lua/dual/dual.cpp b/Examples/lua/dual/dual.cpp index d2a9ecaa9..2108a7275 100644 --- a/Examples/lua/dual/dual.cpp +++ b/Examples/lua/dual/dual.cpp @@ -1,7 +1,7 @@ /* -dual.cpp a test for multiple modules and multiple intrepreters staticly linked together. +dual.cpp a test for multiple modules and multiple interpreters statically linked together. -Earlier version of lua bindings for SWIG would fail if staticly linked. +Earlier version of lua bindings for SWIG would fail if statically linked. What is happening is as follows: example.i declares a type Foo @@ -28,7 +28,7 @@ both Foo and Bar. #include #include -// the 2 libraries which are wrappered via SWIG +// the 2 libraries which are wrapped via SWIG extern "C" int luaopen_example(lua_State*L); extern "C" int luaopen_example2(lua_State*L); @@ -36,19 +36,23 @@ extern "C" int luaopen_example2(lua_State*L); #define DEBUG2(X,Y) {printf(X,Y);fflush(stdout);} #define DEBUG3(X,Y,Z) {printf(X,Y,Z);fflush(stdout);} +#if LUA_VERSION_NUM > 501 +#define lua_open luaL_newstate +#endif + void testModule(lua_State *L) { swig_type_info *pTypeInfo=0,*pTypeInfo2=0; swig_module_info *pModule=0; pModule=SWIG_GetModule(L); - DEBUG2(" SWIG_GetModule() returns %p\n",pModule) + DEBUG2(" SWIG_GetModule() returns %p\n", (void *)pModule) if(pModule==0) return; pTypeInfo = SWIG_TypeQuery(L,"Foo *"); DEBUG2(" Type (Foo*) is %s\n",pTypeInfo==0?"unknown":"known"); - DEBUG3(" Module %p typeinfo(Foo*) %p\n",pModule,pTypeInfo); + DEBUG3(" Module %p typeinfo(Foo*) %p\n", (void *)pModule, (void *)pTypeInfo); pTypeInfo2 = SWIG_TypeQuery(L,"Bar *"); DEBUG2(" Type (Bar*) is %s\n",pTypeInfo2==0?"unknown":"known"); - DEBUG3(" Module %p typeinfo(Bar*) %p\n",pModule,pTypeInfo2); + DEBUG3(" Module %p typeinfo(Bar*) %p\n", (void *)pModule, (void *)pTypeInfo2); } int main(int argc,char* argv[]) diff --git a/Examples/lua/embed/Makefile b/Examples/lua/embed/Makefile index df1f8fa04..5e3a91893 100644 --- a/Examples/lua/embed/Makefile +++ b/Examples/lua/embed/Makefile @@ -4,16 +4,17 @@ TARGET = embed SRCS = example.c INTERFACE = example.i LUA_INTERP = embed.c +LIBS = -lm # this is a little different to normal as we have our own special interpreter # which we want to static link check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' lua_embed_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' lua_embed_run build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' LIBS='$(LIBS)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static clean: - $(MAKE) -f $(TOP)/Makefile lua_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean rm -f $(TARGET) diff --git a/Examples/lua/embed/embed.c b/Examples/lua/embed/embed.c index 9df168f94..1f10cc8e8 100644 --- a/Examples/lua/embed/embed.c +++ b/Examples/lua/embed/embed.c @@ -1,9 +1,9 @@ -/* embed.c a simple test for an embeded interpreter +/* embed.c a simple test for an embedded interpreter The idea is that we wrapper a few simple function (example.c) and write our own app to call it. -What it will do is load the wrappered lib, load runme.lua and then call some functions. +What it will do is load the wrapped lib, load runme.lua and then call some functions. To make life easier, all the printf's have either [C] or [Lua] at the start so you can see where they are coming from. @@ -13,19 +13,24 @@ We will be using the luaL_dostring()/lua_dostring() function to call into lua #include #include +#include #include #include #include +#if LUA_VERSION_NUM > 501 +#define lua_open luaL_newstate +#endif + /* the SWIG wrappered library */ extern int luaopen_example(lua_State*L); /* a really simple way of calling lua from C just give it a lua state & a string to execute Unfortunately lua keeps changing its API's. -In lua 5.0.X its lua_dostring() -In lua 5.1.X its luaL_dostring() +In lua 5.0.X it's lua_dostring() +In lua 5.1.X it's luaL_dostring() so we have a few extra compiles */ int dostring(lua_State *L, char* str) { @@ -54,28 +59,32 @@ int main(int argc,char* argv[]) { luaopen_base(L); luaopen_string(L); luaopen_math(L); - printf("[C] now loading the SWIG wrappered library\n"); + printf("[C] now loading the SWIG wrapped library\n"); luaopen_example(L); printf("[C] all looks ok\n"); printf("\n"); - printf("[C] lets load the file 'runme.lua'\n"); + if (argc != 2 || argv[1] == NULL || strlen(argv[1]) == 0) { + printf("[C] ERROR: no lua file given on command line\n"); + exit(3); + } + printf("[C] let's load the file '%s'\n", argv[1]); printf("[C] any lua code in this file will be executed\n"); - if (luaL_loadfile(L, "runme.lua") || lua_pcall(L, 0, 0, 0)) { + if (luaL_loadfile(L, argv[1]) || lua_pcall(L, 0, 0, 0)) { printf("[C] ERROR: cannot run lua file: %s",lua_tostring(L, -1)); exit(3); } printf("[C] We are now back in C, all looks ok\n"); printf("\n"); - printf("[C] lets call the function 'do_tests()'\n"); + printf("[C] let's call the function 'do_tests()'\n"); ok=dostring(L,"do_tests()"); printf("[C] We are back in C, the dostring() function returned %d\n",ok); printf("\n"); - printf("[C] Lets call lua again, but create an error\n"); + printf("[C] Let's call lua again, but create an error\n"); ok=dostring(L,"no_such_function()"); printf("[C] We are back in C, the dostring() function returned %d\n",ok); printf("[C] it should also have returned 1 and printed an error message\n"); printf("\n"); - printf("[C] Lets call lua again, calling the greeting function\n"); + printf("[C] Let's call lua again, calling the greeting function\n"); ok=dostring(L,"call_greeting()"); printf("[C] This was C=>Lua=>C (getting a bit complex)\n"); printf("\n"); diff --git a/Examples/lua/embed/runme.lua b/Examples/lua/embed/runme.lua index e02fd1d55..a75f74000 100644 --- a/Examples/lua/embed/runme.lua +++ b/Examples/lua/embed/runme.lua @@ -1,7 +1,7 @@ print "[lua] This is runme.lua" --- test program for embeded lua --- we do not need to load the library, as it was already in the intrepreter --- but lets check anyway +-- test program for embedded lua +-- we do not need to load the library, as it was already in the interpreter +-- but let's check anyway assert(type(example)=='table',"Don't appear to have loaded the example module") -- a test function to run the tests diff --git a/Examples/lua/embed2/Makefile b/Examples/lua/embed2/Makefile index fc309ac7e..d30ba0942 100644 --- a/Examples/lua/embed2/Makefile +++ b/Examples/lua/embed2/Makefile @@ -4,16 +4,17 @@ TARGET = embed2 SRCS = example.c INTERFACE = example.i LUA_INTERP = embed2.c +LIBS = -lm # this is a little different to normal as we have our own special interpreter # which we want to static link check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' lua_embed_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' lua_embed_run build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' LIBS='$(LIBS)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static clean: - $(MAKE) -f $(TOP)/Makefile lua_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean rm -f $(TARGET) diff --git a/Examples/lua/embed2/embed2.c b/Examples/lua/embed2/embed2.c index 8d28ee6ea..0ce9f8f7f 100644 --- a/Examples/lua/embed2/embed2.c +++ b/Examples/lua/embed2/embed2.c @@ -1,9 +1,9 @@ -/* embed2.c some more test for an embeded interpreter +/* embed2.c some more tests for an embedded interpreter This will go a bit further as it will pass values to and from the lua code. It uses less of the SWIG code, and more of the raw lua API's -What it will do is load the wrappered lib, load runme.lua and then call some functions. +What it will do is load the wrapped lib, load runme.lua and then call some functions. To make life easier, all the printf's have either [C] or [Lua] at the start so you can see where they are coming from. @@ -24,6 +24,7 @@ We will be using the luaL_dostring()/lua_dostring() function to call into lua #include #include +#include #include #include @@ -31,13 +32,16 @@ We will be using the luaL_dostring()/lua_dostring() function to call into lua #include #include +#if LUA_VERSION_NUM > 501 +#define lua_open luaL_newstate +#endif -/* the SWIG wrappered library */ +/* the SWIG wrapped library */ extern int luaopen_example(lua_State*L); /* This is an example of how to call the Lua function int add(int,int) - its very tedious, but gives you an idea of the issues involded. + its very tedious, but gives you an idea of the issues involved. (look below for a better idea) */ int call_add(lua_State *L,int a,int b,int* res) { @@ -46,11 +50,10 @@ int call_add(lua_State *L,int a,int b,int* res) { push a, push b, call 'add' check & return res */ top=lua_gettop(L); /* for later */ - lua_pushstring(L, "add"); /* function name */ - lua_gettable(L, LUA_GLOBALSINDEX); /* function to be called */ + lua_getglobal(L, "add"); /* function to be called */ if (!lua_isfunction(L,-1)) { printf("[C] error: cannot find function 'add'\n"); - lua_settop(L,top); // reset + lua_settop(L,top); return 0; } lua_pushnumber(L,a); @@ -58,25 +61,25 @@ int call_add(lua_State *L,int a,int b,int* res) { if (lua_pcall(L, 2, 1, 0) != 0) /* call function with 2 arguments and 1 result */ { printf("[C] error running function `add': %s\n",lua_tostring(L, -1)); - lua_settop(L,top); // reset + lua_settop(L,top); return 0; } - // check results + /* check results */ if (!lua_isnumber(L,-1)) { printf("[C] error: returned value is not a number\n"); - lua_settop(L,top); // reset + lua_settop(L,top); return 0; } *res=(int)lua_tonumber(L,-1); lua_settop(L,top); /* reset stack */ - return 1; // ok + return 1; } /* This is a variargs call function for calling from C into Lua. Original Code from Programming in Lua (PIL) by Roberto Ierusalimschy ISBN 85-903798-1-7 http://www.lua.org/pil/25.3.html -This has been modified slightly to make it compile, and its still a bit rough. +This has been modified slightly to make it compile, and it's still a bit rough. But it gives the idea of how to make it work. */ int call_va (lua_State *L,const char *func, const char *sig, ...) { @@ -187,20 +190,24 @@ int main(int argc,char* argv[]) { luaopen_example(L); printf("[C] all looks ok\n"); printf("\n"); - printf("[C] lets load the file 'runme.lua'\n"); + if (argc != 2 || argv[1] == NULL || strlen(argv[1]) == 0) { + printf("[C] ERROR: no lua file given on command line\n"); + exit(3); + } + printf("[C] let's load the file '%s'\n", argv[1]); printf("[C] any lua code in this file will be executed\n"); - if (luaL_loadfile(L, "runme.lua") || lua_pcall(L, 0, 0, 0)) { + if (luaL_loadfile(L, argv[1]) || lua_pcall(L, 0, 0, 0)) { printf("[C] ERROR: cannot run lua file: %s",lua_tostring(L, -1)); exit(3); } printf("[C] We are now back in C, all looks ok\n"); printf("\n"); - printf("[C] lets call the Lua function 'add(1,1)'\n"); + printf("[C] let's call the Lua function 'add(1,1)'\n"); printf("[C] using the C function 'call_add'\n"); ok=call_add(L,1,1,&res); printf("[C] the function returned %d with value %d\n",ok,res); printf("\n"); - printf("[C] lets do this rather easier\n"); + printf("[C] let's do this rather easier\n"); printf("[C] we will call the same Lua function using a generic C function 'call_va'\n"); ok=call_va(L,"add","ii>i",1,1,&res); printf("[C] the function returned %d with value %d\n",ok,res); diff --git a/Examples/lua/embed2/runme.lua b/Examples/lua/embed2/runme.lua index 73af9c5f2..9e7ab616c 100644 --- a/Examples/lua/embed2/runme.lua +++ b/Examples/lua/embed2/runme.lua @@ -1,7 +1,7 @@ print "[lua] This is runme.lua" --- test program for embeded lua --- we do not need to load the library, as it was already in the intrepreter --- but lets check anyway +-- test program for embedded lua +-- we do not need to load the library, as it was already in the interpreter +-- but let's check anyway assert(type(example)=='table',"Don't appear to have loaded the example module") -- note: we will copy the functions from example table into global diff --git a/Examples/lua/embed3/Makefile b/Examples/lua/embed3/Makefile index 8cfa97454..fc0026122 100644 --- a/Examples/lua/embed3/Makefile +++ b/Examples/lua/embed3/Makefile @@ -9,13 +9,13 @@ LUA_INTERP = embed3.cpp # which we want to static link # we also need the external runtime, so we can get access to certain internals of SWIG check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' lua_embed_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' lua_embed_run build: $(SWIG) -c++ -lua $(SWIGOPT) -external-runtime swigluarun.h - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static_cpp clean: - $(MAKE) -f $(TOP)/Makefile lua_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean rm -f swigluarun.h $(TARGET) diff --git a/Examples/lua/embed3/embed3.cpp b/Examples/lua/embed3/embed3.cpp index e5e0e0a7d..9be49add3 100644 --- a/Examples/lua/embed3/embed3.cpp +++ b/Examples/lua/embed3/embed3.cpp @@ -1,4 +1,4 @@ -/* embed3.cpp A C++ embeded interpreter +/* embed3.cpp A C++ embedded interpreter This will register a C++ class with Lua, and then call a Lua function passing C++ objects to this function. @@ -26,15 +26,19 @@ extern "C" { #include #include } - -/* The SWIG external runtime is generated by using. -swig -lua -externalruntime swigluarun.h -It contains useful function used by SWIG in its wrappering -SWIG_TypeQuery() SWIG_NewPointerObj() + +#if LUA_VERSION_NUM > 501 +#define lua_open luaL_newstate +#endif + +/* The SWIG external runtime is generated by using. +swig -lua -externalruntime swigluarun.h +It contains useful function used by SWIG in its wrapper +SWIG_TypeQuery() SWIG_NewPointerObj() */ #include "swigluarun.h" // the SWIG external runtime -/* the SWIG wrappered library */ +/* the SWIG wrapped library */ extern "C" int luaopen_example(lua_State*L); // the code itself @@ -65,8 +69,7 @@ int call_onEvent(lua_State *L, Event e) { push a, push b, call 'add' check & return res */ top = lua_gettop(L); /* for later */ - lua_pushstring(L, "onEvent"); /* function name */ - lua_gettable(L, LUA_GLOBALSINDEX); /* function to be called */ + lua_getglobal(L, "onEvent"); /* function to be called */ if (!lua_isfunction(L, -1)) { printf("[C++] error: cannot find function 'OnEvent'\n"); lua_settop(L, top); // reset @@ -97,10 +100,10 @@ int main(int argc, char* argv[]) { luaopen_example(L); printf("[C++] all looks ok\n"); printf("\n"); - printf("[C++] lets create an Engine and pass a pointer to Lua\n"); + printf("[C++] let's create an Engine and pass a pointer to Lua\n"); Engine engine; /* this code will pass a pointer into lua, but C++ still owns the object - this is a little tedious, to do, but lets do it + this is a little tedious, to do, but let's do it we need to pass the pointer (obviously), the type name and a flag which states if Lua should delete the pointer once its finished with it The type name is a class name string which is registered with SWIG @@ -110,16 +113,20 @@ int main(int argc, char* argv[]) { push_pointer(L,&engine,"Engine *",0); lua_setglobal(L, "pEngine"); // set as global variable - printf("[C++] now lets load the file 'runme.lua'\n"); + if (argc != 2 || argv[1] == NULL || strlen(argv[1]) == 0) { + printf("[C++] ERROR: no lua file given on command line\n"); + exit(3); + } + printf("[C++] now let's load the file '%s'\n", argv[1]); printf("[C++] any lua code in this file will be executed\n"); - if (luaL_loadfile(L, "runme.lua") || lua_pcall(L, 0, 0, 0)) { - printf("[C++] ERROR: cannot run lua file: %s", lua_tostring(L, -1)); + if (luaL_loadfile(L, argv[1]) || lua_pcall(L, 0, 0, 0)) { + printf("[C++] ERROR: cannot run lua file: %s",lua_tostring(L, -1)); exit(3); } printf("[C++] We are now back in C++, all looks ok\n"); printf("\n"); - printf("[C++] Lets call the Lua function onEvent(e)\n"); + printf("[C++] Let's call the Lua function onEvent(e)\n"); printf("[C++] We will give it different events, as we wish\n"); printf("[C++] Starting with STARTUP\n"); Event ev; diff --git a/Examples/lua/embed3/example.h b/Examples/lua/embed3/example.h index 41c13e9c1..df189e34b 100644 --- a/Examples/lua/embed3/example.h +++ b/Examples/lua/embed3/example.h @@ -13,7 +13,7 @@ public: }; -/* We also want to pass some events to Lua, so lets have a few classes +/* We also want to pass some events to Lua, so let's have a few classes to do this. */ class Event diff --git a/Examples/lua/embed3/runme.lua b/Examples/lua/embed3/runme.lua index 3a44bd2fc..8d5b1eada 100644 --- a/Examples/lua/embed3/runme.lua +++ b/Examples/lua/embed3/runme.lua @@ -1,7 +1,7 @@ print "[lua] This is runme.lua" --- test program for embeded lua --- we do not need to load the library, as it was already in the intrepreter --- but lets check anyway +-- test program for embedded lua +-- we do not need to load the library, as it was already in the interpreter +-- but let's check anyway assert(type(example)=='table',"Don't appear to have loaded the example module. Do not run this file directly, run the embed3 executable") @@ -13,12 +13,12 @@ else end --- the embed program expects a function void onEvent(Event) +-- the embedded program expects a function void onEvent(Event) -- this is it function onEvent(e) print("[Lua] onEvent with event",e.mType) - -- lets do something with the Engine + -- let's do something with the Engine -- nothing clever, but ... if e.mType==example.Event_STARTUP then pEngine:start() diff --git a/Examples/lua/exception/Makefile b/Examples/lua/exception/Makefile index 01bee5c6a..ac9c28b69 100644 --- a/Examples/lua/exception/Makefile +++ b/Examples/lua/exception/Makefile @@ -1,20 +1,20 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile lua_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile lua_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean diff --git a/Examples/lua/exception/runme.lua b/Examples/lua/exception/runme.lua index d8125caec..a798efca7 100644 --- a/Examples/lua/exception/runme.lua +++ b/Examples/lua/exception/runme.lua @@ -70,7 +70,7 @@ function b() t:message() end print [[ -Now lets call function a() +Now let's call function a() which calls b() which calls into C++ which will throw an exception!]] @@ -80,7 +80,7 @@ if ok then else print(" call failed with error:",res) end -print "Now lets do the same using xpcall(a,debug.traceback)" +print "Now let's do the same using xpcall(a,debug.traceback)" ok,res=xpcall(a,debug.traceback) if ok then print " that worked! Funny" diff --git a/Examples/lua/funcptr3/Makefile b/Examples/lua/funcptr3/Makefile index 00bfe7992..aeeaad469 100644 --- a/Examples/lua/funcptr3/Makefile +++ b/Examples/lua/funcptr3/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -LIBS = +LIBS = check: build - $(MAKE) -f $(TOP)/Makefile lua_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static clean: - $(MAKE) -f $(TOP)/Makefile lua_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean diff --git a/Examples/lua/functest/Makefile b/Examples/lua/functest/Makefile index 00bfe7992..aeeaad469 100644 --- a/Examples/lua/functest/Makefile +++ b/Examples/lua/functest/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -LIBS = +LIBS = check: build - $(MAKE) -f $(TOP)/Makefile lua_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static clean: - $(MAKE) -f $(TOP)/Makefile lua_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean diff --git a/Examples/lua/functest/example.i b/Examples/lua/functest/example.i index 631e0602d..9bb64cbf5 100644 --- a/Examples/lua/functest/example.i +++ b/Examples/lua/functest/example.i @@ -1,13 +1,12 @@ /* File : example.i */ %module example -%include "typemaps.i" // you must have this for the typemaps for ptrs -// basic function testing -// +%include "typemaps.i" + %inline %{ -extern int add1(int x, int y); // return x+y -- basic function test -extern void add2(int x, int *INPUT, int *OUTPUT); // *z = x+*y -- argin and argout test -extern int add3(int x, int y, int *OUTPUT); // return x+y, *z=x-y -- returning 2 values -extern void add4(int x, int *INOUT); // *y += x -- INOUT dual purpose variable +extern int add1(int x, int y); /* return x+y -- basic function test */ +extern void add2(int x, int *INPUT, int *OUTPUT); /* *z = x+*y -- argin and argout test */ +extern int add3(int x, int y, int *OUTPUT); /* return x+y, *z=x-y -- returning 2 values */ +extern void add4(int x, int *INOUT); /* *y += x -- INOUT dual purpose variable */ %} diff --git a/Examples/lua/functor/Makefile b/Examples/lua/functor/Makefile index 9220dfe51..e647fb2a8 100644 --- a/Examples/lua/functor/Makefile +++ b/Examples/lua/functor/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile lua_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile lua_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean diff --git a/Examples/lua/import.lua b/Examples/lua/import.lua index b2a40b017..4a0f0d3da 100644 --- a/Examples/lua/import.lua +++ b/Examples/lua/import.lua @@ -1,7 +1,7 @@ -- import -- the lua 5.0 loading mechanism is rather poor & relies upon the loadlib() fn -- the lua 5.1 loading mechanism is simplicity itself --- for now we need a bridge which will use the correct verion +-- for now we need a bridge which will use the correct version function import_5_0(module) -- imports the file into the program @@ -10,7 +10,7 @@ function import_5_0(module) -- and look for the fn 'Example_Init()' (note the capitalisation) if rawget(_G,module)~=nil then return end -- module appears to be loaded - -- capitialising the first letter + -- capitalising the first letter local c=string.upper(string.sub(module,1,1)) local fnname=c..string.sub(module,2).."_Init" @@ -26,7 +26,7 @@ function import_5_0(module) end assert(lib,"error loading module:"..module) - lib() -- execute the function: initalising the lib + lib() -- execute the function: initialising the lib local m=rawget(_G,module) -- gets the module object assert(m~=nil,"no module table found") end @@ -39,4 +39,4 @@ if string.sub(_VERSION,1,7)=='Lua 5.0' then import=import_5_0 else import=import_5_1 -end \ No newline at end of file +end diff --git a/Examples/lua/import/Makefile b/Examples/lua/import/Makefile index 0bf47c1a5..8d64a21c6 100644 --- a/Examples/lua/import/Makefile +++ b/Examples/lua/import/Makefile @@ -2,19 +2,19 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig SWIGOPT = LIBS = - + check: build - $(MAKE) -f $(TOP)/Makefile lua_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' lua_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' lua_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' lua_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' lua_cpp clean: - $(MAKE) -f $(TOP)/Makefile lua_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean diff --git a/Examples/lua/nspace/Makefile b/Examples/lua/nspace/Makefile new file mode 100644 index 000000000..17757c2ec --- /dev/null +++ b/Examples/lua/nspace/Makefile @@ -0,0 +1,19 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = +TARGET = example +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean diff --git a/Examples/lua/nspace/example.h b/Examples/lua/nspace/example.h new file mode 100644 index 000000000..53066980a --- /dev/null +++ b/Examples/lua/nspace/example.h @@ -0,0 +1,23 @@ +#ifndef _example_guardian_ +#define _example_guardian_ + +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; } + }; + } +} + +#endif diff --git a/Examples/lua/nspace/example.i b/Examples/lua/nspace/example.i new file mode 100644 index 000000000..c30f87fec --- /dev/null +++ b/Examples/lua/nspace/example.i @@ -0,0 +1,10 @@ +%module example + +%{ +#include "example.h" +%} + +%nspace MyWorld::Nested::Dweller; +%nspace MyWorld::World; + +%include "example.h" diff --git a/Examples/lua/nspace/runme.lua b/Examples/lua/nspace/runme.lua new file mode 100644 index 000000000..876814052 --- /dev/null +++ b/Examples/lua/nspace/runme.lua @@ -0,0 +1,46 @@ +-- file: runme.lua + +-- This file illustrates class C++ interface generated +-- by SWIG. + +---- importing ---- +if string.sub(_VERSION,1,7)=='Lua 5.0' then + -- lua5.0 doesnt have a nice way to do this + lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example') + assert(lib)() +else + -- lua 5.1 does + require('example') +end + +ex = example + +-- Calling a module function ( aka global function ) +assert( ex.module_function() == 7 ) +print("example.module_function(): ", ex.module_function()) + +-- Accessing a module (aka global) variable +assert( ex.module_variable == 9 ) +print("example.module_variable: ", ex.module_variable) + +-- Creating an instance of the class +w1 = ex.MyWorld.World() +print("Creating class instance: w1 = ex.MyWorld.World(): ", w1) + +-- Accessing class members +assert( ex.MyWorld.World():create_world() == 17 ) +print( "w1:create_world() = ", w1:create_world() ) +assert( w1:create_world() == 17 ) +print( "w1:world_max_count = ", w1.world_max_count ) +assert( w1.world_max_count == 9 ) + +-- Accessing enums from class within namespace +print( "Accessing enums: ex.MyWorld.Nested.Dweller.MALE = ", ex.MyWorld.Nested.Dweller.MALE ) +assert( ex.MyWorld.Nested.Dweller.MALE == 0 ) +print( "Accessing enums: ex.MyWorld.Nested.Dweller.FEMALE = ", ex.MyWorld.Nested.Dweller.FEMALE ) +assert( ex.MyWorld.Nested.Dweller.FEMALE == 1 ) + +-- Accessing static member function +print( "Accessing static member function: ex.MyWorld.Nested.Dweller.count() = ", ex.MyWorld.Nested.Dweller.count() ) +assert( ex.MyWorld.Nested.Dweller.count() == 19 ) + diff --git a/Examples/lua/owner/Makefile b/Examples/lua/owner/Makefile index c39e8acdf..96308f0df 100644 --- a/Examples/lua/owner/Makefile +++ b/Examples/lua/owner/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile lua_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile lua_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean diff --git a/Examples/lua/owner/example.cxx b/Examples/lua/owner/example.cxx index bce484aea..c2c073d79 100644 --- a/Examples/lua/owner/example.cxx +++ b/Examples/lua/owner/example.cxx @@ -39,12 +39,15 @@ Square* createSquare(double w) return new Square(w); } -ShapeOwner::ShapeOwner() {printf(" ShapeOwner(%p)\n",this);} +ShapeOwner::ShapeOwner() { + printf(" ShapeOwner(%p)\n", (void *)this); +} + ShapeOwner::~ShapeOwner() { - printf(" ~ShapeOwner(%p)\n",this); - for(unsigned i=0;i x : 0, ptptr ? ptptr->y : 0); + printf("ptptr = %p (%d, %d)\n", (void *)ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); printf("pt = (%d, %d)\n", pt.x, pt.y); printf("status = %d\n", status); } diff --git a/Examples/modula3/class/Makefile b/Examples/modula3/class/Makefile index 9976e6f80..2e2f37526 100644 --- a/Examples/modula3/class/Makefile +++ b/Examples/modula3/class/Makefile @@ -1,6 +1,6 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example PLATFORM = LINUXLIBC6 INTERFACE = example.i @@ -8,10 +8,10 @@ SWIGOPT = -c++ MODULA3SRCS = *.[im]3 check: build - $(MAKE) -f $(TOP)/Makefile modula3_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3 m3ppinplace $(MODULA3SRCS) # compilation of example_wrap.cxx is started by cm3 @@ -21,4 +21,4 @@ build: cm3 clean: - $(MAKE) -f $(TOP)/Makefile modula3_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_clean diff --git a/Examples/modula3/class/example.cxx b/Examples/modula3/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/modula3/class/example.cxx +++ b/Examples/modula3/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -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; } diff --git a/Examples/modula3/class/example.h b/Examples/modula3/class/example.h index 9c1f47995..0dff185b2 100644 --- a/Examples/modula3/class/example.h +++ b/Examples/modula3/class/example.h @@ -1,44 +1,34 @@ /* File : example.h */ -class Shape -{ +class Shape { public: - Shape () - { + Shape() { nshapes++; } - virtual ~ Shape () - { + virtual ~Shape() { nshapes--; - }; - double x, y; - void move (double dx, double dy); - virtual double area (void) const = 0; - virtual double perimeter (void) const = 0; -protected: - static int nshapes; + } + double x, y; + void move(double dx, double dy); + virtual double area() = 0; + virtual double perimeter() = 0; + static int nshapes; }; -class Circle:public Shape -{ +class Circle : public Shape { private: double radius; public: - Circle (double r):radius (r) - { - }; - virtual double area (void) const; - virtual double perimeter (void) const; + Circle(double r) : radius(r) { } + virtual double area(); + virtual double perimeter(); }; -class Square:public Shape -{ +class Square : public Shape { private: double width; public: - Square (double w):width (w) - { - }; - virtual double area (void) const; - virtual double perimeter (void) const; + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; diff --git a/Examples/modula3/enum/Makefile b/Examples/modula3/enum/Makefile index a3b499823..3915e5405 100644 --- a/Examples/modula3/enum/Makefile +++ b/Examples/modula3/enum/Makefile @@ -1,6 +1,6 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i CONSTNUMERIC = example_const @@ -8,18 +8,18 @@ SWIGOPT = -c++ MODULA3SRCS = *.[im]3 check: build - $(MAKE) -f $(TOP)/Makefile modula3_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run build: $(SWIG) -modula3 $(SWIGOPT) -module Example -generateconst $(CONSTNUMERIC) $(TARGET).h $(CXX) -Wall $(CONSTNUMERIC).c -o $(CONSTNUMERIC) $(CONSTNUMERIC) >$(CONSTNUMERIC).i - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3 m3ppinplace $(MODULA3SRCS) mv m3makefile $(MODULA3SRCS) src/ cm3 clean: - $(MAKE) -f $(TOP)/Makefile modula3_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_clean diff --git a/Examples/modula3/exception/Makefile b/Examples/modula3/exception/Makefile index 8d4525512..1dbf1a156 100644 --- a/Examples/modula3/exception/Makefile +++ b/Examples/modula3/exception/Makefile @@ -8,15 +8,15 @@ MODULA3SRCS = *.[im]3 MODULA3FLAGS= -o runme check: build - $(MAKE) -f $(TOP)/Makefile modula3_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3_cpp -# $(MAKE) -f $(TOP)/Makefile MODULA3SRCS='$(MODULA3SRCS)' MODULA3FLAGS='$(MODULA3FLAGS)' modula3_compile +# $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MODULA3SRCS='$(MODULA3SRCS)' MODULA3FLAGS='$(MODULA3FLAGS)' modula3_compile m3ppinplace $(MODULA3SRCS) mv m3makefile $(MODULA3SRCS) src/ cm3 clean: - $(MAKE) -f $(TOP)/Makefile modula3_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_clean diff --git a/Examples/modula3/reference/Makefile b/Examples/modula3/reference/Makefile index 62183931e..3b68fe822 100644 --- a/Examples/modula3/reference/Makefile +++ b/Examples/modula3/reference/Makefile @@ -1,20 +1,20 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i SWIGOPT = -c++ MODULA3SRCS = *.[im]3 check: build - $(MAKE) -f $(TOP)/Makefile modula3_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3 m3ppinplace $(MODULA3SRCS) mv m3makefile $(MODULA3SRCS) src/ cm3 clean: - $(MAKE) -f $(TOP)/Makefile modula3_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_clean diff --git a/Examples/modula3/reference/example.cxx b/Examples/modula3/reference/example.cxx index 649b0169c..9dbaed2ee 100644 --- a/Examples/modula3/reference/example.cxx +++ b/Examples/modula3/reference/example.cxx @@ -19,7 +19,7 @@ Vector operator+(const Vector &a, const Vector &b) { char *Vector::print() { static char temp[512]; - sprintf(temp,"Vector %x (%g,%g,%g)", (int)this, x,y,z); + sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z); return temp; } diff --git a/Examples/modula3/simple/Makefile b/Examples/modula3/simple/Makefile index 6a0ca4f0e..2796b25f8 100644 --- a/Examples/modula3/simple/Makefile +++ b/Examples/modula3/simple/Makefile @@ -1,20 +1,20 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i SWIGOPT = MODULA3SRCS = *.[im]3 check: build - $(MAKE) -f $(TOP)/Makefile modula3_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3 m3ppinplace $(MODULA3SRCS) mv m3makefile $(MODULA3SRCS) src/ cm3 clean: - $(MAKE) -f $(TOP)/Makefile modula3_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_clean diff --git a/Examples/modula3/typemap/Makefile b/Examples/modula3/typemap/Makefile index 6a0ca4f0e..2796b25f8 100644 --- a/Examples/modula3/typemap/Makefile +++ b/Examples/modula3/typemap/Makefile @@ -1,20 +1,20 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i SWIGOPT = MODULA3SRCS = *.[im]3 check: build - $(MAKE) -f $(TOP)/Makefile modula3_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' modula3 m3ppinplace $(MODULA3SRCS) mv m3makefile $(MODULA3SRCS) src/ cm3 clean: - $(MAKE) -f $(TOP)/Makefile modula3_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' modula3_clean diff --git a/Examples/mzscheme/multimap/Makefile b/Examples/mzscheme/multimap/Makefile index d1b4a3f39..ecf83fbeb 100644 --- a/Examples/mzscheme/multimap/Makefile +++ b/Examples/mzscheme/multimap/Makefile @@ -3,13 +3,13 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile mzscheme_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme clean: - $(MAKE) -f $(TOP)/Makefile mzscheme_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean diff --git a/Examples/mzscheme/simple/Makefile b/Examples/mzscheme/simple/Makefile index d1b4a3f39..ecf83fbeb 100644 --- a/Examples/mzscheme/simple/Makefile +++ b/Examples/mzscheme/simple/Makefile @@ -3,13 +3,13 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile mzscheme_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme clean: - $(MAKE) -f $(TOP)/Makefile mzscheme_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean diff --git a/Examples/mzscheme/std_vector/Makefile b/Examples/mzscheme/std_vector/Makefile index 28b91158a..75918a61e 100644 --- a/Examples/mzscheme/std_vector/Makefile +++ b/Examples/mzscheme/std_vector/Makefile @@ -1,20 +1,20 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = GPP = `which g++` MZC = test -n "/usr/bin/mzc" && /usr/bin/mzc check: build - $(MAKE) -f $(TOP)/Makefile mzscheme_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run build: $(SWIG) -mzscheme -c++ $(SWIGOPT) $(INTERFACE) $(MZC) --compiler $(GPP) ++ccf "-I." --cc example_wrap.cxx - $(MZC) --linker $(GPP) --ld $(TARGET).so example_wrap.o - + $(MZC) --linker $(GPP) --ld $(TARGET).so example_wrap.o + clean: - $(MAKE) -f $(TOP)/Makefile mzscheme_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean diff --git a/Examples/ocaml/argout_ref/Makefile b/Examples/ocaml/argout_ref/Makefile index 4e12e3769..09893af65 100644 --- a/Examples/ocaml/argout_ref/Makefile +++ b/Examples/ocaml/argout_ref/Makefile @@ -8,21 +8,21 @@ PROGFILE = example_prog.ml OBJS = example.o check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run build: static static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp dynamic: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic_cpp clean: - $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MLFILE='$(MLFILE)' ocaml_clean diff --git a/Examples/ocaml/contract/Makefile b/Examples/ocaml/contract/Makefile index 91d39247e..df5d6a6f5 100644 --- a/Examples/ocaml/contract/Makefile +++ b/Examples/ocaml/contract/Makefile @@ -1,34 +1,34 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i MLFILE = example.ml PROGFILE = example_prog.ml -OBJS = +OBJS = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run build: static dynamic: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static toplevel: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_toplevel clean: - $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MLFILE='$(MLFILE)' ocaml_clean diff --git a/Examples/ocaml/scoped_enum/Makefile b/Examples/ocaml/scoped_enum/Makefile index 4920e3b3b..794733971 100644 --- a/Examples/ocaml/scoped_enum/Makefile +++ b/Examples/ocaml/scoped_enum/Makefile @@ -1,34 +1,34 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i MLFILE = example.ml PROGFILE = example_prog.ml -OBJS = +OBJS = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run build: static dynamic: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic_cpp static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp toplevel: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp_toplevel clean: - $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MLFILE='$(MLFILE)' ocaml_clean diff --git a/Examples/ocaml/shapes/Makefile b/Examples/ocaml/shapes/Makefile index 38230eb69..69102f3b1 100644 --- a/Examples/ocaml/shapes/Makefile +++ b/Examples/ocaml/shapes/Makefile @@ -1,6 +1,6 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SWIGOPT = +SWIGOPT = SRCS = example.c TARGET = example INTERFACE = example.i @@ -9,27 +9,27 @@ PROGFILE = example_prog.ml OBJS = example.o check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run build: static static_top static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp static_top: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp_toplevel dynamic: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic_cpp clean: - $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MLFILE='$(MLFILE)' ocaml_clean diff --git a/Examples/ocaml/simple/Makefile b/Examples/ocaml/simple/Makefile index 64c7256c1..49bf81c1e 100644 --- a/Examples/ocaml/simple/Makefile +++ b/Examples/ocaml/simple/Makefile @@ -8,27 +8,27 @@ PROGFILE = example_prog.ml OBJS = example.o check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run build: static dynamic: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static toplevel: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \ PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_toplevel clean: - $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MLFILE='$(MLFILE)' ocaml_clean diff --git a/Examples/ocaml/std_string/Makefile b/Examples/ocaml/std_string/Makefile index 0250cfd2d..8f8b2f684 100644 --- a/Examples/ocaml/std_string/Makefile +++ b/Examples/ocaml/std_string/Makefile @@ -1,24 +1,24 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i PROGFILE = runme.ml check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run build: static static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp dynamic: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_dynamic_cpp clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_clean diff --git a/Examples/ocaml/std_vector/Makefile b/Examples/ocaml/std_vector/Makefile index 0250cfd2d..8f8b2f684 100644 --- a/Examples/ocaml/std_vector/Makefile +++ b/Examples/ocaml/std_vector/Makefile @@ -1,24 +1,24 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i PROGFILE = runme.ml check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run build: static static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp dynamic: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_dynamic_cpp clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_clean diff --git a/Examples/ocaml/stl/Makefile b/Examples/ocaml/stl/Makefile index 545f3229a..e4cce4883 100644 --- a/Examples/ocaml/stl/Makefile +++ b/Examples/ocaml/stl/Makefile @@ -1,34 +1,34 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i PROGFILE = runme.ml check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run build: static static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp director: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp_director dynamic: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp toplevel: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp_toplevel clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_clean diff --git a/Examples/ocaml/string_from_ptr/Makefile b/Examples/ocaml/string_from_ptr/Makefile index f7b808934..294bdec83 100644 --- a/Examples/ocaml/string_from_ptr/Makefile +++ b/Examples/ocaml/string_from_ptr/Makefile @@ -1,35 +1,35 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig SWIGOPT = -c++ -SRCS = +SRCS = TARGET = example INTERFACE = foolib.i MLFILE = foolib.ml PROGFILE = example_prog.ml -OBJS = +OBJS = check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run build: static static_top static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp static_top: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_static_cpp_toplevel dynamic: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \ ocaml_dynamic_cpp clean: - $(MAKE) -f $(TOP)/Makefile MLFILE='$(MLFILE)' ocaml_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MLFILE='$(MLFILE)' ocaml_clean diff --git a/Examples/ocaml/strings_test/Makefile b/Examples/ocaml/strings_test/Makefile index 14f55e0d9..b6b866669 100644 --- a/Examples/ocaml/strings_test/Makefile +++ b/Examples/ocaml/strings_test/Makefile @@ -1,29 +1,29 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i PROGFILE = runme.ml check: build - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run build: static top static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp dynamic: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp top: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ ocaml_static_cpp_toplevel clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' ocaml_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_clean diff --git a/Examples/octave/callback/Makefile b/Examples/octave/callback/Makefile index d38d7f896..3b746de2f 100644 --- a/Examples/octave/callback/Makefile +++ b/Examples/octave/callback/Makefile @@ -1,17 +1,3 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx -TARGET = swigexample -INTERFACE = example.i -LIBS = -lm -SWIGOPT = +CXXSRCS = example.cxx -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean +include $(SRCDIR)../example.mk diff --git a/Examples/octave/class/Makefile b/Examples/octave/class/Makefile index d38d7f896..3b746de2f 100644 --- a/Examples/octave/class/Makefile +++ b/Examples/octave/class/Makefile @@ -1,17 +1,3 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx -TARGET = swigexample -INTERFACE = example.i -LIBS = -lm -SWIGOPT = +CXXSRCS = example.cxx -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean +include $(SRCDIR)../example.mk diff --git a/Examples/octave/class/example.cxx b/Examples/octave/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/octave/class/example.cxx +++ b/Examples/octave/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -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; } diff --git a/Examples/octave/class/example.h b/Examples/octave/class/example.h index 0d4527e92..0dff185b2 100644 --- a/Examples/octave/class/example.h +++ b/Examples/octave/class/example.h @@ -7,11 +7,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; }; @@ -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(); }; diff --git a/Examples/octave/constants/Makefile b/Examples/octave/constants/Makefile index 03501bd81..acf4d0575 100644 --- a/Examples/octave/constants/Makefile +++ b/Examples/octave/constants/Makefile @@ -1,17 +1,3 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = -TARGET = swigexample -INTERFACE = example.i -LIBS = -lm -SWIGOPT = +CXXSRCS = -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean +include $(SRCDIR)../example.mk diff --git a/Examples/octave/contract/Makefile b/Examples/octave/contract/Makefile index 73e3962ed..413b64bbd 100644 --- a/Examples/octave/contract/Makefile +++ b/Examples/octave/contract/Makefile @@ -1,15 +1,3 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -SRCS = example.c -TARGET = swigexample -INTERFACE = example.i +SRCS = example.c -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean +include $(SRCDIR)../example.mk diff --git a/Examples/octave/enum/Makefile b/Examples/octave/enum/Makefile index d38d7f896..3b746de2f 100644 --- a/Examples/octave/enum/Makefile +++ b/Examples/octave/enum/Makefile @@ -1,17 +1,3 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx -TARGET = swigexample -INTERFACE = example.i -LIBS = -lm -SWIGOPT = +CXXSRCS = example.cxx -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean +include $(SRCDIR)../example.mk diff --git a/Examples/octave/example.mk b/Examples/octave/example.mk new file mode 100644 index 000000000..e0b1e4efb --- /dev/null +++ b/Examples/octave/example.mk @@ -0,0 +1,32 @@ +# Note: as a convention an example must be in a child directory of this. +# These paths are relative to such an example directory + +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +TARGET = swigexample +INTERFACE = example.i + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' octave_run + +build: +ifneq (,$(SRCS)) + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave +else + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp +endif +ifneq (,$(TARGET2)$(SWIGOPT2)) +ifneq (,$(SRCS)) + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT2)' TARGET='$(TARGET2)' INTERFACE='$(INTERFACE)' octave +else + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT2)' TARGET='$(TARGET2)' INTERFACE='$(INTERFACE)' octave_cpp +endif +endif + + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' octave_clean diff --git a/Examples/octave/extend/Makefile b/Examples/octave/extend/Makefile index d38d7f896..3b746de2f 100644 --- a/Examples/octave/extend/Makefile +++ b/Examples/octave/extend/Makefile @@ -1,17 +1,3 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx -TARGET = swigexample -INTERFACE = example.i -LIBS = -lm -SWIGOPT = +CXXSRCS = example.cxx -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean +include $(SRCDIR)../example.mk diff --git a/Examples/octave/extend/example.h b/Examples/octave/extend/example.h index 9e15cf8e4..77a26ec95 100644 --- a/Examples/octave/extend/example.h +++ b/Examples/octave/extend/example.h @@ -14,7 +14,7 @@ public: virtual std::string getTitle() { return getPosition() + " " + getName(); } virtual std::string getName() { return name; } virtual std::string getPosition() const { return "Employee"; } - virtual ~Employee() { printf("~Employee() @ %p\n", this); } + virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); } }; diff --git a/Examples/octave/funcptr/Makefile b/Examples/octave/funcptr/Makefile index 73e3962ed..413b64bbd 100644 --- a/Examples/octave/funcptr/Makefile +++ b/Examples/octave/funcptr/Makefile @@ -1,15 +1,3 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -SRCS = example.c -TARGET = swigexample -INTERFACE = example.i +SRCS = example.c -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean +include $(SRCDIR)../example.mk diff --git a/Examples/octave/funcptr2/Makefile b/Examples/octave/funcptr2/Makefile index 73e3962ed..413b64bbd 100644 --- a/Examples/octave/funcptr2/Makefile +++ b/Examples/octave/funcptr2/Makefile @@ -1,15 +1,3 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -SRCS = example.c -TARGET = swigexample -INTERFACE = example.i +SRCS = example.c -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean +include $(SRCDIR)../example.mk diff --git a/Examples/octave/functor/Makefile b/Examples/octave/functor/Makefile index 94fb96337..acf4d0575 100644 --- a/Examples/octave/functor/Makefile +++ b/Examples/octave/functor/Makefile @@ -1,17 +1,3 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = -TARGET = swigexample -INTERFACE = example.i -LIBS = -lm -SWIGOPT = +CXXSRCS = -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean +include $(SRCDIR)../example.mk diff --git a/Examples/octave/module_load/Makefile b/Examples/octave/module_load/Makefile index e388763bd..d2cd66e70 100644 --- a/Examples/octave/module_load/Makefile +++ b/Examples/octave/module_load/Makefile @@ -1,18 +1,7 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -SRCS = example.c -TARGET = swigexample -INTERFACE = example.i +SRCS = example.c +TARGET = swigexample +SWIGOPT = -module swigexample +TARGET2 = swigexample2 +SWIGOPT2 = -module swigexample2 -globals . -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' SWIGOPT='-module $$(TARGET)' INTERFACE='$(INTERFACE)' octave - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)2' SWIGOPT='-module $$(TARGET) -globals .' INTERFACE='$(INTERFACE)' octave - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean - rm -f $(TARGET).m +include $(SRCDIR)../example.mk diff --git a/Examples/octave/operator/Makefile b/Examples/octave/operator/Makefile index 94fb96337..acf4d0575 100644 --- a/Examples/octave/operator/Makefile +++ b/Examples/octave/operator/Makefile @@ -1,17 +1,3 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = -TARGET = swigexample -INTERFACE = example.i -LIBS = -lm -SWIGOPT = +CXXSRCS = -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean +include $(SRCDIR)../example.mk diff --git a/Examples/octave/pointer/Makefile b/Examples/octave/pointer/Makefile index 73e3962ed..413b64bbd 100644 --- a/Examples/octave/pointer/Makefile +++ b/Examples/octave/pointer/Makefile @@ -1,15 +1,3 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -SRCS = example.c -TARGET = swigexample -INTERFACE = example.i +SRCS = example.c -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean +include $(SRCDIR)../example.mk diff --git a/Examples/octave/reference/Makefile b/Examples/octave/reference/Makefile index d38d7f896..3b746de2f 100644 --- a/Examples/octave/reference/Makefile +++ b/Examples/octave/reference/Makefile @@ -1,17 +1,3 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = example.cxx -TARGET = swigexample -INTERFACE = example.i -LIBS = -lm -SWIGOPT = +CXXSRCS = example.cxx -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean +include $(SRCDIR)../example.mk diff --git a/Examples/octave/reference/example.cxx b/Examples/octave/reference/example.cxx index 9b72ca6a2..632a03a5b 100644 --- a/Examples/octave/reference/example.cxx +++ b/Examples/octave/reference/example.cxx @@ -19,7 +19,7 @@ Vector operator+(const Vector &a, const Vector &b) { char *Vector::print() { static char temp[512]; - sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z); + sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z); return temp; } diff --git a/Examples/octave/simple/Makefile b/Examples/octave/simple/Makefile index 73e3962ed..413b64bbd 100644 --- a/Examples/octave/simple/Makefile +++ b/Examples/octave/simple/Makefile @@ -1,15 +1,3 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -SRCS = example.c -TARGET = swigexample -INTERFACE = example.i +SRCS = example.c -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean +include $(SRCDIR)../example.mk diff --git a/Examples/octave/template/Makefile b/Examples/octave/template/Makefile index 94fb96337..acf4d0575 100644 --- a/Examples/octave/template/Makefile +++ b/Examples/octave/template/Makefile @@ -1,17 +1,3 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -CXXSRCS = -TARGET = swigexample -INTERFACE = example.i -LIBS = -lm -SWIGOPT = +CXXSRCS = -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean +include $(SRCDIR)../example.mk diff --git a/Examples/octave/variables/Makefile b/Examples/octave/variables/Makefile index 73e3962ed..413b64bbd 100644 --- a/Examples/octave/variables/Makefile +++ b/Examples/octave/variables/Makefile @@ -1,15 +1,3 @@ -TOP = ../.. -SWIG = $(TOP)/../preinst-swig -SRCS = example.c -TARGET = swigexample -INTERFACE = example.i +SRCS = example.c -check: build - $(MAKE) -f $(TOP)/Makefile octave_run - -build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave - -clean: - $(MAKE) -f $(TOP)/Makefile octave_clean +include $(SRCDIR)../example.mk diff --git a/Examples/octave/variables/example.c b/Examples/octave/variables/example.c index 15dcc1b8e..a9102a9d5 100644 --- a/Examples/octave/variables/example.c +++ b/Examples/octave/variables/example.c @@ -51,10 +51,10 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); - printf("iptrvar = %p\n", iptrvar); + printf("cstrvar = %s\n", cstrvar); + printf("iptrvar = %p\n", (void *)iptrvar); printf("name = %s\n", name); - printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); + printf("ptptr = %p (%d, %d)\n", (void *)ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); printf("pt = (%d, %d)\n", pt.x, pt.y); printf("status = %d\n", status); } diff --git a/Examples/perl5/callback/Makefile b/Examples/perl5/callback/Makefile new file mode 100644 index 000000000..0d1cc574f --- /dev/null +++ b/Examples/perl5/callback/Makefile @@ -0,0 +1,20 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +LIBS = -lm + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/callback/example.cxx b/Examples/perl5/callback/example.cxx new file mode 100644 index 000000000..450d75608 --- /dev/null +++ b/Examples/perl5/callback/example.cxx @@ -0,0 +1,4 @@ +/* File : example.cxx */ + +#include "example.h" + diff --git a/Examples/perl5/callback/example.h b/Examples/perl5/callback/example.h new file mode 100644 index 000000000..1a0e8c432 --- /dev/null +++ b/Examples/perl5/callback/example.h @@ -0,0 +1,23 @@ +/* File : example.h */ + +#include +#include + +class Callback { +public: + virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; } + virtual void run() { std::cout << "Callback::run()" << std::endl; } +}; + + +class Caller { +private: + Callback *_callback; +public: + Caller(): _callback(0) {} + ~Caller() { delCallback(); } + void delCallback() { delete _callback; _callback = 0; } + void setCallback(Callback *cb) { delCallback(); _callback = cb; } + void call() { if (_callback) _callback->run(); } +}; + diff --git a/Examples/perl5/callback/example.i b/Examples/perl5/callback/example.i new file mode 100644 index 000000000..5f9072e61 --- /dev/null +++ b/Examples/perl5/callback/example.i @@ -0,0 +1,17 @@ +/* File : example.i */ +%module(directors="1") example +%{ +#include "example.h" +%} + +%include "std_string.i" + +/* turn on director wrapping Callback */ +%feature("director") Callback; + +/* Caller::setCallback(Callback *cb) gives ownership of the cb to the + * Caller object. The wrapper code should understand this. */ +%apply SWIGTYPE *DISOWN { Callback *cb }; + +%include "example.h" + diff --git a/Examples/perl5/callback/index.html b/Examples/perl5/callback/index.html new file mode 100644 index 000000000..82f5e972a --- /dev/null +++ b/Examples/perl5/callback/index.html @@ -0,0 +1,20 @@ + + + SWIG:Examples:perl5:callback + + + + + +SWIG/Examples/perl/callback/ +
+ +Implementing C++ callbacks in Perl
+ ++This example illustrates how to use directors to implement C++ callbacks. +
+ +
+ + diff --git a/Examples/perl5/callback/runme.pl b/Examples/perl5/callback/runme.pl new file mode 100644 index 000000000..54d86783a --- /dev/null +++ b/Examples/perl5/callback/runme.pl @@ -0,0 +1,48 @@ +# file: runme.pl + +# This file illustrates the cross language polymorphism using directors. + +use example; + + +{ + package PlCallback; + use base 'example::Callback'; + sub run { + print "PlCallback->run()\n"; + } +} + +# Create an Caller instance + +$caller = example::Caller->new(); + +# Add a simple C++ callback (caller owns the callback, so +# we disown it first by clearing the .thisown flag). + +print "Adding and calling a normal C++ callback\n"; +print "----------------------------------------\n"; + +$callback = example::Callback->new(); +$callback->DISOWN(); +$caller->setCallback($callback); +$caller->call(); +$caller->delCallback(); + +print "\n"; +print "Adding and calling a Perl callback\n"; +print "----------------------------------\n"; + +# Add a Perl callback (caller owns the callback, so we +# disown it first by calling DISOWN). + +$callback = PlCallback->new(); +$callback->DISOWN(); +$caller->setCallback($callback); +$caller->call(); +$caller->delCallback(); + +# All done. + +print "\n"; +print "perl exit\n"; diff --git a/Examples/perl5/check.list b/Examples/perl5/check.list index e15f02e18..dda849311 100644 --- a/Examples/perl5/check.list +++ b/Examples/perl5/check.list @@ -1,7 +1,9 @@ # see top-level Makefile.in +callback class constants constants2 +extend funcptr import java diff --git a/Examples/perl5/class/Makefile b/Examples/perl5/class/Makefile index 544d13642..0d1cc574f 100644 --- a/Examples/perl5/class/Makefile +++ b/Examples/perl5/class/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/class/example.cxx b/Examples/perl5/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/perl5/class/example.cxx +++ b/Examples/perl5/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -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; } diff --git a/Examples/perl5/class/example.h b/Examples/perl5/class/example.h index b0671d583..fd6943541 100644 --- a/Examples/perl5/class/example.h +++ b/Examples/perl5/class/example.h @@ -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,29 +19,24 @@ 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(); }; typedef Square TSquare; class CFoo { public: - static Square MakeSquare(void) {return Square(4.0);}; - static TSquare MakeTSquare(void) {return Square(4.0);}; + static Square MakeSquare(void) {return Square(4.0);} + static TSquare MakeTSquare(void) {return Square(4.0);} }; - - - - - diff --git a/Examples/perl5/class/example.i b/Examples/perl5/class/example.i index 23ee8a822..fbdf7249f 100644 --- a/Examples/perl5/class/example.i +++ b/Examples/perl5/class/example.i @@ -6,6 +6,4 @@ %} /* Let's just grab the original header file here */ - %include "example.h" - diff --git a/Examples/perl5/class/index.html b/Examples/perl5/class/index.html index 58a50ad2e..b4f923b5a 100644 --- a/Examples/perl5/class/index.html +++ b/Examples/perl5/class/index.html @@ -32,8 +32,8 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); virtual double area() = 0; virtual double perimeter() = 0; @@ -44,7 +44,7 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; + Circle(double r) : radius(r) { } virtual double area(); virtual double perimeter(); }; @@ -53,7 +53,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } virtual double area(); virtual double perimeter(); }; @@ -82,7 +82,7 @@ like this: Note: when creating a C++ extension, you must run SWIG with the -c++ option like this:@@ -97,60 +97,45 @@ Click here to see a script that calls the C++ functions f-% swig -c++ -python example.i +% swig -c++ -perl example.i-$c = example::new_Circle(10.0); +$c = new example::Circle(10.0);-
- To access member data, a pair of accessor functions are used. -For example: +
- You can access member data like so:
- -Note: when accessing member data, the name of the class in which -the data member is defined is used. For example Shape_x_get(). - --example::Shape_x_set($c,15); # Set member data -$x = example::Shape_x_get($c); # Get member data ---
- To invoke a member function, you simply do this - -
--print "The area is ", example::Shape_area($c); +$c->{x} = 15; # Set member data +$x = $c->{x}; # Get member data-
- Type checking knows about the inheritance structure of C++. For example: +
- To invoke a member function, you simply do this:
-example::Shape_area($c); # Works (c is a Shape) -example::Circle_area($c); # Works (c is a Circle) -example::Square_area($c); # Fails (c is definitely not a Square) +print "The area is ", $c->area();-
- To invoke a destructor, simply do this +
- To invoke a destructor, simply do this:
-example::delete_Shape($c); # Deletes a shape +$c->DESTROY(); # Deletes a shape-
- Static member variables are wrapped as C global variables. For example: +
- Static member variables are wrapped like so:
@@ -159,47 +144,11 @@ $example::Shapes_nshapes = 13; # Set a static data member-$n = $example::Shape_nshapes; # Get a static data member -$example::Shapes_nshapes = 13; # Set a static data member +$n = $example::Shape::nshapes; # Get a static data member +$example::Shapes::nshapes = 13; # Set a static data memberGeneral Comments
-
- This low-level interface is not the only way to handle C++ code. Proxy classes -provide a much higher-level interface. - -
-
- SWIG *does* know how to properly perform upcasting of objects in an inheritance +
- SWIG does know how to properly perform upcasting of objects in an inheritance hierarchy (including multiple inheritance). Therefore it is perfectly safe to pass an object of a derived class to any function involving a base class. -
-
- A wide variety of C++ features are not currently supported by SWIG. Here is the -short and incomplete list: - -
-
-
diff --git a/Examples/perl5/class/runme.pl b/Examples/perl5/class/runme.pl index 076e1437b..e45e2b8ce 100644 --- a/Examples/perl5/class/runme.pl +++ b/Examples/perl5/class/runme.pl @@ -40,7 +40,7 @@ foreach $o ($c,$s) { print " $o\n"; print " area = ", $o->area(), "\n"; print " perimeter = ", $o->perimeter(), "\n"; - } +} # ----- Delete everything ----- diff --git a/Examples/perl5/constants/Makefile b/Examples/perl5/constants/Makefile index 899282913..b7b411534 100644 --- a/Examples/perl5/constants/Makefile +++ b/Examples/perl5/constants/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/constants2/Makefile b/Examples/perl5/constants2/Makefile index 2ed10d733..85dd13741 100644 --- a/Examples/perl5/constants2/Makefile +++ b/Examples/perl5/constants2/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i SWIGOPT = -const check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/extend/Makefile b/Examples/perl5/extend/Makefile new file mode 100644 index 000000000..0d1cc574f --- /dev/null +++ b/Examples/perl5/extend/Makefile @@ -0,0 +1,20 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +CXXSRCS = example.cxx +TARGET = example +INTERFACE = example.i +LIBS = -lm + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/extend/example.cxx b/Examples/perl5/extend/example.cxx new file mode 100644 index 000000000..450d75608 --- /dev/null +++ b/Examples/perl5/extend/example.cxx @@ -0,0 +1,4 @@ +/* File : example.cxx */ + +#include "example.h" + diff --git a/Examples/perl5/extend/example.h b/Examples/perl5/extend/example.h new file mode 100644 index 000000000..ca1aed28f --- /dev/null +++ b/Examples/perl5/extend/example.h @@ -0,0 +1,56 @@ +/* File : example.h */ + +#include- Overloaded methods and functions. SWIG wrappers don't know how to resolve name -conflicts so you must give an alternative name to any overloaded method name using the -%name directive like this: - -
-- --void foo(int a); -%name(foo2) void foo(double a, double b); ---
- Overloaded operators. Not supported at all. The only workaround for this is -to write a helper function. For example: - -
-- --%inline %{ - Vector *vector_add(Vector *a, Vector *b) { - ... whatever ... - } -%} ---
- Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all). +
- C++ Namespaces - %nspace isn't yet supported for Perl.
+#include +#include +#include +#include + +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() { printf("~Employee() @ %p\n", (void *)this); } +}; + + +class Manager: public Employee { +public: + Manager(const char* n): Employee(n) {} + virtual std::string getPosition() const { return "Manager"; } +}; + + +class EmployeeList { + std::vector 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); + std::cout << "New employee added. Current employees are:" << std::endl; + std::vector ::iterator i; + for (i=list.begin(); i!=list.end(); i++) { + std::cout << " " << (*i)->getTitle() << std::endl; + } + } + const Employee *get_item(int i) { + return list[i]; + } + ~EmployeeList() { + std::vector ::iterator i; + std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl; + for (i=list.begin(); i!=list.end(); i++) { + delete *i; + } + std::cout << "~EmployeeList empty." << std::endl; + } +}; + diff --git a/Examples/perl5/extend/example.i b/Examples/perl5/extend/example.i new file mode 100644 index 000000000..f5e142b88 --- /dev/null +++ b/Examples/perl5/extend/example.i @@ -0,0 +1,20 @@ +/* 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; + +/* EmployeeList::addEmployee(Employee *p) gives ownership of the + * employee to the EmployeeList object. The wrapper code should + * understand this. */ +%apply SWIGTYPE *DISOWN { Employee *p }; + +%include "example.h" + diff --git a/Examples/perl5/extend/index.html b/Examples/perl5/extend/index.html new file mode 100644 index 000000000..e9d886bcf --- /dev/null +++ b/Examples/perl5/extend/index.html @@ -0,0 +1,19 @@ + + + SWIG:Examples:perl5:extend + + + + + +SWIG/Examples/perl5/extend/ +
+ +Extending a simple C++ class
+ ++This example illustrates the extending of a C++ class with cross language polymorphism. + +
+ + diff --git a/Examples/perl5/extend/runme.pl b/Examples/perl5/extend/runme.pl new file mode 100644 index 000000000..76ee849a4 --- /dev/null +++ b/Examples/perl5/extend/runme.pl @@ -0,0 +1,79 @@ +# file: runme.pl + +# This file illustrates the cross language polymorphism using directors. + +use example; + + +# CEO class, which overrides Employee::getPosition(). + +{ + package CEO; + use base 'example::Manager'; + sub getPosition { + return "CEO"; + } +} + + +# Create an instance of our employee extension class, CEO. The calls to +# getName() and getPosition() are standard, the call to getTitle() uses +# the director wrappers to call CEO->getPosition. $e = CEO->new("Alice") + +$e = CEO->new("Alice"); +print $e->getName(), " is a ", $e->getPosition(), "\n"; +printf "Just call her \"%s\"\n", $e->getTitle(); +print "----------------------\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. + +$list = example::EmployeeList->new(); + +# EmployeeList owns its items, so we must surrender ownership of objects +# we add. This involves calling the DISOWN method to tell the +# C++ director to start reference counting. + +$e->DISOWN(); +$list->addEmployee($e); +print "----------------------\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, both all methods resolve in C++. For item 3, our CEO, getTitle calls +# getPosition which resolves in Perl. The call to getPosition is +# slightly different, however, from the $e->getPosition() call above, since +# now the object reference has been "laundered" by passing through +# EmployeeList as an Employee*. Previously, Perl resolved the call +# immediately in CEO, but now Perl thinks the object is an instance of +# class Employee (actually EmployeePtr). So the call passes through the +# Employee proxy class and on to the C wrappers and C++ director, +# eventually ending up back at the 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 Perl implementation +# in CEO. All this routing takes place transparently. + +print "(position, title) for items 0-3:\n"; + +printf " %s, \"%s\"\n", $list->get_item(0)->getPosition(), $list->get_item(0)->getTitle(); +printf " %s, \"%s\"\n", $list->get_item(1)->getPosition(), $list->get_item(1)->getTitle(); +printf " %s, \"%s\"\n", $list->get_item(2)->getPosition(), $list->get_item(2)->getTitle(); +printf " %s, \"%s\"\n", $list->get_item(3)->getPosition(), $list->get_item(3)->getTitle(); +print "----------------------\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 its +# reference count goes to zero. The Perl destructor runs, and is still +# able to call self.getName() since the underlying C++ object still +# exists. After this destructor runs the remaining C++ destructors run as +# usual to destroy the object. + +undef $list; +print "----------------------\n"; + +# All done. + +print "perl exit\n"; diff --git a/Examples/perl5/funcptr/Makefile b/Examples/perl5/funcptr/Makefile index c4d100020..3e1de1fc1 100644 --- a/Examples/perl5/funcptr/Makefile +++ b/Examples/perl5/funcptr/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/import/Makefile b/Examples/perl5/import/Makefile index baa8277fd..b31ab7952 100644 --- a/Examples/perl5/import/Makefile +++ b/Examples/perl5/import/Makefile @@ -4,17 +4,17 @@ SWIGOPT = LIBS = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='baseclass' INTERFACE='base.i' perl5_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' perl5_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' perl5_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' perl5_cpp clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/index.html b/Examples/perl5/index.html index db46023c4..23c8ff658 100644 --- a/Examples/perl5/index.html +++ b/Examples/perl5/index.html @@ -20,6 +20,8 @@ certain C declarations are turned into constants.- reference. C++ references.
- pointer. Simple pointer handling.
- funcptr. Pointers to functions. +
- callback. C++ callbacks using directors. +
- extend. Extending a simple C++ class.
Compilation Issues
diff --git a/Examples/perl5/inline/Makefile b/Examples/perl5/inline/Makefile index d544a6532..5c98748c1 100644 --- a/Examples/perl5/inline/Makefile +++ b/Examples/perl5/inline/Makefile @@ -1,6 +1,6 @@ run: - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean rm -rf _Inline diff --git a/Examples/perl5/java/Makefile b/Examples/perl5/java/Makefile index b007cfdbb..5eaea3212 100644 --- a/Examples/perl5/java/Makefile +++ b/Examples/perl5/java/Makefile @@ -1,22 +1,22 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run -build: Example.class - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CXX="gcj" \ +build: Example.class Example.h + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ CXXSHARED="gcj -fpic -shared Example.class" PERL5_CCFLAGS='' PERL5_EXP='' LIBS="-lstdc++" perl5_cpp clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean - rm -f *.class Example.h + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean + rm -f *.class Example.h -Example.class: Example.java - gcj -fPIC -C -c -g Example.java - gcjh Example +Example.class Example.h: $(SRCDIR)Example.java + gcj -d . -fPIC -C -c -g $(SRCDIR)Example.java + gcjh Example.class diff --git a/Examples/perl5/multimap/Makefile b/Examples/perl5/multimap/Makefile index c4d100020..3e1de1fc1 100644 --- a/Examples/perl5/multimap/Makefile +++ b/Examples/perl5/multimap/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/multiple_inheritance/Makefile b/Examples/perl5/multiple_inheritance/Makefile index 18c3058f9..1fe5a51bb 100644 --- a/Examples/perl5/multiple_inheritance/Makefile +++ b/Examples/perl5/multiple_inheritance/Makefile @@ -1,20 +1,20 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i -LIBS = +LIBS = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/pointer/Makefile b/Examples/perl5/pointer/Makefile index c4d100020..3e1de1fc1 100644 --- a/Examples/perl5/pointer/Makefile +++ b/Examples/perl5/pointer/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/reference/Makefile b/Examples/perl5/reference/Makefile index d33dd89fe..a22f5a68d 100644 --- a/Examples/perl5/reference/Makefile +++ b/Examples/perl5/reference/Makefile @@ -4,18 +4,18 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = -noproxy +SWIGOPT = -noproxy check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' SWIGOPT='$(SWIGOPT)' perl5_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' SWIGOPT='$(SWIGOPT)' perl5_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/reference/example.cxx b/Examples/perl5/reference/example.cxx index 8a513bf49..9dbaed2ee 100644 --- a/Examples/perl5/reference/example.cxx +++ b/Examples/perl5/reference/example.cxx @@ -19,7 +19,7 @@ Vector operator+(const Vector &a, const Vector &b) { char *Vector::print() { static char temp[512]; - sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z); + sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z); return temp; } diff --git a/Examples/perl5/simple/Makefile b/Examples/perl5/simple/Makefile index c4d100020..3e1de1fc1 100644 --- a/Examples/perl5/simple/Makefile +++ b/Examples/perl5/simple/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/value/Makefile b/Examples/perl5/value/Makefile index c4d100020..3e1de1fc1 100644 --- a/Examples/perl5/value/Makefile +++ b/Examples/perl5/value/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/value/example.i b/Examples/perl5/value/example.i index 98fd60ed5..39663c6b8 100644 --- a/Examples/perl5/value/example.i +++ b/Examples/perl5/value/example.i @@ -26,7 +26,7 @@ Vector *new_Vector(double x, double y, double z) { } void vector_print(Vector *v) { - printf("Vector %p = (%g, %g, %g)\n", v, v->x, v->y, v->z); + printf("Vector %p = (%g, %g, %g)\n", (void *)v, v->x, v->y, v->z); } %} diff --git a/Examples/perl5/variables/Makefile b/Examples/perl5/variables/Makefile index c4d100020..3e1de1fc1 100644 --- a/Examples/perl5/variables/Makefile +++ b/Examples/perl5/variables/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/variables/example.c b/Examples/perl5/variables/example.c index aa4ffe9b3..85685fe72 100644 --- a/Examples/perl5/variables/example.c +++ b/Examples/perl5/variables/example.c @@ -51,10 +51,10 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); - printf("iptrvar = %p\n", iptrvar); + printf("cstrvar = %s\n", cstrvar); + printf("iptrvar = %p\n", (void *)iptrvar); printf("name = %s\n", name); - printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); + printf("ptptr = %p (%d, %d)\n", (void *)ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); printf("pt = (%d, %d)\n", pt.x, pt.y); printf("status = %d\n", status); } diff --git a/Examples/perl5/xmlstring/Makefile b/Examples/perl5/xmlstring/Makefile index df9dabd11..4f02d3ee4 100644 --- a/Examples/perl5/xmlstring/Makefile +++ b/Examples/perl5/xmlstring/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lxerces-c -lxerces-depdom -lm check: build - $(MAKE) -f $(TOP)/Makefile perl5_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' LIBS=$(LIBS) CXX="g++ -g3" perl5_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile perl5_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' perl5_clean diff --git a/Examples/perl5/xmlstring/xmlstring.i b/Examples/perl5/xmlstring/xmlstring.i index 3ef53169d..861e1b84d 100644 --- a/Examples/perl5/xmlstring/xmlstring.i +++ b/Examples/perl5/xmlstring/xmlstring.i @@ -93,6 +93,17 @@ SWIG_FromXMLChPtrAndSize(const XMLCh* input, size_t size) } } +%fragment("SWIG_XMLStringNLen","header") { +size_t +SWIG_XMLStringNLen(const XMLCh* s, size_t maxlen) +{ + const XMLCh *p; + for (p = s; maxlen-- && *p; p++) + ; + return p - s; +} +} + %init { if (!SWIG_UTF8Transcoder()) { croak("ERROR: XML::Xerces: INIT: Could not create UTF-8 transcoder"); @@ -106,6 +117,7 @@ SWIG_FromXMLChPtrAndSize(const XMLCh* input, size_t size) SWIG_AsXMLChPtrAndSize, SWIG_FromXMLChPtrAndSize, XERCES_CPP_NAMESPACE::XMLString::stringLen, + SWIG_XMLStringNLen, "", INT_MIN, INT_MAX); diff --git a/Examples/php/callback/Makefile b/Examples/php/callback/Makefile index 08b2710b2..3ad3999a5 100644 --- a/Examples/php/callback/Makefile +++ b/Examples/php/callback/Makefile @@ -4,18 +4,18 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php_cpp static: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/class/Makefile b/Examples/php/class/Makefile index cefd81f78..8b2b340e9 100644 --- a/Examples/php/class/Makefile +++ b/Examples/php/class/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/class/example.cxx b/Examples/php/class/example.cxx index f171f10e9..046304519 100644 --- a/Examples/php/class/example.cxx +++ b/Examples/php/class/example.cxx @@ -1,14 +1,7 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" -#include -#ifndef M_PI -# define M_PI 3.14159265358979323846 -#endif - -int Shape::get_nshapes() { - return nshapes; -} +#define M_PI 3.14159265358979323846 /* Move the shape to a new location */ void Shape::move(double dx, double dy) { @@ -18,22 +11,18 @@ void Shape::move(double dx, double dy) { int Shape::nshapes = 0; -void Circle::set_radius( double r ) { - radius = r; -} - -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; } diff --git a/Examples/php/class/example.h b/Examples/php/class/example.h index 02eaf7232..0dff185b2 100644 --- a/Examples/php/class/example.h +++ b/Examples/php/class/example.h @@ -10,10 +10,9 @@ public: } 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; - static int get_nshapes(); }; class Circle : public Shape { @@ -21,10 +20,8 @@ private: double radius; public: Circle(double r) : radius(r) { } - ~Circle() { } - void set_radius( double r ); - virtual double area(void); - virtual double perimeter(void); + virtual double area(); + virtual double perimeter(); }; class Square : public Shape { @@ -32,7 +29,6 @@ private: double width; public: Square(double w) : width(w) { } - ~Square() { } - virtual double area(void); - virtual double perimeter(void); + virtual double area(); + virtual double perimeter(); }; diff --git a/Examples/php/class/example.i b/Examples/php/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/php/class/example.i +++ b/Examples/php/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/php/class/runme.php b/Examples/php/class/runme.php index 12b686052..99c253b46 100644 --- a/Examples/php/class/runme.php +++ b/Examples/php/class/runme.php @@ -14,7 +14,7 @@ print " Created square\n"; # ----- Access a static member ----- -print "\nA total of " . Shape::get_nshapes() . " shapes were created\n"; +print "\nA total of " . Shape::nshapes() . " shapes were created\n"; # ----- Member data access ----- @@ -54,7 +54,7 @@ $s = NULL; # the square. $o = NULL; -print Shape::get_nshapes() . " shapes remain\n"; +print Shape::nshapes() . " shapes remain\n"; print "Goodbye\n"; ?> diff --git a/Examples/php/constants/Makefile b/Examples/php/constants/Makefile index 3f24a3921..e5b49571e 100644 --- a/Examples/php/constants/Makefile +++ b/Examples/php/constants/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/cpointer/Makefile b/Examples/php/cpointer/Makefile index 57785acc7..f2c15c5c1 100644 --- a/Examples/php/cpointer/Makefile +++ b/Examples/php/cpointer/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/cpointer/example.c b/Examples/php/cpointer/example.c index 3326dec3e..04dd08df0 100644 --- a/Examples/php/cpointer/example.c +++ b/Examples/php/cpointer/example.c @@ -1,6 +1,6 @@ /* File : example.c */ -void add(double *x, double *y, double *result) { +void add(int *x, int *y, int *result) { *result = *x + *y; } diff --git a/Examples/php/disown/Makefile b/Examples/php/disown/Makefile index cefd81f78..8b2b340e9 100644 --- a/Examples/php/disown/Makefile +++ b/Examples/php/disown/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/enum/Makefile b/Examples/php/enum/Makefile index 22f979d2f..2028d03c7 100644 --- a/Examples/php/enum/Makefile +++ b/Examples/php/enum/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = -noproxy check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/extend/Makefile b/Examples/php/extend/Makefile index 08b2710b2..3ad3999a5 100644 --- a/Examples/php/extend/Makefile +++ b/Examples/php/extend/Makefile @@ -4,18 +4,18 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php_cpp static: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/extend/example.h b/Examples/php/extend/example.h index b27ab9711..ca1aed28f 100644 --- a/Examples/php/extend/example.h +++ b/Examples/php/extend/example.h @@ -14,7 +14,7 @@ public: virtual std::string getTitle() { return getPosition() + " " + getName(); } virtual std::string getName() { return name; } virtual std::string getPosition() const { return "Employee"; } - virtual ~Employee() { printf("~Employee() @ %p\n", this); } + virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); } }; diff --git a/Examples/php/funcptr/Makefile b/Examples/php/funcptr/Makefile index 57785acc7..f2c15c5c1 100644 --- a/Examples/php/funcptr/Makefile +++ b/Examples/php/funcptr/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/overloading/Makefile b/Examples/php/overloading/Makefile index cefd81f78..8b2b340e9 100644 --- a/Examples/php/overloading/Makefile +++ b/Examples/php/overloading/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/pointer/Makefile b/Examples/php/pointer/Makefile index 57785acc7..f2c15c5c1 100644 --- a/Examples/php/pointer/Makefile +++ b/Examples/php/pointer/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/pointer/runme.php b/Examples/php/pointer/runme.php index 5e86de6a2..e79b23810 100644 --- a/Examples/php/pointer/runme.php +++ b/Examples/php/pointer/runme.php @@ -15,7 +15,7 @@ print " c = $c\n"; # Call the add() function wuth some pointers - add(&$a,&$b,&$c); + add($a,$b,$c); print " $a + $b = $c\n"; diff --git a/Examples/php/pragmas/Makefile b/Examples/php/pragmas/Makefile index 3f24a3921..e5b49571e 100644 --- a/Examples/php/pragmas/Makefile +++ b/Examples/php/pragmas/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/pragmas/runme.php b/Examples/php/pragmas/runme.php old mode 100755 new mode 100644 diff --git a/Examples/php/proxy/Makefile b/Examples/php/proxy/Makefile index cefd81f78..8b2b340e9 100644 --- a/Examples/php/proxy/Makefile +++ b/Examples/php/proxy/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/reference/Makefile b/Examples/php/reference/Makefile index cefd81f78..8b2b340e9 100644 --- a/Examples/php/reference/Makefile +++ b/Examples/php/reference/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/reference/example.cxx b/Examples/php/reference/example.cxx index 13e47eade..7ead7fbf6 100644 --- a/Examples/php/reference/example.cxx +++ b/Examples/php/reference/example.cxx @@ -19,23 +19,23 @@ Vector operator+(const Vector &a, const Vector &b) { char *Vector::as_string() { static char temp[512]; - sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z); + sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z); return temp; } VectorArray::VectorArray(int size) { items = new Vector[size]; maxsize = size; - printf("VectorArray new: self=%p\n",this); + printf("VectorArray new: self=%p\n", (void *)this); } VectorArray::~VectorArray() { - printf("VectorArray delete: self=%p\n",this); + printf("VectorArray delete: self=%p\n", (void *)this); delete [] items; } Vector &VectorArray::operator[](int index) { - printf("VectorArray: read[%d] self=%p\n",index,this); + printf("VectorArray: read[%d] self=%p\n", index, (void *)this); if ((index < 0) || (index >= maxsize)) { printf("Panic! Array index out of bounds.\n"); exit(1); @@ -44,6 +44,6 @@ Vector &VectorArray::operator[](int index) { } int VectorArray::size() { - printf("VectorArray: size %d self=%p\n",maxsize,this); + printf("VectorArray: size %d self=%p\n", maxsize, (void *)this); return maxsize; } diff --git a/Examples/php/reference/example.i b/Examples/php/reference/example.i index d6122866b..a372439b1 100644 --- a/Examples/php/reference/example.i +++ b/Examples/php/reference/example.i @@ -37,7 +37,7 @@ public: /* This wrapper provides an alternative to the [] operator */ %extend { Vector &get(int index) { - printf("VectorArray extended get: %p %d\n",$self,index); + printf("VectorArray extended get: %p %d\n", (void *)$self, index); return (*$self)[index]; } void set(int index, Vector &a) { diff --git a/Examples/php/simple/Makefile b/Examples/php/simple/Makefile index 57785acc7..f2c15c5c1 100644 --- a/Examples/php/simple/Makefile +++ b/Examples/php/simple/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/simple/runme.php b/Examples/php/simple/runme.php old mode 100755 new mode 100644 diff --git a/Examples/php/sync/Makefile b/Examples/php/sync/Makefile index cefd81f78..8b2b340e9 100644 --- a/Examples/php/sync/Makefile +++ b/Examples/php/sync/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/sync/example.cxx b/Examples/php/sync/example.cxx index 31ed2021b..0942279b2 100644 --- a/Examples/php/sync/example.cxx +++ b/Examples/php/sync/example.cxx @@ -10,4 +10,4 @@ void Sync::printer(void) { printf("The value of global x is %d\n", x); printf("The value of class s is %s\n", s); printf("The value of class x is %d\n", x); -}; +} diff --git a/Examples/php/value/Makefile b/Examples/php/value/Makefile index 449686784..3db7afec5 100644 --- a/Examples/php/value/Makefile +++ b/Examples/php/value/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = -noproxy check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/value/example.i b/Examples/php/value/example.i index 386fa3b84..20a453468 100644 --- a/Examples/php/value/example.i +++ b/Examples/php/value/example.i @@ -11,7 +11,7 @@ %inline %{ void vector_print(Vector *v) { - printf("Vector %p = (%g, %g, %g)\n", v, v->x, v->y, v->z); + printf("Vector %p = (%g, %g, %g)\n", (void *)v, v->x, v->y, v->z); } %} diff --git a/Examples/php/variables/Makefile b/Examples/php/variables/Makefile index 57785acc7..f2c15c5c1 100644 --- a/Examples/php/variables/Makefile +++ b/Examples/php/variables/Makefile @@ -7,17 +7,17 @@ LIBS = SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile php_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \ php static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \ php_static clean: - $(MAKE) -f $(TOP)/Makefile php_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean diff --git a/Examples/php/variables/example.c b/Examples/php/variables/example.c index 3114c7c5f..d4c6d026d 100644 --- a/Examples/php/variables/example.c +++ b/Examples/php/variables/example.c @@ -51,10 +51,10 @@ void print_vars() { printf("dvar = %g\n", dvar); printf("cvar = %c\n", cvar); printf("strvar = %s\n", strvar ? strvar : "(null)"); - printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)"); - printf("iptrvar = %p\n", iptrvar); + printf("cstrvar = %s\n", cstrvar); + printf("iptrvar = %p\n", (void *)iptrvar); printf("name = %c%c%c%c%c\n", name[0],name[1],name[2],name[3],name[4]); - printf("ptptr = %p %s\n", ptptr, Point_print( ptptr ) ); + printf("ptptr = %p %s\n", (void *)ptptr, Point_print( ptptr ) ); printf("pt = (%d, %d)\n", pt.x, pt.y); printf("status = %d\n", status); } diff --git a/Examples/pike/class/Makefile b/Examples/pike/class/Makefile index aadc47151..d8cf4ea7e 100644 --- a/Examples/pike/class/Makefile +++ b/Examples/pike/class/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile pike_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile pike_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean diff --git a/Examples/pike/class/example.cxx b/Examples/pike/class/example.cxx index c7a3194a4..046304519 100644 --- a/Examples/pike/class/example.cxx +++ b/Examples/pike/class/example.cxx @@ -1,46 +1,28 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" - -#include - #define M_PI 3.14159265358979323846 -// Static member initializer -int Shape::nshapes = 0; - -// Constructor -Shape::Shape() { - nshapes++; -} - -// Move the shape to a new location +/* Move the shape to a new location */ void Shape::move(double dx, double dy) { x += dx; y += dy; } -// Destructor -Shape::~Shape() { - nshapes--; -} +int Shape::nshapes = 0; -// Circle area -double Circle::area() const { +double Circle::area() { return M_PI*radius*radius; } -// Circle perimeter -double Circle::perimeter() const { +double Circle::perimeter() { return 2*M_PI*radius; } -// Square area -double Square::area() const { +double Square::area() { return width*width; } -// Square perimeter -double Square::perimeter() const { +double Square::perimeter() { return 4*width; } diff --git a/Examples/pike/class/example.h b/Examples/pike/class/example.h index f74a4fefc..0dff185b2 100644 --- a/Examples/pike/class/example.h +++ b/Examples/pike/class/example.h @@ -2,12 +2,16 @@ class Shape { public: - Shape(); - virtual ~Shape(); - double x, y; + Shape() { + nshapes++; + } + virtual ~Shape() { + nshapes--; + } + double x, y; void move(double dx, double dy); - virtual double area() const = 0; - virtual double perimeter() const = 0; + virtual double area() = 0; + virtual double perimeter() = 0; static int nshapes; }; @@ -15,21 +19,16 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; - virtual double area() const; - virtual double perimeter() const; + 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() const; - virtual double perimeter() const; + Square(double w) : width(w) { } + virtual double area(); + virtual double perimeter(); }; - - - - - diff --git a/Examples/pike/class/example.i b/Examples/pike/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/pike/class/example.i +++ b/Examples/pike/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/pike/class/runme.pike b/Examples/pike/class/runme.pike old mode 100755 new mode 100644 diff --git a/Examples/pike/constants/Makefile b/Examples/pike/constants/Makefile index 9a882bd4d..736d30f03 100644 --- a/Examples/pike/constants/Makefile +++ b/Examples/pike/constants/Makefile @@ -1,19 +1,19 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile pike_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_static clean: - $(MAKE) -f $(TOP)/Makefile pike_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean diff --git a/Examples/pike/constants/runme.pike b/Examples/pike/constants/runme.pike old mode 100755 new mode 100644 diff --git a/Examples/pike/enum/Makefile b/Examples/pike/enum/Makefile index aadc47151..d8cf4ea7e 100644 --- a/Examples/pike/enum/Makefile +++ b/Examples/pike/enum/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile pike_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile pike_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean diff --git a/Examples/pike/overload/Makefile b/Examples/pike/overload/Makefile index 8d799efe1..f111b1137 100644 --- a/Examples/pike/overload/Makefile +++ b/Examples/pike/overload/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lstdc++ -lm check: build - $(MAKE) -f $(TOP)/Makefile pike_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile pike_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean diff --git a/Examples/pike/simple/Makefile b/Examples/pike/simple/Makefile index f58ed4e65..d7f6b209e 100644 --- a/Examples/pike/simple/Makefile +++ b/Examples/pike/simple/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile pike_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypike' INTERFACE='$(INTERFACE)' pike_static clean: - $(MAKE) -f $(TOP)/Makefile pike_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean diff --git a/Examples/pike/template/Makefile b/Examples/pike/template/Makefile index 73a31ee1a..da115c1d5 100644 --- a/Examples/pike/template/Makefile +++ b/Examples/pike/template/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile pike_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile pike_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' pike_clean diff --git a/Examples/pike/template/runme.pike b/Examples/pike/template/runme.pike old mode 100755 new mode 100644 diff --git a/Examples/python/callback/Makefile b/Examples/python/callback/Makefile index 21e88adc5..a4c4d2a69 100644 --- a/Examples/python/callback/Makefile +++ b/Examples/python/callback/Makefile @@ -4,18 +4,18 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/callback/runme.py b/Examples/python/callback/runme.py index 026e9520b..ddb668407 100644 --- a/Examples/python/callback/runme.py +++ b/Examples/python/callback/runme.py @@ -42,7 +42,7 @@ print print "Adding and calling another Python callback" print "------------------------------------------" -# Lets do the same but use the weak reference this time. +# Let's do the same but use the weak reference this time. callback = PyCallback().__disown__() caller.setCallback(callback) diff --git a/Examples/python/check.list b/Examples/python/check.list index 7cfe437f0..e9e7c8357 100644 --- a/Examples/python/check.list +++ b/Examples/python/check.list @@ -13,6 +13,7 @@ funcptr2 functor import import_template +import_packages java #libffi multimap diff --git a/Examples/python/class/Makefile b/Examples/python/class/Makefile index e940c1f43..41cded284 100644 --- a/Examples/python/class/Makefile +++ b/Examples/python/class/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/class/example.cxx b/Examples/python/class/example.cxx index 1e8e203dd..046304519 100644 --- a/Examples/python/class/example.cxx +++ b/Examples/python/class/example.cxx @@ -1,4 +1,4 @@ -/* File : example.c */ +/* File : example.cxx */ #include "example.h" #define M_PI 3.14159265358979323846 @@ -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; } diff --git a/Examples/python/class/example.h b/Examples/python/class/example.h index 46d901361..0dff185b2 100644 --- a/Examples/python/class/example.h +++ b/Examples/python/class/example.h @@ -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,21 +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(); }; - - - - - diff --git a/Examples/python/class/example.i b/Examples/python/class/example.i index 75700b305..fbdf7249f 100644 --- a/Examples/python/class/example.i +++ b/Examples/python/class/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Examples/python/class/index.html b/Examples/python/class/index.html index 12c5eded1..2e1baa395 100644 --- a/Examples/python/class/index.html +++ b/Examples/python/class/index.html @@ -12,9 +12,7 @@ Wrapping a simple C++ class
-This example illustrates the most primitive form of C++ class wrapping performed -by SWIG. In this case, C++ classes are simply transformed into a collection of -C-style functions that provide access to class members. +This example illustrates wrapping a simple C++ class to give a Python class.
The C++ Code
@@ -32,8 +30,8 @@ public: } virtual ~Shape() { nshapes--; - }; - double x, y; + } + double x, y; void move(double dx, double dy); virtual double area() = 0; virtual double perimeter() = 0; @@ -44,7 +42,7 @@ class Circle : public Shape { private: double radius; public: - Circle(double r) : radius(r) { }; + Circle(double r) : radius(r) { } virtual double area(); virtual double perimeter(); }; @@ -53,7 +51,7 @@ class Square : public Shape { private: double width; public: - Square(double w) : width(w) { }; + Square(double w) : width(w) { } virtual double area(); virtual double perimeter(); }; @@ -102,51 +100,34 @@ c = example.new_Circle(10.0)-
- To access member data, a pair of accessor functions are used. +
- Member variables of the C++ class are wrapped as attributes of the Python class. For example:
- -Note: when accessing member data, the name of the class in which -the member data was must be used. In this case, Shape_x_get() -and Shape_x_set() are used since 'x' was defined in Shape. - --example.Shape_x_set(c,15) # Set member data -x = example.Shape_x_get(c) # Get member data ---
- To invoke a member function, you simply do this - -
--print "The area is ", example.Shape_area(c) +c.x = 15 # Set member data +x = c.x # Get member data-
- Type checking knows about the inheritance structure of C++. For example: +
- Member function are invoked as you would expect:
-example.Shape_area(c) # Works (c is a Shape) -example.Circle_area(c) # Works (c is a Circle) -example.Square_area(c) # Fails (c is definitely not a Square) +print "The area is ", c.area()-
- To invoke a destructor, simply do this +
- To invoke a destructor, simply call
delon the object:-(Note: destructors are currently not inherited. This might change later). --example.delete_Shape(c) # Deletes a shape +del c # Deletes a shape
- Static member variables are wrapped as C global variables. For example: @@ -162,52 +143,12 @@ example.cvar.Shapes_nshapes = 13 # Set a static data member
General Comments
-
- This low-level interface is not the only way to handle C++ code. -Proxy classes provide a much higher-level interface. - -
-
- SWIG *does* know how to properly perform upcasting of objects in +
- SWIG does know how to properly perform upcasting of objects in an inheritance hierarchy (including multiple inheritance). Therefore it is perfectly safe to pass an object of a derived class to any function involving a base class. -
-
- A wide variety of C++ features are not currently supported by SWIG. Here is the -short and incomplete list: - -
-
-
diff --git a/Examples/python/class/runme.py b/Examples/python/class/runme.py index f1272ae81..8f4f27eb9 100644 --- a/Examples/python/class/runme.py +++ b/Examples/python/class/runme.py @@ -38,6 +38,8 @@ for o in [c,s]: print " ", o print " area = ", o.area() print " perimeter = ", o.perimeter() +# prevent o from holding a reference to the last object looked at +o = None print "\nGuess I'll clean up now" @@ -45,7 +47,5 @@ print "\nGuess I'll clean up now" del c del s -s = 3 print example.cvar.Shape_nshapes,"shapes remain" print "Goodbye" - diff --git a/Examples/python/constants/Makefile b/Examples/python/constants/Makefile index 505f199de..8ec6e9cc9 100644 --- a/Examples/python/constants/Makefile +++ b/Examples/python/constants/Makefile @@ -1,19 +1,19 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -SRCS = +SRCS = TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/contract/Makefile b/Examples/python/contract/Makefile index a44887736..fe1d9325e 100644 --- a/Examples/python/contract/Makefile +++ b/Examples/python/contract/Makefile @@ -3,18 +3,18 @@ SWIG = $(TOP)/../preinst-swig SRCS = example.c TARGET = example INTERFACE = example.i -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/docstrings/Makefile b/Examples/python/docstrings/Makefile index 51552f3cf..f471930dd 100644 --- a/Examples/python/docstrings/Makefile +++ b/Examples/python/docstrings/Makefile @@ -7,17 +7,17 @@ LIBS = -lm SWIGOPT = -O check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/enum/Makefile b/Examples/python/enum/Makefile index e940c1f43..41cded284 100644 --- a/Examples/python/enum/Makefile +++ b/Examples/python/enum/Makefile @@ -6,15 +6,15 @@ INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/exception/Makefile b/Examples/python/exception/Makefile index b2b163e2e..ad3d49fe1 100644 --- a/Examples/python/exception/Makefile +++ b/Examples/python/exception/Makefile @@ -1,20 +1,20 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/exceptproxy/Makefile b/Examples/python/exceptproxy/Makefile index 06bce6543..f406dfaf4 100644 --- a/Examples/python/exceptproxy/Makefile +++ b/Examples/python/exceptproxy/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/extend/Makefile b/Examples/python/extend/Makefile index 21e88adc5..a4c4d2a69 100644 --- a/Examples/python/extend/Makefile +++ b/Examples/python/extend/Makefile @@ -4,18 +4,18 @@ CXXSRCS = example.cxx TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/extend/example.h b/Examples/python/extend/example.h index b27ab9711..ca1aed28f 100644 --- a/Examples/python/extend/example.h +++ b/Examples/python/extend/example.h @@ -14,7 +14,7 @@ public: virtual std::string getTitle() { return getPosition() + " " + getName(); } virtual std::string getName() { return name; } virtual std::string getPosition() const { return "Employee"; } - virtual ~Employee() { printf("~Employee() @ %p\n", this); } + virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); } }; diff --git a/Examples/python/funcptr/Makefile b/Examples/python/funcptr/Makefile index df3bc86ff..222916fa1 100644 --- a/Examples/python/funcptr/Makefile +++ b/Examples/python/funcptr/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/funcptr2/Makefile b/Examples/python/funcptr2/Makefile index df3bc86ff..222916fa1 100644 --- a/Examples/python/funcptr2/Makefile +++ b/Examples/python/funcptr2/Makefile @@ -5,15 +5,15 @@ TARGET = example INTERFACE = example.i check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python static: - $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/functor/Makefile b/Examples/python/functor/Makefile index 6ef158379..1234c310e 100644 --- a/Examples/python/functor/Makefile +++ b/Examples/python/functor/Makefile @@ -1,21 +1,21 @@ TOP = ../.. SWIG = $(TOP)/../preinst-swig -CXXSRCS = +CXXSRCS = TARGET = example INTERFACE = example.i LIBS = -lm -SWIGOPT = +SWIGOPT = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp static: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean diff --git a/Examples/python/import/Makefile b/Examples/python/import/Makefile index f63e12271..d83dfeaa8 100644 --- a/Examples/python/import/Makefile +++ b/Examples/python/import/Makefile @@ -4,19 +4,19 @@ SWIGOPT = LIBS = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' python_cpp clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean rm -f foo.py bar.py spam.py base.py diff --git a/Examples/python/import_packages/Makefile b/Examples/python/import_packages/Makefile new file mode 100644 index 000000000..d5054fd22 --- /dev/null +++ b/Examples/python/import_packages/Makefile @@ -0,0 +1,45 @@ +TOP = ../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +import_packages_subdirs = \ + same_modnames1 \ + same_modnames2 \ + from_init1 \ + from_init2 \ + from_init3 \ + relativeimport1 \ + relativeimport1 + +check: build + if test "x$(SRCDIR)" != x; then \ + for file in `cd $(SRCDIR) && find . -type f -name __init__.py`; do \ + cp "${SRCDIR}$$file" "$$file" || exit 1; \ + done; \ + fi; \ + for s in $(import_packages_subdirs); do \ + (cd $$s && $(MAKE) check); \ + done + +build: + for s in $(import_packages_subdirs); do \ + (cd $$s && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build); \ + done + +static: + for s in $(import_packages_subdirs); do \ + (cd $$s && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static); \ + done + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + if test "x$(SRCDIR)" != x; then \ + for file in `cd $(SRCDIR) && find . -type f -name __init__.py`; do \ + rm -f "$$file" || exit 1; \ + done; \ + fi; \ + for s in $(import_packages_subdirs); do \ + (cd $$s && $(MAKE) clean); \ + done diff --git a/Examples/python/import_packages/README b/Examples/python/import_packages/README new file mode 100644 index 000000000..69fe3516e --- /dev/null +++ b/Examples/python/import_packages/README @@ -0,0 +1,2 @@ +These are actually regression tests for SF bug #1297 (GH issue #7). +See individual READMEs in subdirectories. diff --git a/Examples/python/import_packages/from_init1/Makefile b/Examples/python/import_packages/from_init1/Makefile new file mode 100644 index 000000000..b9d803a0e --- /dev/null +++ b/Examples/python/import_packages/from_init1/Makefile @@ -0,0 +1,25 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +ifeq (,$(PY3)) + PKG1DIR = "py2" +else + PKG1DIR = "py3" +endif + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run + +build: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + +static: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd py2 && $(MAKE) clean + cd py3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init1/README b/Examples/python/import_packages/from_init1/README new file mode 100644 index 000000000..e7d7eca9e --- /dev/null +++ b/Examples/python/import_packages/from_init1/README @@ -0,0 +1,63 @@ +This example tests the %import directive and python import from __init__.py. + +This case is not correctly handled by swig 2. + +The issue was reported as Source Forge bug #1297 and later as GitHub issue #7. + +Use 'python runme.py' to run a test. + + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pyX/pkg2/foo.i - Pkg2_Foo class + pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg2_Foo + +and the package pyX.pkg2 has: + + pyX/pkg2/__init__.py - which imports something from "bar" module (we + import Pkg2_Bar class, but it is not the clue, + the clue is the 'from' keyword) + +For example with python2.x the py2/pkg2/__init__.py imports Pkg2_Bar class +as follows + + from bar import Pkg2_Bar # [1] + +Such cases doesn't work when fully qualified python module names are used by +swig (swig 2.0.10, e.g.) to generate python import directives (SF bug #1297). +The generated file "py2/pkg2/bar.py" has following lines: + + import py2.pkg2.foo # [2] + class Pkg2_Bar(py2.pkg2.foo.Pkg2_Foo): # [3] + +but it's not possible to import anything from py2.pkg2 subpackage, e.g. + + import py2.pkg2 + +fails with the following exception: + +Traceback (most recent call last): + File "runme.py", line 3, in- Overloaded methods and functions. SWIG wrappers don't know how to resolve name -conflicts so you must give an alternative name to any overloaded method name using the -%name directive like this: - -
-- --void foo(int a); -%name(foo2) void foo(double a, double b); ---
- Overloaded operators. Not supported at all. The only workaround for this is -to write a helper function. For example: - -
-- --%inline %{ - Vector *vector_add(Vector *a, Vector *b) { - ... whatever ... - } -%} ---
- Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all). - -
-
- Dave's snide remark: Like a large bottle of strong Tequilla, it's better to -use C++ in moderation. +
- C++ Namespaces - %nspace isn't yet supported for Python.
+ import py2.pkg2 + File "py2/pkg2/__init__.py", line 7, in + from .bar import Pkg2_Bar + File "py2/pkg2/bar.py", line 71, in + class Pkg2_Bar(py2.pkg2.foo.Pkg2_Foo): + AttributeError: 'module' object has no attribute 'pkg2' + + +It seems like during the import [1], the sub-package pkg2 is not yet fully +initialized, so py2.pkg2 is not known. The above exception is raised at +line [3]. The problem disappears, for example, if we force swig to use relative +package names. + +If everything works well, the package py2.pkg2 shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/from_init1/py2/Makefile b/Examples/python/import_packages/from_init1/py2/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init1/py2/__init__.py b/Examples/python/import_packages/from_init1/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/Makefile b/Examples/python/import_packages/from_init1/py2/pkg2/Makefile new file mode 100644 index 000000000..1eb810e05 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/Makefile @@ -0,0 +1,20 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp_static + +clean:: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/__init__.py b/Examples/python/import_packages/from_init1/py2/pkg2/__init__.py new file mode 100644 index 000000000..0f9c90203 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/__init__.py @@ -0,0 +1 @@ +from bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/bar.hpp b/Examples/python/import_packages/from_init1/py2/pkg2/bar.hpp new file mode 100644 index 000000000..b369161d3 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY2_PKG2_BAR_HPP +#define PY2_PKG2_BAR_HPP +#include "../../py2/pkg2/foo.hpp" +struct Pkg2_Bar : Pkg2_Foo {}; +#endif /* PY2_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/bar.i b/Examples/python/import_packages/from_init1/py2/pkg2/bar.i new file mode 100644 index 000000000..0795a7751 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import "../../py2/pkg2/foo.i" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/foo.hpp b/Examples/python/import_packages/from_init1/py2/pkg2/foo.hpp new file mode 100644 index 000000000..fed8239f6 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY2_PKG2_FOO_HPP +#define PY2_PKG2_FOO_HPP +struct Pkg2_Foo {}; +#endif /* PY2_PKG2_FOO_HPP */ diff --git a/Examples/python/import_packages/from_init1/py2/pkg2/foo.i b/Examples/python/import_packages/from_init1/py2/pkg2/foo.i new file mode 100644 index 000000000..37b2e1f82 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py2/pkg2/foo.i @@ -0,0 +1,5 @@ +%module(package="py2.pkg2") foo +%{ +#include "../../py2/pkg2/foo.hpp" +%} +%include "../../py2/pkg2/foo.hpp" diff --git a/Examples/python/import_packages/from_init1/py3/Makefile b/Examples/python/import_packages/from_init1/py3/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init1/py3/__init__.py b/Examples/python/import_packages/from_init1/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/Makefile b/Examples/python/import_packages/from_init1/py3/pkg2/Makefile new file mode 100644 index 000000000..1eb810e05 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/Makefile @@ -0,0 +1,20 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp_static + +clean:: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/__init__.py b/Examples/python/import_packages/from_init1/py3/pkg2/__init__.py new file mode 100644 index 000000000..2097aaf2e --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/__init__.py @@ -0,0 +1 @@ +from .bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/bar.hpp b/Examples/python/import_packages/from_init1/py3/pkg2/bar.hpp new file mode 100644 index 000000000..d16463dff --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY3_PKG2_BAR_HPP +#define PY3_PKG2_BAR_HPP +#include "../../py3/pkg2/foo.hpp" +struct Pkg2_Bar : Pkg2_Foo {}; +#endif /* PY3_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/bar.i b/Examples/python/import_packages/from_init1/py3/pkg2/bar.i new file mode 100644 index 000000000..8d8d627b9 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import "../../py3/pkg2/foo.i" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/foo.hpp b/Examples/python/import_packages/from_init1/py3/pkg2/foo.hpp new file mode 100644 index 000000000..c2469dc86 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY3_PKG2_FOO_HPP +#define PY3_PKG2_FOO_HPP +struct Pkg2_Foo {}; +#endif /* PY3_PKG2_FOO_HPP */ diff --git a/Examples/python/import_packages/from_init1/py3/pkg2/foo.i b/Examples/python/import_packages/from_init1/py3/pkg2/foo.i new file mode 100644 index 000000000..76613b593 --- /dev/null +++ b/Examples/python/import_packages/from_init1/py3/pkg2/foo.i @@ -0,0 +1,5 @@ +%module(package="py3.pkg2") foo +%{ +#include "../../py3/pkg2/foo.hpp" +%} +%include "../../py3/pkg2/foo.hpp" diff --git a/Examples/python/import_packages/from_init1/runme.py b/Examples/python/import_packages/from_init1/runme.py new file mode 100644 index 000000000..c23a085fa --- /dev/null +++ b/Examples/python/import_packages/from_init1/runme.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print "Testing %module(package=...) + python 'import' in __init__.py" +import sys +if sys.version_info < (3,0): + import py2.pkg2 + print " Finished importing py2.pkg2" +else: + import py3.pkg2 + print " Finished importing py3.pkg2" diff --git a/Examples/python/import_packages/from_init2/Makefile b/Examples/python/import_packages/from_init2/Makefile new file mode 100644 index 000000000..b9d803a0e --- /dev/null +++ b/Examples/python/import_packages/from_init2/Makefile @@ -0,0 +1,25 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +ifeq (,$(PY3)) + PKG1DIR = "py2" +else + PKG1DIR = "py3" +endif + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run + +build: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + +static: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd py2 && $(MAKE) clean + cd py3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init2/README b/Examples/python/import_packages/from_init2/README new file mode 100644 index 000000000..a0eb41839 --- /dev/null +++ b/Examples/python/import_packages/from_init2/README @@ -0,0 +1,81 @@ +This example tests the %import directive and python import from __init__.py. + +This case is not correctly handled by swig 2. + +The issue was reported as Source Forge bug #1297 and later as GitHub issue #7. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pyX/pkg2/pkg3/foo.i - Pkg3_Foo class + pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg3_Foo + +and the package pyX.pkg2 has: + + pyX/pkg2/__init__.py - which imports something from "bar" module + +For example with python 2.x the py2/pkg2/__init__.py imports Pkg2_Bar class as +follows + + from bar import Pkg2_Bar # [1] + +Such cases doesn't work when fully qualified python module names are used by +swig to generate python import directives (SF bug #1297). The generated file +"py2/pkg2/bar.py" has following lines: + + import py2.pkg2.pkg3.foo # [2] + class Pkg2_Bar(py2.pkg2.pkg3.foo.Pkg3_Foo): # [3] + +and it's not possible to import anything from py2.pkg2 subpackage, e.g. + + import py2.pkg2 + +fails with the following exception: + +Traceback (most recent call last): + File "runme.py", line 3, in + import py2.pkg2 + File "py2/pkg2/__init__.py", line 4, in + from bar import Pkg2_Bar + File "py2/pkg2/bar.py", line 71, in + class Pkg2_Bar(py2.pkg2.pkg3.foo.Pkg3_Foo): +AttributeError: 'module' object has no attribute 'pkg2' + +It seems like during the import [1], the subpackage pkg2 is not yet fully +initialized, so pyX.pkg2 is not known. The above exception is raised at line [3]. +The problem disappears, for example, if we force swig to use relative package +names. + +The difference between this ('from_init2') case and the case +'from_init1' is that here it's not sufficient to import relative module +by just ignoring the package part of the fully qualified module name. IOW +it is not correct to force swig to put: + + import foo + class Pkg2_Bar(foo.Pkg3_Foo) + +into pyX/pkg2/bar.py (note, that this would work for 'from_init1' case). +The import directive shall be rather: + + import pkg3.foo + +for python 2.x and: + + from . import pkg3 + import pkg3.foo + +for python 3, and the class definition shall begin with: + + class Pkg2_Bar(pkg3.foo.Pkg3_Foo) + +If everything works well, the package pyX.pkg2 shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/from_init2/py2/Makefile b/Examples/python/import_packages/from_init2/py2/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init2/py2/__init__.py b/Examples/python/import_packages/from_init2/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/Makefile b/Examples/python/import_packages/from_init2/py2/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/__init__.py b/Examples/python/import_packages/from_init2/py2/pkg2/__init__.py new file mode 100644 index 000000000..0f9c90203 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/__init__.py @@ -0,0 +1 @@ +from bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/bar.hpp b/Examples/python/import_packages/from_init2/py2/pkg2/bar.hpp new file mode 100644 index 000000000..8f09cd5fa --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY2_PKG2_BAR_HPP +#define PY2_PKG2_BAR_HPP +#include "../../py2/pkg2/pkg3/foo.hpp" +struct Pkg2_Bar : Pkg3_Foo {}; +#endif /* PY2_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/bar.i b/Examples/python/import_packages/from_init2/py2/pkg2/bar.i new file mode 100644 index 000000000..28a4c906e --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import "../../py2/pkg2/pkg3/foo.i" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/Makefile new file mode 100644 index 000000000..cb20bd25f --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/__init__.py b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.hpp b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.hpp new file mode 100644 index 000000000..b6c89a431 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY2_PKG2_PKG3_FOO_HPP +#define PY2_PKG2_PKG3_FOO_HPP +struct Pkg3_Foo {}; +#endif /* PY2_PKG2_PKG3_FOO_HPP */ diff --git a/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.i b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.i new file mode 100644 index 000000000..ba32483d2 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py2/pkg2/pkg3/foo.i @@ -0,0 +1,5 @@ +%module(package="py2.pkg2.pkg3") foo +%{ +#include "../../../py2/pkg2/pkg3/foo.hpp" +%} +%include "../../../py2/pkg2/pkg3/foo.hpp" diff --git a/Examples/python/import_packages/from_init2/py3/Makefile b/Examples/python/import_packages/from_init2/py3/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init2/py3/__init__.py b/Examples/python/import_packages/from_init2/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/Makefile b/Examples/python/import_packages/from_init2/py3/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/__init__.py b/Examples/python/import_packages/from_init2/py3/pkg2/__init__.py new file mode 100644 index 000000000..2097aaf2e --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/__init__.py @@ -0,0 +1 @@ +from .bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/bar.hpp b/Examples/python/import_packages/from_init2/py3/pkg2/bar.hpp new file mode 100644 index 000000000..408d910d7 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY3_PKG2_BAR_HPP +#define PY3_PKG2_BAR_HPP +#include "../../py3/pkg2/pkg3/foo.hpp" +struct Pkg2_Bar : Pkg3_Foo {}; +#endif /* PY3_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/bar.i b/Examples/python/import_packages/from_init2/py3/pkg2/bar.i new file mode 100644 index 000000000..1468932ff --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import "../../py3/pkg2/pkg3/foo.i" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/Makefile new file mode 100644 index 000000000..cb20bd25f --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/__init__.py b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.hpp b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.hpp new file mode 100644 index 000000000..531721d36 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY3_PKG2_PKG3_FOO_HPP +#define PY3_PKG2_PKG3_FOO_HPP +struct Pkg3_Foo {}; +#endif /* PY3_PKG2_PKG3_FOO_HPP */ diff --git a/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.i b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.i new file mode 100644 index 000000000..c6ba529b7 --- /dev/null +++ b/Examples/python/import_packages/from_init2/py3/pkg2/pkg3/foo.i @@ -0,0 +1,5 @@ +%module(package="py3.pkg2.pkg3") foo +%{ +#include "../../../py3/pkg2/pkg3/foo.hpp" +%} +%include "../../../py3/pkg2/pkg3/foo.hpp" diff --git a/Examples/python/import_packages/from_init2/runme.py b/Examples/python/import_packages/from_init2/runme.py new file mode 100644 index 000000000..c23a085fa --- /dev/null +++ b/Examples/python/import_packages/from_init2/runme.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print "Testing %module(package=...) + python 'import' in __init__.py" +import sys +if sys.version_info < (3,0): + import py2.pkg2 + print " Finished importing py2.pkg2" +else: + import py3.pkg2 + print " Finished importing py3.pkg2" diff --git a/Examples/python/import_packages/from_init3/Makefile b/Examples/python/import_packages/from_init3/Makefile new file mode 100644 index 000000000..b9d803a0e --- /dev/null +++ b/Examples/python/import_packages/from_init3/Makefile @@ -0,0 +1,25 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +ifeq (,$(PY3)) + PKG1DIR = "py2" +else + PKG1DIR = "py3" +endif + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run + +build: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + +static: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd py2 && $(MAKE) clean + cd py3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/README b/Examples/python/import_packages/from_init3/README new file mode 100644 index 000000000..131d5894c --- /dev/null +++ b/Examples/python/import_packages/from_init3/README @@ -0,0 +1,67 @@ +This example tests the %import directive and python import from __init__.py. + +This case is not correctly handled by swig 2. + +The issue was reported as Source Forge bug #1297 and later as GitHub issue #7. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pyX/pkg2/pkg3/pkg4/foo.i - Pkg4_Foo class + pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg4_Foo + +and the package pyX.pkg2 has: + + pyX/pkg2/__init__.py - which imports something from "bar" module + +For example with python 2.x the py2/pkg2/__init__.py imports Pkg2_Bar class as +follows + + from bar import Pkg2_Bar # [1] + +Such cases doesn't work when fully qualified python module names are used by +swig to generate python import directives (SF bug 1297). The generated file +"py2/pkg2/bar.py" has following lines: + + import py2.pkg2.pkg3.pkg4.foo # [2] + class Pkg2_Bar(py2.pkg2.pkg3.pkg4.foo.P1_S1_S2_Foo): # [3] + +and it's not possible to import anything from py2.pkg2 subpackage, e.g. + + import py2.pkg2 + +fails with the following exception: + + Traceback (most recent call last): + File "runme.py", line 3, in + import py2.pkg2 + File "py2/pkg2/__init__.py", line 4, in + from bar import Pkg2_Bar + File "py2/pkg2/bar.py", line 71, in + class Pkg2_Bar(py2.pkg2.pkg3.pkg4.foo.Pkg4_Foo): + AttributeError: 'module' object has no attribute 'pkg2' + +It seems like during the import [1], the subpackage pkg2 is not yet fully +initialized, so py2.pkg2 can't be used. The above exception is raised at +line [3]. The problem disappears, for example, if we force swig to use relative +package names. + +The difference between this ('from_init3') case and the case +'from_init2' is that here we import base class from module +pyX.pkg2.pkg3.pkg4.foo, which is nested deeper than it was in +'from_init2'. This is just to ensure, that two (and more) levels of +subpackages get imported correctly by generated python code, i.e, not only +'pkg3.foo' is handled properly (one-level subpackage) but the code works also +for 'pkg3.pkg4.foo', and so on. + +If everything works well, the package pyX.pkg2 shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/from_init3/py2/Makefile b/Examples/python/import_packages/from_init3/py2/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py2/__init__.py b/Examples/python/import_packages/from_init3/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/Makefile b/Examples/python/import_packages/from_init3/py2/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/__init__.py b/Examples/python/import_packages/from_init3/py2/pkg2/__init__.py new file mode 100644 index 000000000..0f9c90203 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/__init__.py @@ -0,0 +1 @@ +from bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/bar.hpp b/Examples/python/import_packages/from_init3/py2/pkg2/bar.hpp new file mode 100644 index 000000000..20a00190a --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY2_PKG2_HPP +#define PY2_PKG2_HPP +#include "../../py2/pkg2/pkg3/pkg4/foo.hpp" +struct Pkg2_Bar : Pkg4_Foo {}; +#endif /* PY2_PKG2_HPP */ diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/bar.i b/Examples/python/import_packages/from_init3/py2/pkg2/bar.i new file mode 100644 index 000000000..0a932a2b9 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import "../../py2/pkg2/pkg3/pkg4/foo.i" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/Makefile new file mode 100644 index 000000000..d6ae1b2bc --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg4 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/__init__.py b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/Makefile b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/Makefile new file mode 100644 index 000000000..286d90070 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/__init__.py b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.hpp b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.hpp new file mode 100644 index 000000000..2df933c59 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY2_PKG2_PKG3_PKG4 +#define PY2_PKG2_PKG3_PKG4 +struct Pkg4_Foo {}; +#endif /* PY2_PKG2_PKG3_PKG4 */ diff --git a/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.i b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.i new file mode 100644 index 000000000..311d7161c --- /dev/null +++ b/Examples/python/import_packages/from_init3/py2/pkg2/pkg3/pkg4/foo.i @@ -0,0 +1,5 @@ +%module(package="py2.pkg2.pkg3.pkg4") foo +%{ +#include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp" +%} +%include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp" diff --git a/Examples/python/import_packages/from_init3/py3/Makefile b/Examples/python/import_packages/from_init3/py3/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py3/__init__.py b/Examples/python/import_packages/from_init3/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/Makefile b/Examples/python/import_packages/from_init3/py3/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/__init__.py b/Examples/python/import_packages/from_init3/py3/pkg2/__init__.py new file mode 100644 index 000000000..2097aaf2e --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/__init__.py @@ -0,0 +1 @@ +from .bar import Pkg2_Bar diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/bar.hpp b/Examples/python/import_packages/from_init3/py3/pkg2/bar.hpp new file mode 100644 index 000000000..16fdd362e --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY3_PKG2_HPP +#define PY3_PKG2_HPP +#include "../../py3/pkg2/pkg3/pkg4/foo.hpp" +struct Pkg2_Bar : Pkg4_Foo {}; +#endif /* PY3_PKG2_HPP */ diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/bar.i b/Examples/python/import_packages/from_init3/py3/pkg2/bar.i new file mode 100644 index 000000000..3abbb05d3 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import "../../py3/pkg2/pkg3/pkg4/foo.i" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/Makefile new file mode 100644 index 000000000..d6ae1b2bc --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg4 && $(MAKE) clean diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/__init__.py b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/Makefile b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/Makefile new file mode 100644 index 000000000..286d90070 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/__init__.py b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.hpp b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.hpp new file mode 100644 index 000000000..e24654c28 --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY3_PKG2_PKG3_PKG4 +#define PY3_PKG2_PKG3_PKG4 +struct Pkg4_Foo {}; +#endif /* PY3_PKG2_PKG3_PKG4 */ diff --git a/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.i b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.i new file mode 100644 index 000000000..36c5f01ea --- /dev/null +++ b/Examples/python/import_packages/from_init3/py3/pkg2/pkg3/pkg4/foo.i @@ -0,0 +1,5 @@ +%module(package="py3.pkg2.pkg3.pkg4") foo +%{ +#include "../../../../py3/pkg2/pkg3/pkg4/foo.hpp" +%} +%include "../../../../py3/pkg2/pkg3/pkg4/foo.hpp" diff --git a/Examples/python/import_packages/from_init3/runme.py b/Examples/python/import_packages/from_init3/runme.py new file mode 100644 index 000000000..c23a085fa --- /dev/null +++ b/Examples/python/import_packages/from_init3/runme.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print "Testing %module(package=...) + python 'import' in __init__.py" +import sys +if sys.version_info < (3,0): + import py2.pkg2 + print " Finished importing py2.pkg2" +else: + import py3.pkg2 + print " Finished importing py3.pkg2" diff --git a/Examples/python/import_packages/relativeimport1/Makefile b/Examples/python/import_packages/relativeimport1/Makefile new file mode 100644 index 000000000..b9d803a0e --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/Makefile @@ -0,0 +1,25 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +ifeq (,$(PY3)) + PKG1DIR = "py2" +else + PKG1DIR = "py3" +endif + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run + +build: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + +static: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd py2 && $(MAKE) clean + cd py3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport1/README b/Examples/python/import_packages/relativeimport1/README new file mode 100644 index 000000000..a99ef2426 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/README @@ -0,0 +1,22 @@ +This example tests the %import directive and -relativeimport swig option. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pyX/pkg2/pkg3/foo.i - Pkg3_Foo class + pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg3_Foo + +The code is processed by swig with -relativeimport flag. The runtime test +imports pyX.pkg2.bar module. + +If everything works well, the module pyX.pkg2.bar shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/relativeimport1/py2/Makefile b/Examples/python/import_packages/relativeimport1/py2/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport1/py2/__init__.py b/Examples/python/import_packages/relativeimport1/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/Makefile b/Examples/python/import_packages/relativeimport1/py2/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/__init__.py b/Examples/python/import_packages/relativeimport1/py2/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.hpp b/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.hpp new file mode 100644 index 000000000..8f09cd5fa --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY2_PKG2_BAR_HPP +#define PY2_PKG2_BAR_HPP +#include "../../py2/pkg2/pkg3/foo.hpp" +struct Pkg2_Bar : Pkg3_Foo {}; +#endif /* PY2_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.i b/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.i new file mode 100644 index 000000000..28a4c906e --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import "../../py2/pkg2/pkg3/foo.i" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/Makefile new file mode 100644 index 000000000..cb20bd25f --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/__init__.py b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.hpp b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.hpp new file mode 100644 index 000000000..b6c89a431 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY2_PKG2_PKG3_FOO_HPP +#define PY2_PKG2_PKG3_FOO_HPP +struct Pkg3_Foo {}; +#endif /* PY2_PKG2_PKG3_FOO_HPP */ diff --git a/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.i b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.i new file mode 100644 index 000000000..ba32483d2 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py2/pkg2/pkg3/foo.i @@ -0,0 +1,5 @@ +%module(package="py2.pkg2.pkg3") foo +%{ +#include "../../../py2/pkg2/pkg3/foo.hpp" +%} +%include "../../../py2/pkg2/pkg3/foo.hpp" diff --git a/Examples/python/import_packages/relativeimport1/py3/Makefile b/Examples/python/import_packages/relativeimport1/py3/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport1/py3/__init__.py b/Examples/python/import_packages/relativeimport1/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/Makefile b/Examples/python/import_packages/relativeimport1/py3/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/__init__.py b/Examples/python/import_packages/relativeimport1/py3/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.hpp b/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.hpp new file mode 100644 index 000000000..408d910d7 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY3_PKG2_BAR_HPP +#define PY3_PKG2_BAR_HPP +#include "../../py3/pkg2/pkg3/foo.hpp" +struct Pkg2_Bar : Pkg3_Foo {}; +#endif /* PY3_PKG2_BAR_HPP */ diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.i b/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.i new file mode 100644 index 000000000..1468932ff --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import "../../py3/pkg2/pkg3/foo.i" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/Makefile new file mode 100644 index 000000000..cb20bd25f --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/__init__.py b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.hpp b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.hpp new file mode 100644 index 000000000..531721d36 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY3_PKG2_PKG3_FOO_HPP +#define PY3_PKG2_PKG3_FOO_HPP +struct Pkg3_Foo {}; +#endif /* PY3_PKG2_PKG3_FOO_HPP */ diff --git a/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.i b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.i new file mode 100644 index 000000000..c6ba529b7 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/py3/pkg2/pkg3/foo.i @@ -0,0 +1,5 @@ +%module(package="py3.pkg2.pkg3") foo +%{ +#include "../../../py3/pkg2/pkg3/foo.hpp" +%} +%include "../../../py3/pkg2/pkg3/foo.hpp" diff --git a/Examples/python/import_packages/relativeimport1/runme.py b/Examples/python/import_packages/relativeimport1/runme.py new file mode 100644 index 000000000..44ce8d1c4 --- /dev/null +++ b/Examples/python/import_packages/relativeimport1/runme.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print "Testing %module(package=...) with -relativeimport" +import sys +if sys.version_info < (3,0): + import py2.pkg2.bar + print " Finished importing py2.pkg2.bar" +else: + import py3.pkg2.bar + print " Finished importing py3.pkg2.bar" diff --git a/Examples/python/import_packages/relativeimport2/Makefile b/Examples/python/import_packages/relativeimport2/Makefile new file mode 100644 index 000000000..b9d803a0e --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/Makefile @@ -0,0 +1,25 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = +PY3 = + +ifeq (,$(PY3)) + PKG1DIR = "py2" +else + PKG1DIR = "py3" +endif + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run + +build: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' build + +static: + cd $(PKG1DIR) && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -relativeimport' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd py2 && $(MAKE) clean + cd py3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/README b/Examples/python/import_packages/relativeimport2/README new file mode 100644 index 000000000..af2d2840b --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/README @@ -0,0 +1,22 @@ +This example tests the %import directive and -relativeimport option. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pyX/pkg2/pkg3/pkg4/foo.i - Pkg4_Foo class + pyX/pkg2/bar.i - Pkg2_Bar class derived from Pkg4_Foo + +The difference between this ('relativeimport2') case and the case +'relativeimport1' is the "distance" between importer and importee. + +If everything works well, the package pyX.pkg2 shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/relativeimport2/py2/Makefile b/Examples/python/import_packages/relativeimport2/py2/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py2/__init__.py b/Examples/python/import_packages/relativeimport2/py2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/Makefile b/Examples/python/import_packages/relativeimport2/py2/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/__init__.py b/Examples/python/import_packages/relativeimport2/py2/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.hpp b/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.hpp new file mode 100644 index 000000000..20a00190a --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY2_PKG2_HPP +#define PY2_PKG2_HPP +#include "../../py2/pkg2/pkg3/pkg4/foo.hpp" +struct Pkg2_Bar : Pkg4_Foo {}; +#endif /* PY2_PKG2_HPP */ diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.i b/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.i new file mode 100644 index 000000000..0a932a2b9 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py2.pkg2") bar +%{ +#include "../../py2/pkg2/bar.hpp" +%} +%import "../../py2/pkg2/pkg3/pkg4/foo.i" +%include "../../py2/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/Makefile new file mode 100644 index 000000000..d6ae1b2bc --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg4 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/__init__.py b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/Makefile b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/Makefile new file mode 100644 index 000000000..286d90070 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/__init__.py b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.hpp b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.hpp new file mode 100644 index 000000000..2df933c59 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY2_PKG2_PKG3_PKG4 +#define PY2_PKG2_PKG3_PKG4 +struct Pkg4_Foo {}; +#endif /* PY2_PKG2_PKG3_PKG4 */ diff --git a/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.i b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.i new file mode 100644 index 000000000..311d7161c --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py2/pkg2/pkg3/pkg4/foo.i @@ -0,0 +1,5 @@ +%module(package="py2.pkg2.pkg3.pkg4") foo +%{ +#include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp" +%} +%include "../../../../py2/pkg2/pkg3/pkg4/foo.hpp" diff --git a/Examples/python/import_packages/relativeimport2/py3/Makefile b/Examples/python/import_packages/relativeimport2/py3/Makefile new file mode 100644 index 000000000..9595397d8 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py3/__init__.py b/Examples/python/import_packages/relativeimport2/py3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/Makefile b/Examples/python/import_packages/relativeimport2/py3/pkg2/Makefile new file mode 100644 index 000000000..36e099b78 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/Makefile @@ -0,0 +1,18 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp + cd pkg3 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='bar' python_clean + cd pkg3 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/__init__.py b/Examples/python/import_packages/relativeimport2/py3/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.hpp b/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.hpp new file mode 100644 index 000000000..16fdd362e --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.hpp @@ -0,0 +1,5 @@ +#ifndef PY3_PKG2_HPP +#define PY3_PKG2_HPP +#include "../../py3/pkg2/pkg3/pkg4/foo.hpp" +struct Pkg2_Bar : Pkg4_Foo {}; +#endif /* PY3_PKG2_HPP */ diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.i b/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.i new file mode 100644 index 000000000..3abbb05d3 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/bar.i @@ -0,0 +1,6 @@ +%module(package="py3.pkg2") bar +%{ +#include "../../py3/pkg2/bar.hpp" +%} +%import "../../py3/pkg2/pkg3/pkg4/foo.i" +%include "../../py3/pkg2/bar.hpp" diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/Makefile b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/Makefile new file mode 100644 index 000000000..d6ae1b2bc --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/Makefile @@ -0,0 +1,14 @@ +TOP = ../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg4 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg4 && $(MAKE) clean diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/__init__.py b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/Makefile b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/Makefile new file mode 100644 index 000000000..286d90070 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/__init__.py b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.hpp b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.hpp new file mode 100644 index 000000000..e24654c28 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PY3_PKG2_PKG3_PKG4 +#define PY3_PKG2_PKG3_PKG4 +struct Pkg4_Foo {}; +#endif /* PY3_PKG2_PKG3_PKG4 */ diff --git a/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.i b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.i new file mode 100644 index 000000000..36c5f01ea --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/py3/pkg2/pkg3/pkg4/foo.i @@ -0,0 +1,5 @@ +%module(package="py3.pkg2.pkg3.pkg4") foo +%{ +#include "../../../../py3/pkg2/pkg3/pkg4/foo.hpp" +%} +%include "../../../../py3/pkg2/pkg3/pkg4/foo.hpp" diff --git a/Examples/python/import_packages/relativeimport2/runme.py b/Examples/python/import_packages/relativeimport2/runme.py new file mode 100644 index 000000000..ac60eb630 --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/runme.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print "Testing %module(package=...) + python 'import' in __init__.py" +import sys +if sys.version_info < (3,0): + import py2.pkg2.bar + print " Finished importing py2.pkg2.bar" +else: + import py3.pkg2.bar + print " Finished importing py3.pkg2.bar" diff --git a/Examples/python/import_packages/relativeimport2/runme3.py b/Examples/python/import_packages/relativeimport2/runme3.py new file mode 100644 index 000000000..4b0d112cf --- /dev/null +++ b/Examples/python/import_packages/relativeimport2/runme3.py @@ -0,0 +1,9 @@ +# Test import of modules content from within __init__.py +print("Testing %module(package=...) + python 'import' in __init__.py") +import sys +if sys.version_info < (3, 0): + import py2.pkg2.bar + print(" Finished importing py2.pkg2.bar") +else: + import py3.pkg2.bar + print(" Finished importing py3.pkg2.bar") diff --git a/Examples/python/import_packages/same_modnames1/Makefile b/Examples/python/import_packages/same_modnames1/Makefile new file mode 100644 index 000000000..e05c13017 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/Makefile @@ -0,0 +1,20 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run + +build: + cd pkg1 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg1 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg1 && $(MAKE) clean + cd pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/same_modnames1/README b/Examples/python/import_packages/same_modnames1/README new file mode 100644 index 000000000..ee3f8d6f7 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/README @@ -0,0 +1,26 @@ +This example tests the %import directive and working with multiple modules. + +There are two modules having same name but belonging to different packages. +This case is not correctly handled by swig 2. + +The issue was reported as Source Forge bug #1297 and later as GitHub issue #7. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pkg1/foo.i - Pkg1_Foo class. + pkg2/foo.i - Pkg2_Foo class (derived from Pkg1_Foo). + +The pkg2/foo.i module uses %import to refer to pkg1/foo.i. + +If everything works well, the module pkg2.foo shall load properly. + +Unix: +----- +- Run make +- Run the test as described above. diff --git a/Examples/python/import_packages/same_modnames1/pkg1/Makefile b/Examples/python/import_packages/same_modnames1/pkg1/Makefile new file mode 100644 index 000000000..df1b30321 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg1/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/same_modnames1/pkg1/__init__.py b/Examples/python/import_packages/same_modnames1/pkg1/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/same_modnames1/pkg1/foo.hpp b/Examples/python/import_packages/same_modnames1/pkg1/foo.hpp new file mode 100644 index 000000000..b07c983b3 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg1/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PKG1_FOO_HPP +#define PKG1_FOO_HPP +struct Pkg1_Foo{}; +#endif /* PKG1_FOO_HPP */ diff --git a/Examples/python/import_packages/same_modnames1/pkg1/foo.i b/Examples/python/import_packages/same_modnames1/pkg1/foo.i new file mode 100644 index 000000000..9939f420a --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg1/foo.i @@ -0,0 +1,5 @@ +%module(package="pkg1") foo +%{ +#include "../pkg1/foo.hpp" +%} +%include "../pkg1/foo.hpp" diff --git a/Examples/python/import_packages/same_modnames1/pkg2/Makefile b/Examples/python/import_packages/same_modnames1/pkg2/Makefile new file mode 100644 index 000000000..df1b30321 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg2/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/same_modnames1/pkg2/__init__.py b/Examples/python/import_packages/same_modnames1/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/same_modnames1/pkg2/foo.hpp b/Examples/python/import_packages/same_modnames1/pkg2/foo.hpp new file mode 100644 index 000000000..72563a9d0 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg2/foo.hpp @@ -0,0 +1,5 @@ +#ifndef PKG2_FOO_HPP +#define PKG2_FOO_HPP +#include "../pkg1/foo.hpp" +struct Pkg2_Foo : public Pkg1_Foo{}; +#endif /* PKG2_FOO_HPP */ diff --git a/Examples/python/import_packages/same_modnames1/pkg2/foo.i b/Examples/python/import_packages/same_modnames1/pkg2/foo.i new file mode 100644 index 000000000..3a1ce0198 --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/pkg2/foo.i @@ -0,0 +1,6 @@ +%module(package="pkg2") foo +%{ +#include "../pkg2/foo.hpp" +%} +%import "../pkg1/foo.i" +%include "../pkg2/foo.hpp" diff --git a/Examples/python/import_packages/same_modnames1/runme.py b/Examples/python/import_packages/same_modnames1/runme.py new file mode 100644 index 000000000..923f0e0bb --- /dev/null +++ b/Examples/python/import_packages/same_modnames1/runme.py @@ -0,0 +1,9 @@ +# Test import of same modules from different packages +print "Testing %module(package=...) + %import + same modules in different packages" +import pkg2.foo +print " Finished importing pkg2.foo" + +var2 = pkg2.foo.Pkg2_Foo() +if str(type(var2)).find("'pkg2.foo.Pkg2_Foo'") == -1: + raise RuntimeError("failed type checking: " + str(type(var2))) +print " Successfully created object pkg2.foo.Pkg2_Foo" diff --git a/Examples/python/import_packages/same_modnames2/Makefile b/Examples/python/import_packages/same_modnames2/Makefile new file mode 100644 index 000000000..770343a80 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/Makefile @@ -0,0 +1,20 @@ +TOP = ../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +check: build + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run + +build: + cd pkg1 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + cd pkg1/pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' build + +static: + cd pkg1 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + cd pkg1/pkg2 && $(MAKE) SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_clean + cd pkg1 && $(MAKE) clean + cd pkg1/pkg2 && $(MAKE) clean diff --git a/Examples/python/import_packages/same_modnames2/README b/Examples/python/import_packages/same_modnames2/README new file mode 100644 index 000000000..9b0233f8b --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/README @@ -0,0 +1,26 @@ +This example tests the %import directive and working with multiple modules. + +There are two modules having same name but belonging to different packages. +This case is not correctly handled by swig 2. + +The issue was reported as Source Forge bug #1297 and later as GitHub issue #7. + +Use 'python runme.py' to run a test. + +Overview: +--------- + +The example defines 2 different extension modules--each wrapping a separate C++ +class. + + pkg1/foo.i - Pkg1_Foo class + pkg1/pkg2/foo.i - Pkg2_Foo class derived from Pkg1_Foo + +The pkg1/pkg2/foo module uses %import to refer to pkg1/foo. + +If everything works well, the module pkg1.pkg2.foo shall load properly. + +Unix: +----- +- Run make +- Run the test as described above diff --git a/Examples/python/import_packages/same_modnames2/pkg1/Makefile b/Examples/python/import_packages/same_modnames2/pkg1/Makefile new file mode 100644 index 000000000..df1b30321 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/same_modnames2/pkg1/__init__.py b/Examples/python/import_packages/same_modnames2/pkg1/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/same_modnames2/pkg1/foo.hpp b/Examples/python/import_packages/same_modnames2/pkg1/foo.hpp new file mode 100644 index 000000000..b07c983b3 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/foo.hpp @@ -0,0 +1,4 @@ +#ifndef PKG1_FOO_HPP +#define PKG1_FOO_HPP +struct Pkg1_Foo{}; +#endif /* PKG1_FOO_HPP */ diff --git a/Examples/python/import_packages/same_modnames2/pkg1/foo.i b/Examples/python/import_packages/same_modnames2/pkg1/foo.i new file mode 100644 index 000000000..9939f420a --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/foo.i @@ -0,0 +1,5 @@ +%module(package="pkg1") foo +%{ +#include "../pkg1/foo.hpp" +%} +%include "../pkg1/foo.hpp" diff --git a/Examples/python/import_packages/same_modnames2/pkg1/pkg2/Makefile b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/Makefile new file mode 100644 index 000000000..11e8573ad --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/Makefile @@ -0,0 +1,15 @@ +TOP = ../../../../.. +SWIG = $(realpath $(TOP)/../preinst-swig) +SWIGOPT = +LIBS = + +build: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp + +static: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp_static + +clean: + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='foo' python_clean diff --git a/Examples/python/import_packages/same_modnames2/pkg1/pkg2/__init__.py b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.hpp b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.hpp new file mode 100644 index 000000000..1b4a1d558 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.hpp @@ -0,0 +1,5 @@ +#ifndef PKG1_PKG2_FOO_HPP +#define PKG1_PKG2_FOO_HPP +#include "../../pkg1/foo.hpp" +struct Pkg2_Foo : public Pkg1_Foo{}; +#endif /* PKG1_PKG2_FOO_HPP */ diff --git a/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.i b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.i new file mode 100644 index 000000000..1741b3799 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/pkg1/pkg2/foo.i @@ -0,0 +1,6 @@ +%module(package="pkg1.pkg2") foo +%{ +#include "../../pkg1/pkg2/foo.hpp" +%} +%import "../../pkg1/foo.i" +%include "../../pkg1/pkg2/foo.hpp" diff --git a/Examples/python/import_packages/same_modnames2/runme.py b/Examples/python/import_packages/same_modnames2/runme.py new file mode 100644 index 000000000..af8f78194 --- /dev/null +++ b/Examples/python/import_packages/same_modnames2/runme.py @@ -0,0 +1,7 @@ +import pkg1.pkg2.foo +print " Finished importing pkg1.pkg2.foo" + +var2 = pkg1.pkg2.foo.Pkg2_Foo(); +if str(type(var2)).find("'pkg1.pkg2.foo.Pkg2_Foo'") == -1: + raise RuntimeError("failed type checking: " + str(type(var2))) +print " Successfully created object pkg1.pkg2.foo.Pkg2_Foo" diff --git a/Examples/python/import_template/Makefile b/Examples/python/import_template/Makefile index f63e12271..d83dfeaa8 100644 --- a/Examples/python/import_template/Makefile +++ b/Examples/python/import_template/Makefile @@ -4,19 +4,19 @@ SWIGOPT = LIBS = check: build - $(MAKE) -f $(TOP)/Makefile python_run + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run build: - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp - $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \ LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' python_cpp clean: - $(MAKE) -f $(TOP)/Makefile TARGET='$(TARGET)' python_clean + $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean rm -f foo.py bar.py spam.py base.py diff --git a/Examples/python/index.html b/Examples/python/index.html index 37f4b55af..3bbdd66e8 100644 --- a/Examples/python/index.html +++ b/Examples/python/index.html @@ -56,8 +56,7 @@ Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
-This example illustrates C++ class wrapping performed by SWIG. -C++ classes are simply transformed into Ruby classes that provide methods to -access class members. +This example illustrates wrapping a simple C++ class to give a Ruby class.
-
-
-
-
-- --void foo(int a); -%name(foo2) void foo(double a, double b); --
-
-
-%inline %{
- Vector *vector_add(Vector *a, Vector *b) {
- ... whatever ...
- }
-%}
-
-
-
--
- -
-
-
-
-- --void foo(int a); -%name(foo2) void foo(double a, double b); --
-
-
-%inline %{
- Vector *vector_add(Vector *a, Vector *b) {
- ... whatever ...
- }
-%}
-
-
-
--