summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2014-05-01 22:32:14 +0100
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2014-05-01 22:32:14 +0100
commit6d86fb173915867bd70d6780a174bce3c5b3c1df (patch)
tree7c913144a4f54f20f01c35ece3ac88e02f15a19f
parente6485d3ff2efa377b6a42008a6027fe2ebdc4f1a (diff)
parent6b25dfda60cea903311b9b807cd29fed648c9364 (diff)
downloadswig-6d86fb173915867bd70d6780a174bce3c5b3c1df.tar.gz
Merge branch 'master' into coverity-scan
* master: (378 commits) Restore full Travis testing since javascript branch merge Revert "Remove unnecessary Javascript installs on Travis" Remove unnecessary Javascript installs on Travis Javascript cosmetic changes Fix some typos Javascript: ensure banner appears before %begin code [PHP] The generated __isset() method now returns true for read-only properties. Eliminate needless casting away const from string constants Fix typos Enable Javascript in director_nspace_director_name_collision.i. Make javascript 'nspace' conform to corresponding lua example. Added some documentation on using 'node-webkit'. Fix missing ")" in code example Fix comment typos Fix m4 quoting of checks for yodl2man and yodl2html versions Enable javascript examples 'exception', 'namespace'. Fix bug and regression in javascript namespace generator. Prettify generated output in JS emitters. Fix node-gyp configuration for example 'exception'. Fix regression of 226da4. Print error when specified multiple js engines. Removed obsolete 'node.i'. Added a comment about V8_VERSION macro. Restore missing copyright info in javascript branch beautify javascript.cxx Javascript variable naming convention corrections Javascript test-suite - warning suppression not needed Javascript example Makefiles more consistent with other languages Cosmetic code changes in javascript.cxx Fix regression in Javascript generator for enums. Fix configuration for Javascript/node ctests. SKIP_JAVASCRIPT only when there is none of v8/node/jsc. Fix generator for Javascript enums. Turn on Swig_cparse_cplusplusout for Javascript/v8. Fix configuration for ctest with Javascript/v8. Add cast to test 'string_simple' to avoid C++ compiler error. Add 'fix' for Javascript/v8 to test 'enum_forward'. Fixed errors from previous commit. Removed all unnecessary asserts Remove unused variable Another go html fix Fix intgosize arg documentation Optimize metamethods inheritance resolving Updating documentation Only disable javascript tests if node-gyp is missing when testing node Revert "Javascript node test-suite makefile fixes for parallel make" Suppress keyword warning in test-suite Restore and fix infinity testcase for Javascript Simple C string test Javascript node test-suite makefile fixes for parallel make Restore missing make code in javascript branch Javascript test-suite makefile update ADD RUNPIPE and RUNTOOL to Javascript examples Remove unnecessary blank lines from Javascript examples Detect node-gyp at configure time and show version in javascript_version target Fix typo in Javascript exception Whitespace cleanup of Example Makefiles .gitignore: ignore Lib/swigwarn.swg Revert css style changes in javascript branch Add missing license info Javascript html documentation tidy up Improve missing JS engine error message a few Javascript clarifications in configure.ac Makefile and autoconf file tidy up for Javascript Fixing unused variable warnings Finish implementation with proxy functions Tidy up Example makefile for Javascript Alphabetical order for Javascript in -help output Remove junk files Remove duplicate declarations of strtoimax and strtoumax in inttypes.i Ignored enum fixes. Further shift operator regression fixes Fix use of shift operators in expressions regression since 3.0.0 Fix seg fault with extra ) brackets and >> More efficient end of template bracket (>>) handling beautify scanner.c Tidy up scanner.c DOH readme correction Fix typo in -lua -help output Remove extra </div> Update documentation for deprecation and removal of Close() Fix segfault when there are too many closing round brackets in parsed code Refix operator<< definition giving a syntax error Fix regression in 3.0.0 where legal code following an operator<< definition might give a syntax error. Remove unnecessary block from PHP version of SWIG_exception macro [PHP] Fix wrapping director constructors with default parameters with a ZTS-enabled build of PHP. Travis file code consistency Turn on Travis testing on javascript branch Add javascript to Sections.html Optimized travis before_install for Javascript. Document Javascript related preprocessor macros. Updated Javascript documentation. Insert a workaround for c_delete and c_delete_function for v8. Update Javascript.html. Remove inadvertently added xcode file. Remove gdb pretty printing. Remove cmake relict. Remove pandoc toolchain. Remove Javascript documentation source file. Revert "Development version for travis configuration." Fix travis configuration. Fix regression in custom v8 interpreter. Development version for travis configuration. Generalized smoke test configuration. Add 'version' target for javascript. Merged branch 'devel' from https://github.com/oliver----/swig-v8 (squashed commit): Add check to skip javascript test-suite if default interpreter is not installed. Activate travis matrix for different Javascript interpreters. Beautified Javascript module. Fix regressions. Removed obsolete paragraph from Javascript documentation. Fix pandoc filter. Minor tweaks in Javascript documentation. Adding a chapter about Javascript tests and examples. Minor change in Javascript configuration. Fix issues that were observed with newer JavascriptCore. Add missing copy ctor for Javascript Code Template class. Removed CMake. Fix regression in Javascript configuration. Fix regressions in configuration of some Javascript examples. More gitignores filtering Javascript related files. Fix custom javascript interpreter configuration for OSX. Make examples work with node.js and the custom interpreter. Introduced an extra Makefile for the custom javascript interpreter. Fix travis configuration. Added a comment. Fix regressions in Javascript example configuration. Fix issue with strange constants under OSX. Some fixes in example section of Javascript documentation. Add note about '-node' command line flag for Node.js code generation. Added examples to Javascript module documentation. Simplification in common javascript example Makefile. Add an extra argument for enabling nodejs support. Add more notes about how to install node. Better error message when no Javascript emitter is specified. Deactivated broken JS examples. Refactored configuration for javascript examples. Beginning to document v8 integration. Documented extending Node.js and Webkit's Javascript engine. Pandoc filter detects shell blocks when not explicitely given. Conitnued documenting the Javascript module. Not a real change. Add a pandoc filter to create compatible html. Add Javascript to chapters. More Javascript module documentation. Next iteration on creating a documentation for the Javascript module. Next iteration on creating a documentation for the Javascript module. Travis configuration for Javascript branch. Javascript examples. Javascript documentation. CMake configuration. Fix regression. Fix test configuration. Trying to install former working version of nodejs. Fix test configuration for nodejs. Add stub std_deque.i files. Add non pretty printing function to Templates. Fix bug with typedefd function pointers. Add some test runners. Fix emitter for member pointer constants. Fix %nspace support and activated relevant tests. Disable warnings for some v8 test-cases. Fix regression. Bugfix in argument marshalling. Disable testcase 'typemap_variables' for v8. Bugfix for Javascript generator. Replace $symname in generated function wrappers. Add missing macros. Let v8 generated code include stdlib.h Add cdata.i typemaps. Rearrange generation of init block to have custom init code within the initializer body. Make JSC inheritance definition more robust. Removed dead code. Bugfix for JSC %typemap(out) std::string&. Fix typemap declarations for (unsigned) long long. Add support for IN/OUTPUT typemaps. removed Clear before Dispose from newer v8 code, consider the following code: template <class T> void Persistent<T>::Dispose() { if (this->IsEmpty()) return; //Clear will trigger this V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_)); ... } fixed newer v8 compilation Add stub 'typemaps.i' files. Bugfix Javascript generator: valid name for dispatcher functions. Fix Javascript generator for smartpointeraccessed variables. Bugfix for Javascript generator: avoid duplicate action code generation. Bugfix in Javascript generator: detect member setter/getters correctly. Fix configuration for nodejs based tests. Some fixes and cleanup in Javascript generator. Fix settings for building nodejs tests. Add support for PackedData to Javascript generator. Added two more Javascript tests. Some fixes for the Javascript generator. Redefined set of Javascript smoke tests. Clean up in `javascripttypemaps.swg`. Fix v8 generator to use a non clashing name for built-in 'equals' method. Fix Javascript generator to use %renamed variable names. Activate Javascript test-cases `rename_simple` and `rename_scope`. Activate Javascript testcases `rename1-4`. Add `infinity` test-case to list of smoke tests. Added unit test using C99 INFINITY. This test actually tests a float conversion bug where converting to float imposed overflow checking which should not be there and causes this program to error out. This was seen originally in Javascript, but it turns out Python has the same bug. Lua does not have this bug. Other generators have not been tested. Bug-fix for static variables as proposed by Kota Iguchi. Let Travis test all three targets. Allow to run the test suite with our list of smoke tests. ... Conflicts: .travis.yml
-rw-r--r--.gitignore9
-rw-r--r--CHANGES6
-rw-r--r--CHANGES.current20
-rw-r--r--COPYRIGHT2
-rw-r--r--Doc/Manual/Extending.html10
-rw-r--r--Doc/Manual/Go.html6
-rw-r--r--Doc/Manual/Javascript.html808
-rw-r--r--Doc/Manual/Lua.html28
-rw-r--r--Doc/Manual/Preprocessor.html3
-rw-r--r--Doc/Manual/Ruby.html2
-rw-r--r--Doc/Manual/Sections.html1
-rw-r--r--Doc/Manual/chapters1
-rw-r--r--Examples/Makefile.in111
-rw-r--r--Examples/android/class/Makefile2
-rw-r--r--Examples/android/extend/Makefile2
-rw-r--r--Examples/chicken/class/Makefile4
-rw-r--r--Examples/chicken/constants/Makefile8
-rw-r--r--Examples/chicken/multimap/Makefile8
-rw-r--r--Examples/chicken/overload/Makefile6
-rw-r--r--Examples/chicken/simple/Makefile8
-rw-r--r--Examples/go/constants/Makefile2
-rw-r--r--Examples/go/template/Makefile2
-rw-r--r--Examples/guile/constants/Makefile2
-rw-r--r--Examples/java/constants/Makefile2
-rw-r--r--Examples/java/native/Makefile2
-rw-r--r--Examples/java/template/Makefile2
-rw-r--r--Examples/java/typemap/Makefile2
-rw-r--r--Examples/javascript/check.list13
-rwxr-xr-xExamples/javascript/class/Makefile3
-rw-r--r--Examples/javascript/class/binding.gyp8
-rwxr-xr-xExamples/javascript/class/example.cxx28
-rwxr-xr-xExamples/javascript/class/example.h34
-rwxr-xr-xExamples/javascript/class/example.i10
-rw-r--r--Examples/javascript/class/example.js1
-rwxr-xr-xExamples/javascript/class/runme.js46
-rwxr-xr-xExamples/javascript/constant/Makefile3
-rw-r--r--Examples/javascript/constant/binding.gyp8
-rw-r--r--Examples/javascript/constant/example.h8
-rwxr-xr-xExamples/javascript/constant/example.i24
-rw-r--r--Examples/javascript/constant/example.js1
-rwxr-xr-xExamples/javascript/constant/runme.js14
-rwxr-xr-xExamples/javascript/enum/Makefile3
-rw-r--r--Examples/javascript/enum/binding.gyp8
-rwxr-xr-xExamples/javascript/enum/example.cxx37
-rwxr-xr-xExamples/javascript/enum/example.h13
-rwxr-xr-xExamples/javascript/enum/example.i11
-rw-r--r--Examples/javascript/enum/example.js1
-rwxr-xr-xExamples/javascript/enum/runme.js34
-rw-r--r--Examples/javascript/example.mk27
-rwxr-xr-xExamples/javascript/exception/Makefile3
-rw-r--r--Examples/javascript/exception/binding.gyp29
-rw-r--r--Examples/javascript/exception/example.cxx1
-rw-r--r--Examples/javascript/exception/example.h53
-rw-r--r--Examples/javascript/exception/example.i12
-rw-r--r--Examples/javascript/exception/example.js1
-rw-r--r--Examples/javascript/exception/runme.js64
-rwxr-xr-xExamples/javascript/functor/Makefile3
-rw-r--r--Examples/javascript/functor/binding.gyp8
-rw-r--r--Examples/javascript/functor/example.cxx0
-rw-r--r--Examples/javascript/functor/example.i25
-rw-r--r--Examples/javascript/functor/example.js1
-rw-r--r--Examples/javascript/functor/runme.js15
-rwxr-xr-xExamples/javascript/nspace/Makefile3
-rw-r--r--Examples/javascript/nspace/binding.gyp8
-rw-r--r--Examples/javascript/nspace/example.h23
-rw-r--r--Examples/javascript/nspace/example.i10
-rw-r--r--Examples/javascript/nspace/example.js1
-rw-r--r--Examples/javascript/nspace/runme.js50
-rwxr-xr-xExamples/javascript/operator/Makefile3
-rw-r--r--Examples/javascript/operator/binding.gyp8
-rw-r--r--Examples/javascript/operator/example.h36
-rw-r--r--Examples/javascript/operator/example.i34
-rw-r--r--Examples/javascript/operator/example.js1
-rw-r--r--Examples/javascript/operator/runme.js25
-rwxr-xr-xExamples/javascript/overload/Makefile3
-rw-r--r--Examples/javascript/overload/binding.gyp8
-rw-r--r--Examples/javascript/overload/example.h28
-rw-r--r--Examples/javascript/overload/example.i16
-rw-r--r--Examples/javascript/overload/example.js1
-rw-r--r--Examples/javascript/overload/runme.js9
-rwxr-xr-xExamples/javascript/pointer/Makefile3
-rw-r--r--Examples/javascript/pointer/binding.gyp8
-rwxr-xr-xExamples/javascript/pointer/example.cxx16
-rwxr-xr-xExamples/javascript/pointer/example.i30
-rw-r--r--Examples/javascript/pointer/example.js1
-rwxr-xr-xExamples/javascript/pointer/runme.js35
-rw-r--r--Examples/javascript/pointer/typemaps.i0
-rwxr-xr-xExamples/javascript/reference/Makefile3
-rw-r--r--Examples/javascript/reference/binding.gyp8
-rwxr-xr-xExamples/javascript/reference/example.cxx46
-rwxr-xr-xExamples/javascript/reference/example.h26
-rwxr-xr-xExamples/javascript/reference/example.i42
-rw-r--r--Examples/javascript/reference/example.js1
-rwxr-xr-xExamples/javascript/reference/runme.js67
-rwxr-xr-xExamples/javascript/simple/Makefile3
-rw-r--r--Examples/javascript/simple/binding.gyp8
-rw-r--r--Examples/javascript/simple/example.cxx18
-rw-r--r--Examples/javascript/simple/example.i7
-rw-r--r--Examples/javascript/simple/example.js1
-rwxr-xr-xExamples/javascript/simple/runme.js26
-rwxr-xr-xExamples/javascript/template/Makefile3
-rw-r--r--Examples/javascript/template/binding.gyp8
-rw-r--r--Examples/javascript/template/example.h32
-rw-r--r--Examples/javascript/template/example.i17
-rw-r--r--Examples/javascript/template/example.js1
-rw-r--r--Examples/javascript/template/runme.js30
-rwxr-xr-xExamples/javascript/variables/Makefile3
-rw-r--r--Examples/javascript/variables/binding.gyp8
-rwxr-xr-xExamples/javascript/variables/example.cxx96
-rwxr-xr-xExamples/javascript/variables/example.h6
-rwxr-xr-xExamples/javascript/variables/example.i49
-rw-r--r--Examples/javascript/variables/example.js1
-rwxr-xr-xExamples/javascript/variables/runme.js68
-rw-r--r--Examples/lua/arrays/runme.lua2
-rw-r--r--Examples/lua/constants/Makefile4
-rw-r--r--Examples/lua/dual/dual.cpp6
-rw-r--r--Examples/lua/embed/embed.c18
-rw-r--r--Examples/lua/embed/runme.lua6
-rw-r--r--Examples/lua/embed2/embed2.c16
-rw-r--r--Examples/lua/embed2/runme.lua6
-rw-r--r--Examples/lua/embed3/embed3.cpp14
-rw-r--r--Examples/lua/embed3/example.h2
-rw-r--r--Examples/lua/embed3/runme.lua10
-rw-r--r--Examples/lua/exception/Makefile2
-rw-r--r--Examples/lua/exception/runme.lua4
-rw-r--r--Examples/lua/funcptr3/Makefile2
-rw-r--r--Examples/lua/functest/Makefile2
-rw-r--r--Examples/lua/functor/Makefile4
-rw-r--r--Examples/lua/import/Makefile2
-rw-r--r--Examples/lua/nspace/Makefile2
-rw-r--r--Examples/lua/owner/runme.lua14
-rw-r--r--Examples/lua/pointer/Makefile2
-rw-r--r--Examples/modula3/class/Makefile2
-rw-r--r--Examples/modula3/enum/Makefile2
-rw-r--r--Examples/modula3/reference/Makefile2
-rw-r--r--Examples/modula3/simple/Makefile2
-rw-r--r--Examples/modula3/typemap/Makefile2
-rw-r--r--Examples/mzscheme/multimap/Makefile2
-rw-r--r--Examples/mzscheme/simple/Makefile2
-rw-r--r--Examples/mzscheme/std_vector/Makefile8
-rw-r--r--Examples/ocaml/contract/Makefile4
-rw-r--r--Examples/ocaml/scoped_enum/Makefile4
-rw-r--r--Examples/ocaml/shapes/Makefile2
-rw-r--r--Examples/ocaml/std_string/Makefile2
-rw-r--r--Examples/ocaml/std_vector/Makefile2
-rw-r--r--Examples/ocaml/stl/Makefile2
-rw-r--r--Examples/ocaml/string_from_ptr/Makefile4
-rw-r--r--Examples/ocaml/strings_test/Makefile2
-rw-r--r--Examples/perl5/funcptr/Makefile2
-rw-r--r--Examples/perl5/java/Makefile4
-rw-r--r--Examples/perl5/multimap/Makefile2
-rw-r--r--Examples/perl5/multiple_inheritance/Makefile4
-rw-r--r--Examples/perl5/pointer/Makefile2
-rw-r--r--Examples/perl5/reference/Makefile2
-rw-r--r--Examples/perl5/simple/Makefile2
-rw-r--r--Examples/perl5/value/Makefile2
-rw-r--r--Examples/perl5/variables/Makefile2
-rw-r--r--Examples/php/callback/Makefile2
-rw-r--r--Examples/php/extend/Makefile2
-rw-r--r--Examples/pike/constants/Makefile2
-rw-r--r--Examples/pike/template/Makefile4
-rw-r--r--Examples/python/callback/Makefile2
-rw-r--r--Examples/python/constants/Makefile2
-rw-r--r--Examples/python/contract/Makefile2
-rw-r--r--Examples/python/exception/Makefile2
-rw-r--r--Examples/python/exceptproxy/Makefile4
-rw-r--r--Examples/python/extend/Makefile2
-rw-r--r--Examples/python/functor/Makefile4
-rw-r--r--Examples/python/java/Makefile3
-rw-r--r--Examples/python/libffi/Makefile2
-rw-r--r--Examples/python/operator/Makefile4
-rw-r--r--Examples/python/smartptr/Makefile2
-rw-r--r--Examples/python/std_map/Makefile4
-rw-r--r--Examples/python/std_vector/Makefile4
-rw-r--r--Examples/python/swigrun/Makefile2
-rw-r--r--Examples/python/template/Makefile4
-rw-r--r--Examples/python/varargs/Makefile2
-rw-r--r--Examples/ruby/constants/Makefile2
-rw-r--r--Examples/ruby/exception_class/Makefile2
-rw-r--r--Examples/ruby/hashargs/Makefile4
-rw-r--r--Examples/ruby/import/Makefile2
-rw-r--r--Examples/ruby/import_template/Makefile2
-rw-r--r--Examples/ruby/java/Makefile3
-rw-r--r--Examples/ruby/operator/Makefile4
-rw-r--r--Examples/ruby/std_vector/Makefile4
-rw-r--r--Examples/ruby/template/Makefile4
-rw-r--r--Examples/tcl/java/Makefile3
-rw-r--r--Examples/tcl/operator/Makefile2
-rw-r--r--Examples/tcl/std_vector/Makefile2
-rw-r--r--Examples/test-suite/c_delete.i4
-rw-r--r--Examples/test-suite/c_delete_function.i4
-rw-r--r--Examples/test-suite/common.mk3
-rw-r--r--Examples/test-suite/constructor_copy.i2
-rw-r--r--Examples/test-suite/cpp11_template_double_brackets.i14
-rw-r--r--Examples/test-suite/cpp_basic.i13
-rw-r--r--Examples/test-suite/d/operator_overload_runme.2.d2
-rw-r--r--Examples/test-suite/director_nspace.i2
-rw-r--r--Examples/test-suite/director_nspace_director_name_collision.i2
-rw-r--r--Examples/test-suite/enum_forward.i4
-rw-r--r--Examples/test-suite/enum_ignore.i20
-rw-r--r--Examples/test-suite/errors/cpp_extra_brackets.i6
-rw-r--r--Examples/test-suite/errors/cpp_extra_brackets.stderr1
-rw-r--r--Examples/test-suite/errors/cpp_extra_brackets2.i9
-rw-r--r--Examples/test-suite/errors/cpp_extra_brackets2.stderr1
-rw-r--r--Examples/test-suite/infinity.i47
-rwxr-xr-xExamples/test-suite/javascript/Makefile.in114
-rw-r--r--Examples/test-suite/javascript/abstract_access_runme.js6
-rw-r--r--Examples/test-suite/javascript/abstract_inherit_runme.js40
-rw-r--r--Examples/test-suite/javascript/abstract_typedef2_runme.js6
-rw-r--r--Examples/test-suite/javascript/abstract_typedef_runme.js8
-rw-r--r--Examples/test-suite/javascript/abstract_virtual_runme.js11
-rw-r--r--Examples/test-suite/javascript/array_member_runme.js22
-rw-r--r--Examples/test-suite/javascript/arrays_global_runme.js18
-rw-r--r--Examples/test-suite/javascript/callback_runme.js30
-rw-r--r--Examples/test-suite/javascript/char_binary_runme.js38
-rw-r--r--Examples/test-suite/javascript/char_strings_runme.js11
-rw-r--r--Examples/test-suite/javascript/class_ignore_runme.js6
-rw-r--r--Examples/test-suite/javascript/class_scope_weird_runme.js6
-rw-r--r--Examples/test-suite/javascript/complextest_runme.js22
-rw-r--r--Examples/test-suite/javascript/constover_runme.js33
-rw-r--r--Examples/test-suite/javascript/constructor_copy_runme.js42
-rw-r--r--Examples/test-suite/javascript/cpp_enum_runme.js28
-rw-r--r--Examples/test-suite/javascript/cpp_namespace_runme.js47
-rw-r--r--Examples/test-suite/javascript/cpp_static_runme.js9
-rw-r--r--Examples/test-suite/javascript/director_alternating_runme.js5
-rw-r--r--Examples/test-suite/javascript/disown_runme.js22
-rw-r--r--Examples/test-suite/javascript/dynamic_cast_runme.js12
-rw-r--r--Examples/test-suite/javascript/empty_runme.js1
-rw-r--r--Examples/test-suite/javascript/enum_template_runme.js8
-rw-r--r--Examples/test-suite/javascript/infinity_runme.js4
-rw-r--r--Examples/test-suite/javascript/namespace_virtual_method_runme.js3
-rw-r--r--Examples/test-suite/javascript/node_template/binding.gyp.in30
-rw-r--r--Examples/test-suite/javascript/node_template/index.js.in1
-rw-r--r--Examples/test-suite/javascript/nspace_extend_runme.js27
-rw-r--r--Examples/test-suite/javascript/nspace_runme.js76
-rw-r--r--Examples/test-suite/javascript/overload_copy_runme.js4
-rw-r--r--Examples/test-suite/javascript/preproc_include_runme.js23
-rw-r--r--Examples/test-suite/javascript/preproc_runme.js14
-rw-r--r--Examples/test-suite/javascript/rename1_runme.js68
-rw-r--r--Examples/test-suite/javascript/rename2_runme.js68
-rw-r--r--Examples/test-suite/javascript/rename3_runme.js68
-rw-r--r--Examples/test-suite/javascript/rename4_runme.js68
-rw-r--r--Examples/test-suite/javascript/rename_scope_runme.js17
-rw-r--r--Examples/test-suite/javascript/rename_simple_runme.js50
-rw-r--r--Examples/test-suite/javascript/ret_by_value_runme.js8
-rw-r--r--Examples/test-suite/javascript/setup_test.sh6
-rw-r--r--Examples/test-suite/javascript/string_simple_runme.js10
-rw-r--r--Examples/test-suite/javascript/struct_value_runme.js11
-rw-r--r--Examples/test-suite/javascript/template_static_runme.js3
-rw-r--r--Examples/test-suite/javascript/typedef_class_runme.js7
-rw-r--r--Examples/test-suite/javascript/typedef_inherit_runme.js23
-rw-r--r--Examples/test-suite/javascript/typedef_scope_runme.js12
-rw-r--r--Examples/test-suite/javascript/typemap_arrays_runme.js5
-rw-r--r--Examples/test-suite/javascript/typemap_delete_runme.js5
-rw-r--r--Examples/test-suite/javascript/typemap_namespace_runme.js7
-rw-r--r--Examples/test-suite/javascript/typemap_ns_using_runme.js4
-rw-r--r--Examples/test-suite/javascript/using1_runme.js4
-rw-r--r--Examples/test-suite/javascript/using2_runme.js4
-rw-r--r--Examples/test-suite/javascript/varargs_runme.js44
-rw-r--r--Examples/test-suite/lua/cpp_basic_runme.lua10
-rw-r--r--Examples/test-suite/lua/operator_overload_runme.lua32
-rw-r--r--Examples/test-suite/nspace.i2
-rw-r--r--Examples/test-suite/nspace_extend.i2
-rw-r--r--Examples/test-suite/operator_overload.i4
-rw-r--r--Examples/test-suite/php/arrays_runme.php1
-rw-r--r--Examples/test-suite/string_simple.i13
-rw-r--r--Lib/exception.i2
-rw-r--r--Lib/inttypes.i8
-rw-r--r--Lib/javascript/jsc/arrays_javascript.i123
-rw-r--r--Lib/javascript/jsc/ccomplex.i26
-rw-r--r--Lib/javascript/jsc/cdata.i1
-rw-r--r--Lib/javascript/jsc/complex.i6
-rw-r--r--Lib/javascript/jsc/exception.i1
-rw-r--r--Lib/javascript/jsc/javascript.swg19
-rw-r--r--Lib/javascript/jsc/javascriptcode.swg418
-rw-r--r--Lib/javascript/jsc/javascriptcomplex.swg146
-rw-r--r--Lib/javascript/jsc/javascriptfragments.swg23
-rw-r--r--Lib/javascript/jsc/javascripthelpers.swg69
-rw-r--r--Lib/javascript/jsc/javascriptinit.swg67
-rw-r--r--Lib/javascript/jsc/javascriptkw.swg40
-rw-r--r--Lib/javascript/jsc/javascriptprimtypes.swg182
-rw-r--r--Lib/javascript/jsc/javascriptrun.swg298
-rw-r--r--Lib/javascript/jsc/javascriptruntime.swg19
-rw-r--r--Lib/javascript/jsc/javascriptstrings.swg184
-rw-r--r--Lib/javascript/jsc/javascripttypemaps.swg54
-rwxr-xr-xLib/javascript/jsc/std_common.i5
-rw-r--r--Lib/javascript/jsc/std_complex.i19
-rw-r--r--Lib/javascript/jsc/std_deque.i1
-rw-r--r--Lib/javascript/jsc/std_except.i1
-rwxr-xr-xLib/javascript/jsc/std_map.i74
-rwxr-xr-xLib/javascript/jsc/std_pair.i34
-rwxr-xr-xLib/javascript/jsc/std_string.i69
-rwxr-xr-xLib/javascript/jsc/std_vector.i85
-rwxr-xr-xLib/javascript/jsc/stl.i10
-rw-r--r--Lib/javascript/jsc/typemaps.i148
-rw-r--r--Lib/javascript/v8/arrays_javascript.i125
-rw-r--r--Lib/javascript/v8/ccomplex.i26
-rw-r--r--Lib/javascript/v8/cdata.i1
-rw-r--r--Lib/javascript/v8/complex.i6
-rw-r--r--Lib/javascript/v8/exception.i1
-rw-r--r--Lib/javascript/v8/javascript.swg19
-rw-r--r--Lib/javascript/v8/javascriptcode.swg468
-rw-r--r--Lib/javascript/v8/javascriptcomplex.swg123
-rw-r--r--Lib/javascript/v8/javascriptfragments.swg23
-rw-r--r--Lib/javascript/v8/javascripthelpers.swg87
-rw-r--r--Lib/javascript/v8/javascriptinit.swg118
-rw-r--r--Lib/javascript/v8/javascriptkw.swg40
-rw-r--r--Lib/javascript/v8/javascriptprimtypes.swg198
-rw-r--r--Lib/javascript/v8/javascriptrun.swg462
-rw-r--r--Lib/javascript/v8/javascriptruntime.swg55
-rw-r--r--Lib/javascript/v8/javascriptstrings.swg59
-rw-r--r--Lib/javascript/v8/javascripttypemaps.swg43
-rwxr-xr-xLib/javascript/v8/std_common.i5
-rw-r--r--Lib/javascript/v8/std_complex.i19
-rw-r--r--Lib/javascript/v8/std_deque.i1
-rw-r--r--Lib/javascript/v8/std_except.i1
-rwxr-xr-xLib/javascript/v8/std_map.i74
-rwxr-xr-xLib/javascript/v8/std_pair.i33
-rwxr-xr-xLib/javascript/v8/std_string.i79
-rwxr-xr-xLib/javascript/v8/std_vector.i85
-rwxr-xr-xLib/javascript/v8/stl.i10
-rw-r--r--Lib/javascript/v8/typemaps.i148
-rw-r--r--Lib/lua/luarun.swg285
-rw-r--r--Lib/lua/luaruntime.swg4
-rw-r--r--Lib/typemaps/strings.swg4
-rw-r--r--Makefile.in19
-rw-r--r--Source/CParse/parser.y16
-rw-r--r--Source/DOH/README4
-rw-r--r--Source/Makefile.am1
-rw-r--r--Source/Modules/allegrocl.cxx2
-rw-r--r--Source/Modules/allocate.cxx4
-rw-r--r--Source/Modules/cffi.cxx2
-rw-r--r--Source/Modules/chicken.cxx12
-rw-r--r--Source/Modules/clisp.cxx2
-rw-r--r--Source/Modules/csharp.cxx6
-rw-r--r--Source/Modules/d.cxx2
-rw-r--r--Source/Modules/go.cxx10
-rw-r--r--Source/Modules/guile.cxx6
-rw-r--r--Source/Modules/java.cxx6
-rw-r--r--Source/Modules/javascript.cxx2427
-rw-r--r--Source/Modules/lua.cxx51
-rw-r--r--Source/Modules/main.cxx10
-rw-r--r--Source/Modules/modula3.cxx2
-rw-r--r--Source/Modules/mzscheme.cxx4
-rw-r--r--Source/Modules/ocaml.cxx4
-rw-r--r--Source/Modules/octave.cxx2
-rw-r--r--Source/Modules/perl5.cxx2
-rw-r--r--Source/Modules/php.cxx77
-rw-r--r--Source/Modules/pike.cxx2
-rw-r--r--Source/Modules/python.cxx6
-rw-r--r--Source/Modules/r.cxx5
-rw-r--r--Source/Modules/ruby.cxx4
-rw-r--r--Source/Modules/swigmain.cxx2
-rw-r--r--Source/Modules/tcl8.cxx2
-rw-r--r--Source/Modules/uffi.cxx2
-rw-r--r--Source/Swig/cwrap.c2
-rw-r--r--Source/Swig/scanner.c151
-rw-r--r--Tools/javascript/Makefile.in56
-rw-r--r--Tools/javascript/javascript.cxx66
-rw-r--r--Tools/javascript/js_shell.cxx156
-rw-r--r--Tools/javascript/js_shell.h53
-rw-r--r--Tools/javascript/jsc_shell.cxx233
-rwxr-xr-xTools/javascript/v8_shell.cxx313
-rw-r--r--configure.ac238
364 files changed, 12533 insertions, 400 deletions
diff --git a/.gitignore b/.gitignore
index 48826d914..d4d70b010 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,8 @@
# Editor files and various other junk
.*.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
@@ -71,6 +74,7 @@ Examples/xml/Makefile
Source/Include/stamp-h1
Source/Include/swigconfig.h
Source/Makefile
+Tools/javascript/Makefile
.deps
config.log
config.status
@@ -81,10 +85,12 @@ swig.spec
.dirstamp
CCache/ccache-swig
CCache/ccache-swig.1
+Lib/swigwarn.swg
Source/CParse/parser.c
Source/CParse/parser.h
Source/eswig
swig
+Tools/javascript/javascript
# Generated documentation
Doc/Manual/CCache.html
@@ -102,6 +108,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/*/
@@ -114,6 +121,8 @@ Examples/test-suite/r/*/
Examples/test-suite/ruby/*/
Examples/test-suite/tcl/*/
Examples/test-suite/uffi/*/
+*_wrap.c
+*_wrap.cxx
# Python generated files, based on:
# https://github.com/github/gitignore/blob/master/Python.gitignore
diff --git a/CHANGES b/CHANGES
index 297da776f..821d76b2c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -9970,7 +9970,7 @@ Version 1.3.23 (November 11, 2004)
- Remove the ability to share type information by using c linking.
All type sharing happens through a global variable in the target language.
+ Remove SWIG_NOIMPORT, SWIG_RUNTIME, and related defines.
- + Depreciate -runtime, -noruntime command line options
+ + Deprecate -runtime, -noruntime command line options
+ Update test-suite common.mk to correctly build multicpptest
+ Remove reference to precommon.swg
+ Update the guile_gh interface to share data by a global var instead
@@ -21212,9 +21212,9 @@ Version 1.3 Alpha 1 (February 11, 2000)
*** POTENTIAL INCOMPATIBILITY ***
1/30/00 : loic
- Conditionaly compile experimental code with --enable-experiment
+ Conditionally compile experimental code with --enable-experiment
configure flag.
- Fix .cvsignore to ignore configrue & yacc generated files
+ Fix .cvsignore to ignore configure & yacc generated files
1/28/00 : loic
Apply automake everywhere
diff --git a/CHANGES.current b/CHANGES.current
index eba047dc0..826b1a2c5 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,26 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.1 (in progress)
===========================
+2014-05-01: olly
+ [PHP] The generated __isset() method now returns true for read-only properties.
+
+2014-04-08: wsfulton
+ SF Bug #1366 - Remove duplicate declarations of strtoimax and strtoumax in inttypes.i
+
+2014-04-08: wsfulton
+ [Java C#] Enums which have been ignored via %ignore and are subsequently
+ used are handled slightly differently. Type wrapper classes are now generated
+ which are effectively a wrapper of an empty enum. Previously in Java uncompilable
+ code was generated and in C# an int was used.
+
+2014-04-04: wsfulton
+ Fix regression in 3.0.0 where legal code following an operator<< definition might
+ give a syntax error. SF Bug #1365.
+
+2014-04-03: olly
+ [PHP] Fix wrapping director constructors with default parameters
+ with a ZTS-enabled build of PHP.
+
2014-04-02: olly
[PHP] Pass the ZTS context we already have to avoid needing to
call TSRMLS_FETCH, which is relatively expensive.
diff --git a/COPYRIGHT b/COPYRIGHT
index 3f4711a47..1344630bb 100644
--- a/COPYRIGHT
+++ b/COPYRIGHT
@@ -16,6 +16,8 @@ Active SWIG Developers:
Joseph Wang (joequant@gmail.com) (R)
Xavier Delacour (xavier.delacour@gmail.com) (Octave)
David Nadlinger (code@klickverbot.at) (D)
+ Oliver Buchtala (oliver.buchtala@gmail.com) (Javascript)
+ Neha Narang (narangneha03@gmail.com) (Javascript)
Past SWIG developers and major contributors include:
Dave Beazley (dave-swig@dabeaz.com) (SWIG core, Python, Tcl, Perl)
diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html
index 5cd89a280..5c209bbb5 100644
--- a/Doc/Manual/Extending.html
+++ b/Doc/Manual/Extending.html
@@ -1500,12 +1500,11 @@ Create a File object wrapper around an existing <tt>FILE *</tt> object.
</div>
<p>
-<b><tt>int Close(String_or_FILE *f)</tt></b>
+There's no explicit function to close a file, just call <tt>Delete(f)</tt> -
+this decreases the reference count, and the file will be closed when the
+reference count reaches zero.
</p>
-<div class="indent">
-<p>Closes a file. Has no effect on strings.</p>
-
<p>
The use of the above I/O functions and strings play a critical role in SWIG. It is
common to see small code fragments of code generated using code like this:
@@ -1529,8 +1528,6 @@ Printf(f, "%s\n", s);
Similarly, the preprocessor and parser all operate on string-files.
</p>
-</div>
-
<H2><a name="Extending_nn21"></a>39.6 Navigating and manipulating parse trees</H2>
@@ -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;
diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html
index f970b02e8..93b87a4a4 100644
--- a/Doc/Manual/Go.html
+++ b/Doc/Manual/Go.html
@@ -94,9 +94,9 @@ swig -go -help
</tr>
<tr>
-<td>-intgo-type-size %lt;s%gt;</td>
+<td>-intgosize &lt;s&gt;</td>
<td>Set the size for the Go type <tt>int</tt>. This controls the size
- that the C/C++ code expects to see. The %lt;s%gt; argument should
+ that the C/C++ code expects to see. The &lt;s&gt; argument should
be 32 or 64. This option is currently required during the
transition from Go 1.0 to Go 1.1, as the size of <tt>int</tt> on
64-bit x86 systems changes between those releases (from 32 bits to
@@ -125,7 +125,7 @@ swig -go -help
</tr>
<tr>
-<td>-soname %lt;name%gt;</td>
+<td>-soname &lt;name&gt;</td>
<td>Set the runtime name of the shared library that the dynamic linker
should include at runtime. The default is the package name with
".so" appended. This is only used when generating code for
diff --git a/Doc/Manual/Javascript.html b/Doc/Manual/Javascript.html
new file mode 100644
index 000000000..e589d9d09
--- /dev/null
+++ b/Doc/Manual/Javascript.html
@@ -0,0 +1,808 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <link rel="stylesheet" type="text/css" href="./style.css">
+ <title></title>
+</head>
+<body>
+
+<H1>SWIG and Javascript</H1>
+<p>This chapter describes SWIG's support of Javascript. It does not cover SWIG basics, but only information that is specific to this module.</p>
+
+<H2>Overview</H2>
+<p>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 <a href="http://nodejs.org">node.js</a>, it is also used as a backend development language.</p>
+<p>Native Javascript extensions can be used for applications that embed a web-browser view or that embed a Javascript engine (such as <em>node.js</em>). Extending a general purpose web-browser is not possible as this would be a severe security issue.</p>
+<p>SWIG Javascript currently supports <strong>JavascriptCore</strong>, the Javascript engine used by <code>Safari/Webkit</code>, and <strong>v8</strong>, which is used by <code>Chromium</code> and <code>node.js</code>.</p>
+<p><a href="http://www.webkit.org/">WebKit</a> is a modern browser implementation available as open-source which can be embedded into an application.
+With <a href="https://github.com/rogerwang/node-webkit">node-webkit</a> there is a platform which uses Google's <code>Chromium</code> as Web-Browser widget and <code>node.js</code> for javascript extensions.
+</p>
+
+<H2>Preliminaries</H2>
+
+<H3>Running SWIG</H3>
+
+<p>Suppose that you defined a SWIG module such as the following:</p>
+<div class="code">
+<pre>
+%module example
+%{
+#include "example.h"
+%}
+int gcd(int x, int y);
+extern double Foo;</pre>
+</div>
+<p>To build a Javascript module, run SWIG using the <code>-javascript</code> option and a desired target engine <code>-jsc</code>, <code>-v8</code>, or <code>-node</code>. The generator for <code>node</code> is essentially delegating to the <code>v8</code> generator and adds some necessary preprocessor definitions.</p>
+<div class="shell">
+<pre>
+$ swig -javascript -jsc example.i</pre>
+</div>
+<p>If building a C++ extension, add the -c++ option:</p>
+<div class="shell">
+<pre>
+$ swig -c++ -javascript -jsc example.i</pre>
+</div>
+<p>This creates a C/C++ source file <code>example_wrap.c</code> or <code>example_wrap.cxx</code>. The generated C source file contains the low-level wrappers that need to be compiled and linked with the rest of your C/C++ application to create an extension module.</p>
+<p>The name of the wrapper file is derived from the name of the input file. For example, if the input file is <code>example.i</code>, the name of the wrapper file is <code>example_wrap.c</code>. To change this, you can use the -o option. The wrapped module will export one function which must be called to register the module with the Javascript interpreter. For example, if your module is named <code>example</code> the corresponding initializer for JavascriptCore would be</p>
+<div class="code">
+<pre>
+bool example_initialize(JSGlobalContextRef context, JSObjectRef *exports)</pre>
+</div>
+<p>and for v8:</p>
+<div class="code">
+<pre>
+void example_initialize(v8::Handle<v8::Object> exports)</pre>
+</div>
+<p>
+<p><b>Note</b>: be aware that <code>v8</code> has a C++ API, and thus, the generated modules must be compiled as C++.</p>
+</p>
+
+<H3>Running Tests and Examples</H3>
+<p>The configuration for tests and examples currently supports Linux and Mac only and not MinGW (Windows) yet.</p>
+<p>The default interpreter is <code>node.js</code> as it is available on all platforms and convenient to use.</p>
+<p>Running the examples with JavascriptCore requires <code>libjavascriptcoregtk-1.0</code> to be installed, e.g., under Ubuntu with</p>
+<div class="shell">
+<pre>
+$ sudo apt-get install libjavascriptcoregtk-1.0-dev</pre>
+</div>
+<p>Running with <code>V8</code> requires <code>libv8</code>:</p>
+<div class="shell">
+<pre>
+$ sudo apt-get install libv8-dev</pre>
+</div>
+<p>Examples can be run using</p>
+<div class="shell">
+<pre>
+$ make check-javascript-examples ENGINE=jsc</pre>
+</div>
+<p><code>ENGINE</code> can be <code>node</code>, <code>jsc</code>, or <code>v8</code>.</p>
+<p>The test-suite can be run using</p>
+<div class="shell">
+<pre>
+$ make check-javascript-test-suite ENGINE=jsc</pre>
+</div>
+<p>Tests should run without any problems, i.e., have been tried out, on the following platforms/interpreters:</p>
+<div class="code">
+<pre>
+- Ubuntu Precise 12.04 64bit
+ - JavascriptCore (Webkit 1.8.3)
+ - Node.js (0.10.26)
+ - v8 (3.7.12)
+- Ubuntu Saucy 13.10 64bit
+ - JavascriptCore (Webkit 1.10.2)
+ - Node.js
+ - v8 (3.14.5)
+- Mac OSX Mountain Lion 10.8
+ - JavascriptCore (built-in)
+ - Node.js
+- Windows 7 64bit (VS 2010)
+ - Node.js</pre>
+</div>
+<p>
+
+<H3>Future work</H3>
+<p>The Javascript module is not yet as mature as other modules and some things are still missing. As it makes use of SWIG's Unified Typemap Library (UTL), many typemaps are inherited. We could work on that if requested:</p>
+<ul>
+<li><p>More typemaps: compared to other modules there are only a few typemaps implemented. For instance a lot of the <code>std_*.i</code> typemaps are missing, such as <code>std_iostream</code>, for instance.</p></li>
+<li><p>Director support: this would allow to extend a C++ abstract base class in Javascript. A pragmatic intermediate step for the most important usecase would be to support Javascript callbacks as arguments.</p></li>
+</ul>
+
+<H2>Integration</H2>
+<p>This chapter gives a short introduction how to use a native Javascript extension: as a <code>node.js</code> module, and as an extension for an embedded Webkit.</p>
+
+<H3>Creating <code>node.js</code> Extensions</H3>
+<p>To install <code>node.js</code> you can download an installer from their <a href="https://launchpad.net/~chris-lea/+archive/node.js">web-site</a> for OSX and Windows. For Linux you can either build the source yourself and run <code>sudo checkinstall</code> or keep to the (probably stone-age) packaged version. For Ubuntu there is a <a href="https://launchpad.net/~chris-lea/+archive/node.js/">PPA</a> available.</p>
+<div class="shell">
+<pre>
+$ sudo add-apt-repository ppa:chris-lea/node.js
+$ sudo apt-get update
+$ sudo apt-get install nodejs</pre>
+</div>
+<p>As <code>v8</code> 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, <code>node.js</code> provides a build tool called <code>node-gyp</code>.</p>
+<p>You have to install it using <code>npm</code>:</p>
+<div class="shell">
+<pre>
+$ sudo npm install -g node-gyp</pre>
+</div>
+<p><code>node-gyp</code> expects a configuration file named <code>binding.gyp</code> which is basically in JSON format and conforms to the same format that is used with Google's build-tool <code>gyp</code>.</p>
+<p><code>binding.gyp</code>:</p>
+<div class="code">
+<pre>
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}</pre>
+</div>
+<p>First create the wrapper using SWIG:</p>
+<div class="shell">
+<pre>
+$ swig -javascript -node -c++ example.cxx</pre>
+</div>
+<p>Then run <code>node-gyp</code></p>
+<div class="shell">
+<pre>
+$ node-gyp</pre>
+</div>
+<p>This will create a <code>build</code> folder containing the native module. To use the extension you need to 'require' it in your Javascript source file:</p>
+<div class="code">
+<pre>
+require("./build/Release/example")</pre>
+</div>
+<p>A more detailed explanation is given in the <a href="#Javascript_examples">Examples</a> section.</p>
+
+<H4>Troubleshooting</H4>
+<ul>
+<li><em>'module' object has no attribute 'script_main'</em></li>
+</ul>
+<p>This error happens when <code>gyp</code> is installed as a distribution package. It seems to be outdated. Removing it resolves the problem.</p>
+<div class="shell">
+<pre>
+$ sudo apt-get remove gyp</pre>
+</div>
+
+<H3>Embedded Webkit</H3>
+<p>Webkit is pre-installed on OSX and available as a library for GTK.</p>
+
+<H4>OSX</H4>
+<p>There is general information about programming with WebKit on <a href="https://developer.apple.com/library/mac/documentation/cocoa/conceptual/DisplayWebContent/DisplayWebContent.html">Apple Developer Documentation</a>. Details about <code>Cocoa</code> programming are not covered here.</p>
+<p>An integration of a native extension 'example' would look like this:</p>
+<div class="code">
+<pre>
+#import "appDelegate.h"
+
+extern bool example_initialize(JSGlobalContextRef context);
+
+
+@implementation ExampleAppDelegate
+
+@synthesize webView;
+
+
+- (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];
+
+ example_initialize(context);
+
+ [ [webView mainFrame] loadRequest:
+ [NSURLRequest requestWithURL: [NSURL URLWithString:url] ]
+ ];
+}
+
+@end</pre>
+</div>
+
+<H4>GTK</H4>
+<p>There is general information about programming GTK at <a href="https://developer.gnome.org/gtk2/">GTK documentation</a> and in the <a href="https://developer.gnome.org/gtk-tutorial">GTK tutorial</a>, and for Webkit there is a <a href="http://webkitgtk.org/reference/webkitgtk/stable/index.html">Webkit GTK+ API Reference</a>.</p>
+<p>An integration of a native extension 'example' would look like this:</p>
+<div class="code">
+<pre>
+#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);
+ example_initialize(context);
+
+ ...
+
+ // 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;
+}</pre>
+</div>
+
+<H3>Creating Applications with <code>node-webkit</code></H3>
+<p>
+<p>To get started with <code>node-webkit</code> there is a very informative set of <a href="https://github.com/rogerwang/node-webkit/wiki">wiki pages</a>.</p>
+<p>Similar to <code>node.js</code>, <code>node-webkit</code> is started from command line within a <code>node.js</code> project directory.
+Native extensions are created in the very same way as for <code>node.js</code>, except that a customized <code>gyp</code> derivate has to be used: <a href="https://github.com/rogerwang/nw-gyp">nw-gyp</a>.
+</p>
+
+<p>
+A simple example would have the following structure:
+</p>
+
+<div class="code">
+<pre>
+- package.json
+- app.html
+- app.js
+- node_modules
+ / example
+ ... (as known from node.js)
+</pre>
+</div>
+
+<p>
+The configuration file essentially conforms to <code>node.js</code> syntax.
+It has some extras to configure <code>node-webkit</code>. See the <a href="">Manifest</a> specification for more details.
+</p>
+
+<p>
+ <code>package.json</code>:
+</p>
+<div class="code">
+<pre>
+{
+ "name": "example"
+ "main": "app.html"
+ "window": {
+ "show": true,
+ "width": 800,
+ "height": 600
+ }
+}</pre>
+</div>
+
+<p>
+The <code>'main'</code> property of <code>package.json</code> specifies a web-page to be rendered in
+the main window.</p>
+
+<p>
+ <code>app.html</code>:
+</p>
+
+<div class="code">
+<pre>
+&lt;html&gt;
+ &lt;head&gt;
+ &lt;script src="app.js"&gt;&lt;/script&gt;
+ &lt;/head&gt;
+ &lt;body&gt;
+ &lt;div&gt;
+ The greatest common divisor of
+ &lt;span id="x"&gt;&lt;/span&gt; and
+ &lt;span id="y"&gt;&lt;/span&gt; is
+ &lt;span id="z"&gt;&lt;/span&gt;.
+ &lt;/div&gt;
+ &lt;/body&gt;
+&lt;/html&gt;</pre>
+</div>
+
+<p>
+As known from <code>node.js</code> one can use <code>require</code> to load javascript modules.
+Additionally, <code>node-webkit</code> provides an API that allows to manipulate the window's menu,
+open new windows, and many more things.
+</p>
+
+<p>
+ <code>app.js</code>:
+</p>
+
+<div class="code">
+<pre>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;
+};</pre>
+</div>
+
+<H2><a name="Javascript_examples">Examples</H2>
+<p>Some basic examples are shown here in more detail.</p>
+
+<H3>Simple</H3>
+<p>The common example <code>simple</code> looks like this:</p>
+<div class="code">
+<pre>
+/* File : example.i */
+%module example
+
+%inline %{
+extern int gcd(int x, int y);
+extern double Foo;
+%}</pre>
+</div>
+<p>To make this available as a node extension a <code>binding.gyp</code> has to be created:</p>
+<div class="code">
+<pre>
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}</pre>
+</div>
+<p>Then <code>node-gyp</code> is used to build the extension:</p>
+<div class="shell">
+<pre>
+$ node-gyp configure build</pre>
+</div>
+<p>From a 'nodejs` application the extension would be used like this:</p>
+<div class="code">
+<pre>
+// 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;</pre>
+</div>
+<p>First the module <code>example</code> is loaded from the previously built extension. Global methods and variables are available in the scope of the module.</p>
+<p>
+<p><b>Note</b>: ECMAScript 5, the currently implemented Javascript standard, does not have modules. <code>node.js</code> and other implementations provide this mechanism defined by the <a href="http://wiki.commonjs.org/wiki/CommonJS">CommonJS</a> group. For browsers this is provided by <a href="http://browserify.org">Browserify</a>, for instance.</p>
+</p>
+
+<H3>Class</H3>
+<p>The common example <code>class</code> defines three classes, <code>Shape</code>, <code>Circle</code>, and <code>Square</code>:</p>
+<div class="code">
+<pre>
+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);
+};</pre>
+</div>
+<p><code>Circle</code> and <code>Square</code> inherit from <code>Shape</code>. <code>Shape</code> has a static variable <code>nshapes</code>, a function <code>move</code> that can't be overridden (non-virtual), and two abstract functions <code>area</code> and <code>perimeter</code> (pure virtual) that must be overridden by the sub-classes.</p>
+<p>A <code>nodejs</code> extension is built the same way as for the <code>simple</code> example.</p>
+<p>In Javascript it can be used as follows:</p>
+<div class="code">
+<pre>
+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();</pre>
+</div>
+<p>Running these commands in an interactive node shell results in the following output:</p>
+<div class="shell">
+<pre>
+$ 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)</pre>
+</div>
+<p>
+<p><b>Note</b>: 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 <code>prototype</code> 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 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain">Inheritance and the prototype chain</a>, for instance.</p>
+</p>
+
+<H2>Implementation</H2>
+<p>The Javascript Module implementation has taken a very different approach compared to other language modules in order to support different Javascript interpreters.</p>
+
+<H3>Source Code</H3>
+<p>The Javascript module is implemented in <code>Source/Modules/javascript.cxx</code>. It dispatches the code generation to a <code>JSEmitter</code> instance, <code>V8Emitter</code> or <code>JSCEmitter</code>. Additionally there are some helpers: <code>Template</code>, for templated code generation, and <code>JSEmitterState</code>, 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:</p>
+<div class="code">
+<pre>
+// 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_) { ... }
+...</pre>
+</div>
+
+<H3>Code Templates</H3>
+<p>All generated code is created on the basis of code templates. The templates for <em>JavascriptCore</em> can be found in <code>Lib/javascript/jsc/javascriptcode.swg</code>, for <em>v8</em> in <code>Lib/javascript/v8/javascriptcode.swg</code>.</p>
+<p>To track the originating code template for generated code you can run</p>
+<div class="shell">
+<pre>
+$ swig -javascript -jsc -debug-codetemplates</pre>
+</div>
+<p>which wraps generated code with a descriptive comment</p>
+<div class="code">
+<pre>
+/* begin fragment("template_name") */
+
+...generated code ...
+
+/* end fragment("template_name") */</pre>
+</div>
+<p>The Template class is used like this:</p>
+<div class="code">
+<pre>
+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);</pre>
+</div>
+<p>A code template is registered with the <em>JSEmitter</em> via <code>fragment(name, &quot;template&quot;)</code>, e.g.,</p>
+<div class="code">
+<pre>
+%fragment ("jsc_variable_declaration", "templates")
+%{
+ {"$jsname", $jsgetter, $jssetter, kJSPropertyAttributeNone},
+%}</pre>
+</div>
+<p><code>Template</code> creates a copy of that string and <code>Template::replace</code> uses Swig's <code>Replaceall</code> to replace variables in the template. <code>Template::trim</code> can be used to eliminate leading and trailing whitespaces. <code>Template::print</code> is used to write the final template string to a Swig <code>DOH</code> (based on <code>Printv</code>). All methods allow chaining.</p>
+
+<H3>Emitter</H3>
+<p>The Javascript module delegates code generation to a <code>JSEmitter</code> instance. The following extract shows the essential interface:</p>
+<div class="code">
+<pre>
+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();
+
+ ...
+
+}</pre>
+</div>
+<p>The module calls <code>initialize</code>, <code>dump</code>, and <code>close</code> from within the <code>top</code> method:</p>
+<div class="code">
+<pre>
+int JAVASCRIPT::top(Node *n) {
+ emitter->initialize(n);
+
+ Language::top(n);
+
+ emitter->dump(n);
+ emitter->close();
+
+ return SWIG_OK;
+}</pre>
+</div>
+<p>The methods <code>enterClass</code> and <code>exitClass</code> are called from within the <code>classHandler</code> method:</p>
+<div class="code">
+<pre>
+int JAVASCRIPT::classHandler(Node *n) {
+
+ emitter->enterClass(n);
+ Language::classHandler(n);
+ emitter->exitClass(n);
+
+ return SWIG_OK;
+}</pre>
+</div>
+<p>In <code>enterClass</code> the emitter stores state information that is necessary when processing class members. In <code>exitClass</code> the wrapper code for the whole class is generated.</p>
+
+<H3>Emitter states</H3>
+<p>For storing information during the AST traversal the emitter provides a <code>JSEmitterState</code> with different slots to store data representing the scopes global, class, function, and variable.</p>
+<div class="code">
+<pre>
+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);
+
+ ...
+};</pre>
+</div>
+<p>When entering a scope, such as in <code>enterClass</code>, the corresponding state is reset and new data is stored:</p>
+<div class="code">
+<pre>
+state.clazz(RESET);
+state.clazz(NAME, Getattr(n, "sym:name"));</pre>
+</div>
+<p>State information can be retrieved using <code>state.clazz(NAME)</code> or with <code>Getattr</code> on <code>state.clazz()</code> which actually returns a <code>Hash</code> instance.</p>
+</body>
+</html>
diff --git a/Doc/Manual/Lua.html b/Doc/Manual/Lua.html
index e6cf11b9f..c67e08834 100644
--- a/Doc/Manual/Lua.html
+++ b/Doc/Manual/Lua.html
@@ -990,7 +990,7 @@ The current list of operators which can be overloaded (and the alternative funct
<li><tt>__sub__</tt> operator-
<li><tt>__mul__</tt> operator *
<li><tt>__div__</tt> operator/
-<li><tt>__neg__</tt> unary minus
+<li><tt>__unm__</tt> unary minus
<li><tt>__call__</tt> operator<tt>()</tt> (often used in functor classes)
<li><tt>__pow__</tt> the exponential fn (no C++ equivalent, Lua uses <tt>^</tt>)
<li><tt>__concat__</tt> the concatenation operator (SWIG maps C++'s <tt>~</tt> to Lua's <tt>..</tt>)
@@ -1037,7 +1037,29 @@ It is also possible to overload the operator<tt>[]</tt>, but currently this cann
void __setitem__(int i,double d); // i is the index, d is the data
};
</pre></div>
-
+<p>
+C++ operators are mapped to Lua predefined metafunctions. Class inherits from its bases the following list of metafunctions ( thus inheriting the folloging
+operators and pseudo-operators):</p>
+<ul>
+<li><tt>__add__</tt>
+<li><tt>__sub__</tt>
+<li><tt>__mul__</tt>
+<li><tt>__div__</tt>
+<li><tt>__unm__</tt>
+<li><tt>__mod__</tt>
+<li><tt>__call__</tt>
+<li><tt>__pow__</tt>
+<li><tt>__concat__</tt>
+<li><tt>__eq__</tt>
+<li><tt>__lt__</tt>
+<li><tt>__le__</tt>
+<li><tt>__len__</tt>
+<li><tt>__getitem__</tt>
+<li><tt>__setitem__</tt>
+<li><tt>__tostring</tt> used internally by Lua for tostring() function. __str__ is mapped to this function
+</ul>
+<p>No other lua metafunction is inherited. For example, __gc is not inherited and must be redefined in every class. <tt>__tostring</tt> is subject to a special handling. If absent in class and in class bases, a default one will be provided by SWIG</p>
+</p>
<H3><a name="Lua_nn19"></a>27.3.12 Class extension with %extend</H3>
@@ -1073,7 +1095,7 @@ Now we extend it with some new code
return tmp;
}
bool operator==(const Complex&amp; c)
- { return ($self-&gt;re()==c.re() &amp;&amp; $self-&gt;im()==c.im();}
+ { return ($self-&gt;re()==c.re() &amp;&amp; $self-&gt;im()==c.im());}
};
</pre></div>
<p>
diff --git a/Doc/Manual/Preprocessor.html b/Doc/Manual/Preprocessor.html
index d5c41dde7..745570ca4 100644
--- a/Doc/Manual/Preprocessor.html
+++ b/Doc/Manual/Preprocessor.html
@@ -115,6 +115,9 @@ SWIGCLISP Defined when using CLISP
SWIGCSHARP Defined when using C#
SWIGGUILE Defined when using Guile
SWIGJAVA Defined when using Java
+SWIGJAVASCRIPT Defined when using Javascript
+SWIG_JAVASCRIPT_JSC Defined when using Javascript for JavascriptCore
+SWIG_JAVASCRIPT_V8 Defined when using Javascript for v8 or node.js
SWIGLUA Defined when using Lua
SWIGMODULA3 Defined when using Modula-3
SWIGMZSCHEME Defined when using Mzscheme
diff --git a/Doc/Manual/Ruby.html b/Doc/Manual/Ruby.html
index 3fc45834d..9719239a9 100644
--- a/Doc/Manual/Ruby.html
+++ b/Doc/Manual/Ruby.html
@@ -4690,7 +4690,7 @@ public:
C++ constructor, thus creating a new <tt>foo</tt> 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 <tt>Foo's</tt> destructor.</p>
+called. It in turn will call <tt>Foo</tt>'s destructor.</p>
<p>Next, consider this code: </p>
diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html
index 877ca2fae..99d1dfe0d 100644
--- a/Doc/Manual/Sections.html
+++ b/Doc/Manual/Sections.html
@@ -42,6 +42,7 @@ Last update : SWIG-3.0.1 (in progress)
<li><a href="Go.html#Go">Go support</a></li>
<li><a href="Guile.html#Guile">Guile support</a></li>
<li><a href="Java.html#Java">Java support</a></li>
+<li><a href="Javascript.html#Java">Javascript support</a></li>
<li><a href="Lisp.html#Lisp">Common Lisp support</a></li>
<li><a href="Lua.html#Lua">Lua support</a></li>
<li><a href="Modula3.html#Modula3">Modula3 support</a></li>
diff --git a/Doc/Manual/chapters b/Doc/Manual/chapters
index 45d35e793..c5f655254 100644
--- a/Doc/Manual/chapters
+++ b/Doc/Manual/chapters
@@ -23,6 +23,7 @@ D.html
Go.html
Guile.html
Java.html
+Javascript.html
Lisp.html
Lua.html
Modula3.html
diff --git a/Examples/Makefile.in b/Examples/Makefile.in
index 218d8eca5..01febf575 100644
--- a/Examples/Makefile.in
+++ b/Examples/Makefile.in
@@ -590,6 +590,117 @@ java_clean:
rm -f *.@OBJEXT@ *@JAVASO@
##################################################################
+##### JAVASCRIPT ######
+##################################################################
+
+# Note: These targets are also from within Makefiles in the Example directories.
+# There is a common makefile, 'Examples/javascript/js_example.mk' to simplify
+# create a configuration for a new example.
+
+ROOT_DIR = @ROOT_DIR@
+JSINCLUDES = @JSCOREINC@ @JSV8INC@
+JSDYNAMICLINKING = @JSCOREDYNAMICLINKING@ @JSV8DYNAMICLINKING@
+JSSO =@JSSO@
+JSLDSHARED = @JSLDSHARED@
+JSCXXSHARED = @JSCXXSHARED@
+NODEJS = @NODEJS@
+NODEGYP = @NODEGYP@
+
+# ----------------------------------------------------------------
+# Creating and building Javascript wrappers
+# ----------------------------------------------------------------
+
+javascript_wrapper:
+ $(SWIG) -javascript $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.c $(INTERFACEPATH)
+
+javascript_wrapper_cpp: $(SRCS)
+ $(SWIG) -javascript -c++ $(SWIGOPT) -o $(INTERFACEDIR)$(TARGET)_wrap.cxx $(INTERFACEPATH)
+
+javascript_build: $(SRCS)
+ $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) $(JSINCLUDES)
+ $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
+
+javascript_build_cpp: $(SRCS)
+ifeq (node,$(JSENGINE))
+ $(NODEGYP) --loglevel=silent configure build 1>>/dev/null
+else
+ $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(JSINCLUDES)
+ $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
+
+endif
+
+# These targets are used by the test-suite:
+
+javascript: $(SRCS) javascript_custom_interpreter
+ $(SWIG) -javascript $(SWIGOPT) $(INTERFACEPATH)
+ifeq (jsc, $(ENGINE))
+ $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDES) $(JSINCLUDES)
+ $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
+else # (v8 | node) # v8 and node must be compiled as c++
+ $(CXX) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(JSINCLUDES)
+ $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
+endif
+
+javascript_cpp: $(SRCS) javascript_custom_interpreter
+ $(SWIG) -javascript -c++ $(SWIGOPT) $(INTERFACEPATH)
+ $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) $(JSINCLUDES)
+ $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(JSDYNAMICLINKING) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
+
+# -----------------------------------------------------------------
+# Running a Javascript example
+# -----------------------------------------------------------------
+
+javascript_custom_interpreter:
+ (cd $(ROOT_DIR)/Tools/javascript && $(MAKE) JSENGINE='$(JSENGINE)')
+
+ifeq (node,$(JSENGINE))
+javascript_run:
+ $(RUNTOOL) $(NODEJS) $(RUNME).js $(RUNPIPE)
+else
+javascript_run: javascript_custom_interpreter
+ $(RUNTOOL) $(ROOT_DIR)/Tools/javascript/javascript -$(JSENGINE) -L $(TARGET) $(RUNME).js $(RUNPIPE)
+endif
+
+# -----------------------------------------------------------------
+# Version display
+# -----------------------------------------------------------------
+
+javascript_version:
+ifeq (, $(ENGINE))
+ @if [ "$(NODEJS)" != "" ]; then \
+ echo "Node.js: `($(NODEJS) --version)`"; \
+ echo "node-gyp: `($(NODEGYP) --version)`"; \
+ else \
+ echo "Version depends on the interpreter"; \
+ fi
+endif
+ifeq (node, $(ENGINE))
+ echo "Node.js: `($(NODEJS) --version)`"
+ echo "node-gyp: `($(NODEGYP) --version)`"
+endif
+ifeq (jsc, $(ENGINE))
+ @if [ "@JSCOREVERSION@" != "" ]; then \
+ echo "@JSCOREVERSION@"; \
+ else \
+ echo "Unknown JavascriptCore version."; \
+ fi
+endif
+ifeq (v8, $(ENGINE))
+ echo "Unknown v8 version."
+endif
+
+# -----------------------------------------------------------------
+# Cleaning the Javascript examples
+# -----------------------------------------------------------------
+
+javascript_clean:
+ rm -rf build
+ rm -f *_wrap* $(RUNME)
+ rm -f core @EXTRA_CLEAN@
+ rm -f *.@OBJEXT@ *@JSSO@ *.$(SO)
+ (cd $(ROOT_DIR)/Tools/javascript && $(MAKE) -s clean)
+
+##################################################################
##### ANDROID ######
##################################################################
diff --git a/Examples/android/class/Makefile b/Examples/android/class/Makefile
index 6155d9494..cef405ece 100644
--- a/Examples/android/class/Makefile
+++ b/Examples/android/class/Makefile
@@ -5,7 +5,7 @@ INTERFACE = example.i
INTERFACEDIR = jni/
PACKAGEDIR = src/org/swig
PACKAGENAME= org.swig.classexample
-SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/classexample
+SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/classexample
PROJECTNAME= SwigClass
TARGETID = 1
#INSTALLOPTIONS = -s # To install on SD Card
diff --git a/Examples/android/extend/Makefile b/Examples/android/extend/Makefile
index ec53013af..9b796494a 100644
--- a/Examples/android/extend/Makefile
+++ b/Examples/android/extend/Makefile
@@ -5,7 +5,7 @@ INTERFACE = example.i
INTERFACEDIR = jni/
PACKAGEDIR = src/org/swig
PACKAGENAME= org.swig.extendexample
-SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/extendexample
+SWIGOPT = -package $(PACKAGENAME) -outdir $(PACKAGEDIR)/extendexample
PROJECTNAME= SwigExtend
TARGETID = 1
#INSTALLOPTIONS = -s # To install on SD Card
diff --git a/Examples/chicken/class/Makefile b/Examples/chicken/class/Makefile
index 1436d836f..cd445c867 100644
--- a/Examples/chicken/class/Makefile
+++ b/Examples/chicken/class/Makefile
@@ -1,12 +1,12 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
INTERFACE = example.i
-SRCS =
+SRCS =
CXXSRCS = example.cxx
TARGET = class
INCLUDE =
SWIGOPT =
-CFLAGS =
+CFLAGS =
VARIANT =
# uncomment the following lines to build a static exe (only pick one of the CHICKEN_MAIN lines)
diff --git a/Examples/chicken/constants/Makefile b/Examples/chicken/constants/Makefile
index 31e39d346..fe396733e 100644
--- a/Examples/chicken/constants/Makefile
+++ b/Examples/chicken/constants/Makefile
@@ -2,12 +2,12 @@ TOP = ../..
SWIG = $(TOP)/../preinst-swig
INTERFACE = example.i
SRCS =
-CXXSRCS =
+CXXSRCS =
TARGET = constants
INCLUDE =
-SWIGOPT =
-CFLAGS =
-VARIANT =
+SWIGOPT =
+CFLAGS =
+VARIANT =
# uncomment the following two lines to build a static exe
#CHICKEN_MAIN = runme.scm
diff --git a/Examples/chicken/multimap/Makefile b/Examples/chicken/multimap/Makefile
index eba36169d..d92cfede0 100644
--- a/Examples/chicken/multimap/Makefile
+++ b/Examples/chicken/multimap/Makefile
@@ -2,12 +2,12 @@ TOP = ../..
SWIG = $(TOP)/../preinst-swig
INTERFACE = example.i
SRCS = example.c
-CXXSRCS =
+CXXSRCS =
TARGET = multimap
INCLUDE =
-SWIGOPT =
-CFLAGS =
-VARIANT =
+SWIGOPT =
+CFLAGS =
+VARIANT =
# uncomment the following two lines to build a static exe
#CHICKEN_MAIN = runme.scm
diff --git a/Examples/chicken/overload/Makefile b/Examples/chicken/overload/Makefile
index e15352ec5..fb190e882 100644
--- a/Examples/chicken/overload/Makefile
+++ b/Examples/chicken/overload/Makefile
@@ -1,13 +1,13 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
INTERFACE = example.i
-SRCS =
+SRCS =
CXXSRCS = example.cxx
TARGET = overload
INCLUDE =
SWIGOPT = -proxy -unhideprimitive
-CFLAGS =
-VARIANT =
+CFLAGS =
+VARIANT =
# uncomment the following lines to build a static exe
#CHICKEN_MAIN = runme.scm
diff --git a/Examples/chicken/simple/Makefile b/Examples/chicken/simple/Makefile
index f8fb006a4..d0d737484 100644
--- a/Examples/chicken/simple/Makefile
+++ b/Examples/chicken/simple/Makefile
@@ -2,12 +2,12 @@ TOP = ../..
SWIG = $(TOP)/../preinst-swig
INTERFACE = example.i
SRCS = example.c
-CXXSRCS =
+CXXSRCS =
TARGET = simple
INCLUDE =
-SWIGOPT =
-CFLAGS =
-VARIANT =
+SWIGOPT =
+CFLAGS =
+VARIANT =
# uncomment the following two lines to build a static exe
#CHICKEN_MAIN = runme.scm
diff --git a/Examples/go/constants/Makefile b/Examples/go/constants/Makefile
index c232e9ed1..9fa967366 100644
--- a/Examples/go/constants/Makefile
+++ b/Examples/go/constants/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
SWIGOPT =
diff --git a/Examples/go/template/Makefile b/Examples/go/template/Makefile
index 6796348a9..51cd97a80 100644
--- a/Examples/go/template/Makefile
+++ b/Examples/go/template/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
SWIGOPT =
diff --git a/Examples/guile/constants/Makefile b/Examples/guile/constants/Makefile
index d8a3cfebd..2b6965e9e 100644
--- a/Examples/guile/constants/Makefile
+++ b/Examples/guile/constants/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = my-guile
INTERFACE = example.i
diff --git a/Examples/java/constants/Makefile b/Examples/java/constants/Makefile
index 97c5b673c..4e21fc4cd 100644
--- a/Examples/java/constants/Makefile
+++ b/Examples/java/constants/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
SWIGOPT =
diff --git a/Examples/java/native/Makefile b/Examples/java/native/Makefile
index 29d5a082a..e858cbe77 100644
--- a/Examples/java/native/Makefile
+++ b/Examples/java/native/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = example
INTERFACE = example.i
SWIGOPT =
diff --git a/Examples/java/template/Makefile b/Examples/java/template/Makefile
index 97c5b673c..4e21fc4cd 100644
--- a/Examples/java/template/Makefile
+++ b/Examples/java/template/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
SWIGOPT =
diff --git a/Examples/java/typemap/Makefile b/Examples/java/typemap/Makefile
index 29d5a082a..e858cbe77 100644
--- a/Examples/java/typemap/Makefile
+++ b/Examples/java/typemap/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = example
INTERFACE = example.i
SWIGOPT =
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 100755
index 000000000..31846faae
--- /dev/null
+++ b/Examples/javascript/class/Makefile
@@ -0,0 +1,3 @@
+SRCS = example.cxx
+
+include ../example.mk
diff --git a/Examples/javascript/class/binding.gyp b/Examples/javascript/class/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/class/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/class/example.cxx b/Examples/javascript/class/example.cxx
new file mode 100755
index 000000000..e23fa6f73
--- /dev/null
+++ b/Examples/javascript/class/example.cxx
@@ -0,0 +1,28 @@
+/* File : example.c */
+#include <iostream>
+#include "example.h"
+#define M_PI 3.14159265358979323846
+
+/* Move the shape to a new location */
+void Shape::move(double dx, double dy) {
+ x += dx;
+ y += dy;
+}
+
+int Shape::nshapes = 0;
+
+double Circle::area(void) {
+ return M_PI*radius*radius;
+}
+
+double Circle::perimeter(void) {
+ return 2*M_PI*radius;
+}
+
+double Square::area(void) {
+ return width*width;
+}
+
+double Square::perimeter(void) {
+ return 4*width;
+}
diff --git a/Examples/javascript/class/example.h b/Examples/javascript/class/example.h
new file mode 100755
index 000000000..64b7684fa
--- /dev/null
+++ b/Examples/javascript/class/example.h
@@ -0,0 +1,34 @@
+/* File : example.h */
+
+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);
+};
diff --git a/Examples/javascript/class/example.i b/Examples/javascript/class/example.i
new file mode 100755
index 000000000..75700b305
--- /dev/null
+++ b/Examples/javascript/class/example.i
@@ -0,0 +1,10 @@
+/* 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/class/example.js b/Examples/javascript/class/example.js
new file mode 100644
index 000000000..79cd3913f
--- /dev/null
+++ b/Examples/javascript/class/example.js
@@ -0,0 +1 @@
+module.exports = require("./build/Release/example");
diff --git a/Examples/javascript/class/runme.js b/Examples/javascript/class/runme.js
new file mode 100755
index 000000000..e1d5d9797
--- /dev/null
+++ b/Examples/javascript/class/runme.js
@@ -0,0 +1,46 @@
+var example = require("./example");
+
+// ----- Object creation -----
+
+console.log("Creating some objects:");
+c = new example.Circle(10);
+console.log("Created circle " + c);
+s = new example.Square(10);
+console.log("Created square " + s);
+
+// ----- Access a static member -----
+console.log("\nA total of " + example.Shape.nshapes + " shapes were created"); // access static member as properties of the class object
+
+// ----- Member data access -----
+// Set the location of the object.
+// Note: methods in the base class Shape are used since
+// x and y are defined there.
+
+c.x = 20;
+c.y = 30;
+s.x = -10;
+s.y = 5;
+
+console.log("\nHere is their new position:");
+console.log("Circle = (" + c.x + "," + c.y + ")");
+console.log("Square = (" + s.x + "," + s.y + ")");
+
+// ----- Call some methods -----
+console.log("\nHere are some properties of the shapes:");
+console.log("Circle:");
+console.log("area = " + c.area() + "");
+console.log("perimeter = " + c.perimeter() + "");
+console.log("\n");
+console.log("Square:");
+console.log("area = " + s.area() + "");
+console.log("perimeter = " + s.perimeter() + "");
+
+// ----- Delete everything -----
+console.log("\nGuess I'll clean up now");
+// Note: this invokes the virtual destructor
+delete c;
+delete s;
+
+console.log(example.Shape.nshapes + " shapes remain");
+
+console.log("Goodbye");
diff --git a/Examples/javascript/constant/Makefile b/Examples/javascript/constant/Makefile
new file mode 100755
index 000000000..ea04c7df8
--- /dev/null
+++ b/Examples/javascript/constant/Makefile
@@ -0,0 +1,3 @@
+SRCS =
+
+include ../example.mk
diff --git a/Examples/javascript/constant/binding.gyp b/Examples/javascript/constant/binding.gyp
new file mode 100644
index 000000000..69af46b22
--- /dev/null
+++ b/Examples/javascript/constant/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/constant/example.h b/Examples/javascript/constant/example.h
new file mode 100644
index 000000000..2c88ebd1e
--- /dev/null
+++ b/Examples/javascript/constant/example.h
@@ -0,0 +1,8 @@
+#define ICONST 42
+#define FCONST 2.1828
+#define CCONST 'x'
+#define CCONST2 '\n'
+#define SCONST "Hello World"
+#define SCONST2 "\"Hello World\""
+#define EXTERN extern
+#define FOO (ICONST + BAR)
diff --git a/Examples/javascript/constant/example.i b/Examples/javascript/constant/example.i
new file mode 100755
index 000000000..a6d28e7c9
--- /dev/null
+++ b/Examples/javascript/constant/example.i
@@ -0,0 +1,24 @@
+/* File : example.i */
+%module example
+
+/* A few preprocessor macros */
+
+#define ICONST 42
+#define FCONST 2.1828
+#define CCONST 'x'
+#define CCONST2 '\n'
+#define SCONST "Hello World"
+#define SCONST2 "\"Hello World\""
+
+/* This should work just fine */
+#define EXPR ICONST + 3*(FCONST)
+
+/* This shouldn't do anything */
+#define EXTERN extern
+
+/* Neither should this (BAR isn't defined) */
+#define FOO (ICONST + BAR)
+
+/* The following directives also produce constants */
+%constant int iconst = 37;
+%constant double fconst = 3.14;
diff --git a/Examples/javascript/constant/example.js b/Examples/javascript/constant/example.js
new file mode 100644
index 000000000..79cd3913f
--- /dev/null
+++ b/Examples/javascript/constant/example.js
@@ -0,0 +1 @@
+module.exports = require("./build/Release/example");
diff --git a/Examples/javascript/constant/runme.js b/Examples/javascript/constant/runme.js
new file mode 100755
index 000000000..f4b55881e
--- /dev/null
+++ b/Examples/javascript/constant/runme.js
@@ -0,0 +1,14 @@
+var example = require("./example");
+
+console.log("ICONST = " + example.ICONST + " (should be 42)");
+console.log("FCONST = " + example.FCONST + " (should be 2.1828)");
+console.log("CCONST = " + example.CCONST + " (should be 'x')");
+console.log("CCONST2 = " + example.CCONST2 + " (this should be on a new line)");
+console.log("SCONST = " + example.SCONST + " (should be 'Hello World')");
+console.log("SCONST2 = " + example.SCONST2 + " (should be '\"Hello World\"')");
+console.log("EXPR = " + example.EXPR + " (should be 48.5484)");
+console.log("iconst = " + example.iconst + " (should be 37)");
+console.log("fconst = " + example.fconst + " (should be 3.14)");
+
+console.log("EXTERN = " + example.EXTERN + " (should be undefined)");
+console.log("FOO = " + example.FOO + " (should be undefined)");
diff --git a/Examples/javascript/enum/Makefile b/Examples/javascript/enum/Makefile
new file mode 100755
index 000000000..31846faae
--- /dev/null
+++ b/Examples/javascript/enum/Makefile
@@ -0,0 +1,3 @@
+SRCS = example.cxx
+
+include ../example.mk
diff --git a/Examples/javascript/enum/binding.gyp b/Examples/javascript/enum/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/enum/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/enum/example.cxx b/Examples/javascript/enum/example.cxx
new file mode 100755
index 000000000..6785e57ac
--- /dev/null
+++ b/Examples/javascript/enum/example.cxx
@@ -0,0 +1,37 @@
+/* File : example.c */
+
+#include "example.h"
+#include <stdio.h>
+
+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 100755
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 100755
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..79cd3913f
--- /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 100755
index 000000000..d4e89e8c8
--- /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..274eff1a3
--- /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 JSENGINE='$(JSENGINE)' TARGET='$(TARGET)' javascript_run
+
+build:
+ $(MAKE) -f $(EXAMPLES_TOP)/Makefile CXXSRCS='$(SRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
+ $(MAKE) -f $(EXAMPLES_TOP)/Makefile CXXSRCS='$(SRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' JSENGINE='$(JSENGINE)' javascript_build_cpp
+
+clean:
+ $(MAKE) -f $(EXAMPLES_TOP)/Makefile javascript_clean
diff --git a/Examples/javascript/exception/Makefile b/Examples/javascript/exception/Makefile
new file mode 100755
index 000000000..31846faae
--- /dev/null
+++ b/Examples/javascript/exception/Makefile
@@ -0,0 +1,3 @@
+SRCS = example.cxx
+
+include ../example.mk
diff --git a/Examples/javascript/exception/binding.gyp b/Examples/javascript/exception/binding.gyp
new file mode 100644
index 000000000..2be0a17a2
--- /dev/null
+++ b/Examples/javascript/exception/binding.gyp
@@ -0,0 +1,29 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ],
+ 'defines': [
+ 'BUILDING_NODE_EXTENSION=1',
+ ],
+ 'conditions': [
+ ['OS=="mac"',
+ {
+ 'xcode_settings': {
+ 'GCC_ENABLE_CPP_RTTI': 'YES',
+ 'GCC_ENABLE_CPP_EXCEPTIONS' : 'YES'
+ }
+ }
+ ],
+ ['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"',
+ {
+ 'cflags': [ "-Wno-unused-variable", "-Wno-unused-but-set-variable", "-Wno-unused-but-set-parameter"],
+ 'cflags_cc': [ "-Wno-unused-variable", "-Wno-unused-but-set-variable", "-Wno-unused-but-set-parameter"],
+ 'cflags!': [ '-fno-exceptions' ],
+ 'cflags_cc!': [ '-fno-exceptions', '-fno-rtti' ]
+ }
+ ]
+ ]
+ }
+ ]
+}
diff --git a/Examples/javascript/exception/example.cxx b/Examples/javascript/exception/example.cxx
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/Examples/javascript/exception/example.cxx
@@ -0,0 +1 @@
+
diff --git a/Examples/javascript/exception/example.h b/Examples/javascript/exception/example.h
new file mode 100644
index 000000000..7cf917d01
--- /dev/null
+++ b/Examples/javascript/exception/example.h
@@ -0,0 +1,53 @@
+/* File : example.h */
+
+#include <string.h>
+#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..79cd3913f
--- /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..977f51ebc
--- /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 100755
index 000000000..31846faae
--- /dev/null
+++ b/Examples/javascript/functor/Makefile
@@ -0,0 +1,3 @@
+SRCS = example.cxx
+
+include ../example.mk
diff --git a/Examples/javascript/functor/binding.gyp b/Examples/javascript/functor/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/functor/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/functor/example.cxx b/Examples/javascript/functor/example.cxx
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/Examples/javascript/functor/example.cxx
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
+template<class T> class 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<int>;
+%template(doubleSum) Sum<double>;
+
+
+
+
diff --git a/Examples/javascript/functor/example.js b/Examples/javascript/functor/example.js
new file mode 100644
index 000000000..79cd3913f
--- /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..dc12470f4
--- /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 100755
index 000000000..ea04c7df8
--- /dev/null
+++ b/Examples/javascript/nspace/Makefile
@@ -0,0 +1,3 @@
+SRCS =
+
+include ../example.mk
diff --git a/Examples/javascript/nspace/binding.gyp b/Examples/javascript/nspace/binding.gyp
new file mode 100644
index 000000000..69af46b22
--- /dev/null
+++ b/Examples/javascript/nspace/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example_wrap.cxx" ]
+ }
+ ]
+}
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..79cd3913f
--- /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..d6a49d8d4
--- /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 100755
index 000000000..ea04c7df8
--- /dev/null
+++ b/Examples/javascript/operator/Makefile
@@ -0,0 +1,3 @@
+SRCS =
+
+include ../example.mk
diff --git a/Examples/javascript/operator/binding.gyp b/Examples/javascript/operator/binding.gyp
new file mode 100644
index 000000000..69af46b22
--- /dev/null
+++ b/Examples/javascript/operator/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example_wrap.cxx" ]
+ }
+ ]
+}
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 <math.h>
+
+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..79cd3913f
--- /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..a700918d6
--- /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 100755
index 000000000..ea04c7df8
--- /dev/null
+++ b/Examples/javascript/overload/Makefile
@@ -0,0 +1,3 @@
+SRCS =
+
+include ../example.mk
diff --git a/Examples/javascript/overload/binding.gyp b/Examples/javascript/overload/binding.gyp
new file mode 100644
index 000000000..69af46b22
--- /dev/null
+++ b/Examples/javascript/overload/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example_wrap.cxx" ]
+ }
+ ]
+}
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 <iostream>
+
+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..79cd3913f
--- /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..1e6c861a6
--- /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 100755
index 000000000..31846faae
--- /dev/null
+++ b/Examples/javascript/pointer/Makefile
@@ -0,0 +1,3 @@
+SRCS = example.cxx
+
+include ../example.mk
diff --git a/Examples/javascript/pointer/binding.gyp b/Examples/javascript/pointer/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/pointer/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/pointer/example.cxx b/Examples/javascript/pointer/example.cxx
new file mode 100755
index 000000000..8762329fe
--- /dev/null
+++ b/Examples/javascript/pointer/example.cxx
@@ -0,0 +1,16 @@
+/* File : example.c */
+
+void add(int *x, int *y, int *result) {
+ *result = *x + *y;
+}
+
+void subtract(int *x, int *y, int *result) {
+ *result = *x - *y;
+}
+
+int divide(int n, int d, int *r) {
+ int q;
+ q = n/d;
+ *r = n - q*d;
+ return q;
+}
diff --git a/Examples/javascript/pointer/example.i b/Examples/javascript/pointer/example.i
new file mode 100755
index 000000000..38c67d7d2
--- /dev/null
+++ b/Examples/javascript/pointer/example.i
@@ -0,0 +1,30 @@
+/* File : example.i */
+%module example
+
+%{
+extern void add(int *, int *, int *);
+extern void subtract(int *, int *, int *);
+extern int divide(int, int, int *);
+%}
+
+/* This example illustrates a couple of different techniques
+ for manipulating C pointers */
+
+/* First we'll use the pointer library */
+extern void add(int *x, int *y, int *result);
+%include cpointer.i
+%pointer_functions(int, intp);
+
+/* Next we'll use some typemaps */
+
+%include typemaps.i
+extern void subtract(int *INPUT, int *INPUT, int *OUTPUT);
+
+/* Next we'll use typemaps and the %apply directive */
+
+%apply int *OUTPUT { int *r };
+extern int divide(int n, int d, int *r);
+
+
+
+
diff --git a/Examples/javascript/pointer/example.js b/Examples/javascript/pointer/example.js
new file mode 100644
index 000000000..79cd3913f
--- /dev/null
+++ b/Examples/javascript/pointer/example.js
@@ -0,0 +1 @@
+module.exports = require("./build/Release/example");
diff --git a/Examples/javascript/pointer/runme.js b/Examples/javascript/pointer/runme.js
new file mode 100755
index 000000000..fb8cf0c74
--- /dev/null
+++ b/Examples/javascript/pointer/runme.js
@@ -0,0 +1,35 @@
+var example = require("./example");
+
+// First create some objects using the pointer library.
+console.log("Testing the pointer library");
+a = example.new_intp();
+b = example.new_intp();
+c = example.new_intp();
+
+example.intp_assign(a,37);
+example.intp_assign(b,42);
+
+console.log(" a = " + example.intp_value(a));
+console.log(" b = " + example.intp_value(b));
+console.log(" c = " + example.intp_value(c));
+
+//// Call the add() function with some pointers
+example.add(a, b, c);
+
+//
+//// Now get the result
+r = example.intp_value(c);
+console.log(" 37 + 42 = " + r);
+
+// Clean up the pointers
+example.delete_intp(a);
+example.delete_intp(b);
+example.delete_intp(c);
+
+//// Now try the typemap library
+//// This should be much easier. Now how it is no longer
+//// necessary to manufacture pointers.
+//"OUTPUT" Mapping is not supported
+//console.log("Trying the typemap library");
+//r = example.subtract(37,42);
+//console.log("37 - 42 =" + r);
diff --git a/Examples/javascript/pointer/typemaps.i b/Examples/javascript/pointer/typemaps.i
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/Examples/javascript/pointer/typemaps.i
diff --git a/Examples/javascript/reference/Makefile b/Examples/javascript/reference/Makefile
new file mode 100755
index 000000000..31846faae
--- /dev/null
+++ b/Examples/javascript/reference/Makefile
@@ -0,0 +1,3 @@
+SRCS = example.cxx
+
+include ../example.mk
diff --git a/Examples/javascript/reference/binding.gyp b/Examples/javascript/reference/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/reference/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/reference/example.cxx b/Examples/javascript/reference/example.cxx
new file mode 100755
index 000000000..8a513bf49
--- /dev/null
+++ b/Examples/javascript/reference/example.cxx
@@ -0,0 +1,46 @@
+/* File : example.cxx */
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+#include "example.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+Vector operator+(const Vector &a, const Vector &b) {
+ Vector r;
+ r.x = a.x + b.x;
+ r.y = a.y + b.y;
+ r.z = a.z + b.z;
+ return r;
+}
+
+char *Vector::print() {
+ static char temp[512];
+ sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z);
+ return temp;
+}
+
+VectorArray::VectorArray(int size) {
+ items = new Vector[size];
+ maxsize = size;
+}
+
+VectorArray::~VectorArray() {
+ delete [] items;
+}
+
+Vector &VectorArray::operator[](int index) {
+ if ((index < 0) || (index >= maxsize)) {
+ printf("Panic! Array index out of bounds.\n");
+ exit(1);
+ }
+ return items[index];
+}
+
+int VectorArray::size() {
+ return maxsize;
+}
+
diff --git a/Examples/javascript/reference/example.h b/Examples/javascript/reference/example.h
new file mode 100755
index 000000000..4915adb1b
--- /dev/null
+++ b/Examples/javascript/reference/example.h
@@ -0,0 +1,26 @@
+/* File : example.h */
+
+class Vector {
+private:
+ double x,y,z;
+public:
+ Vector() : x(0), y(0), z(0) { };
+ Vector(double x, double y, double z) : x(x), y(y), z(z) { };
+ friend Vector operator+(const Vector &a, const Vector &b);
+ char *print();
+};
+
+class VectorArray {
+private:
+ Vector *items;
+ int maxsize;
+public:
+ VectorArray(int maxsize);
+ ~VectorArray();
+ Vector &operator[](int);
+ int size();
+};
+
+
+
+
diff --git a/Examples/javascript/reference/example.i b/Examples/javascript/reference/example.i
new file mode 100755
index 000000000..1cf19c82c
--- /dev/null
+++ b/Examples/javascript/reference/example.i
@@ -0,0 +1,42 @@
+/* File : example.i */
+
+/* This file has a few "typical" uses of C++ references. */
+
+%module example
+
+%{
+#include "example.h"
+%}
+
+class Vector {
+public:
+ Vector(double x, double y, double z);
+ ~Vector();
+ char *print();
+};
+
+/* This helper function calls an overloaded operator */
+%inline %{
+Vector addv(Vector &a, Vector &b) {
+ return a+b;
+}
+%}
+
+/* Wrapper around an array of vectors class */
+
+class VectorArray {
+public:
+ VectorArray(int maxsize);
+ ~VectorArray();
+ int size();
+
+ /* This wrapper provides an alternative to the [] operator */
+ %extend {
+ Vector &get(int index) {
+ return (*$self)[index];
+ }
+ void set(int index, Vector &a) {
+ (*$self)[index] = a;
+ }
+ }
+};
diff --git a/Examples/javascript/reference/example.js b/Examples/javascript/reference/example.js
new file mode 100644
index 000000000..79cd3913f
--- /dev/null
+++ b/Examples/javascript/reference/example.js
@@ -0,0 +1 @@
+module.exports = require("./build/Release/example");
diff --git a/Examples/javascript/reference/runme.js b/Examples/javascript/reference/runme.js
new file mode 100755
index 000000000..88c108314
--- /dev/null
+++ b/Examples/javascript/reference/runme.js
@@ -0,0 +1,67 @@
+// This file illustrates the manipulation of C++ references in Javascript.
+var example = require("./example");
+
+// ----- Object creation -----
+
+console.log("Creating some objects:");
+a = new example.Vector(3,4,5);
+b = new example.Vector(10,11,12);
+
+console.log(" created" + a.print());
+console.log(" created" + b.print());
+
+// ----- Call an overloaded operator -----
+
+// This calls the wrapper we placed around operator+(const Vector &a, const Vector &)
+// It returns a new allocated object.
+
+console.log("Adding a+b");
+c = example.addv(a, b);
+console.log("a+b = " + c.print());
+
+
+// TODO: Note: Unless we free the result, a memory leak will occur
+//delete_Vector(c);
+
+// ----- Create a vector array -----
+
+// Note: Using the high-level interface here
+console.log("Creating an array of vectors");
+va = new example.VectorArray(10);
+console.log("va = " + va);
+
+// ----- Set some values in the array -----
+
+// These operators copy the value of a and b to the vector array
+va.set(0,a);
+va.set(1,b);
+
+// This will work, but it will cause a memory leak!
+va.set(2,example.addv(a,b));
+
+// The non-leaky way to do it
+//c = addv(a,b);
+//va.set(3,c);
+//delete_Vector(c);
+
+// Get some values from the array
+
+console.log("Getting some array values");
+for (i = 0; i < 5; i++) {
+ temp = va.get(i);
+ console.log(i,temp.print());
+}
+
+// Watch under resource meter to check on this
+console.log("Making sure we don't leak memory.");
+for (i = 0; i < 1000000; i++) {
+ c = va.get(i % 10);
+}
+//---------TODO---------
+//----- Clean up -----
+//console.log("Cleaning up");
+
+//example.delete_VectorArray(va);
+//example.delete_Vector(a);
+//example.delete_Vector(b);
+
diff --git a/Examples/javascript/simple/Makefile b/Examples/javascript/simple/Makefile
new file mode 100755
index 000000000..31846faae
--- /dev/null
+++ b/Examples/javascript/simple/Makefile
@@ -0,0 +1,3 @@
+SRCS = example.cxx
+
+include ../example.mk
diff --git a/Examples/javascript/simple/binding.gyp b/Examples/javascript/simple/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/simple/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/simple/example.cxx b/Examples/javascript/simple/example.cxx
new file mode 100644
index 000000000..1c2af789c
--- /dev/null
+++ b/Examples/javascript/simple/example.cxx
@@ -0,0 +1,18 @@
+/* File : example.c */
+
+/* A global variable */
+double Foo = 3.0;
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x > 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..79cd3913f
--- /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 100755
index 000000000..be2c18669
--- /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 100755
index 000000000..ea04c7df8
--- /dev/null
+++ b/Examples/javascript/template/Makefile
@@ -0,0 +1,3 @@
+SRCS =
+
+include ../example.mk
diff --git a/Examples/javascript/template/binding.gyp b/Examples/javascript/template/binding.gyp
new file mode 100644
index 000000000..69af46b22
--- /dev/null
+++ b/Examples/javascript/template/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example_wrap.cxx" ]
+ }
+ ]
+}
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<class T> T max(T a, T b) { return a>b ? a : b; }
+
+template<class T> 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<int>;
+%template(maxdouble) max<double>;
+%template(vecint) vector<int>;
+%template(vecdouble) vector<double>;
+
diff --git a/Examples/javascript/template/example.js b/Examples/javascript/template/example.js
new file mode 100644
index 000000000..79cd3913f
--- /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..55894dfd5
--- /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 100755
index 000000000..31846faae
--- /dev/null
+++ b/Examples/javascript/variables/Makefile
@@ -0,0 +1,3 @@
+SRCS = example.cxx
+
+include ../example.mk
diff --git a/Examples/javascript/variables/binding.gyp b/Examples/javascript/variables/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/variables/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/variables/example.cxx b/Examples/javascript/variables/example.cxx
new file mode 100755
index 000000000..f10390a9e
--- /dev/null
+++ b/Examples/javascript/variables/example.cxx
@@ -0,0 +1,96 @@
+/* File : example.c */
+
+/* I'm a file containing some C global variables */
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#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", iptrvar);
+ printf("name = %s\n", name);
+ printf("ptptr = %p (%d, %d)\n", 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 100755
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 100755
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..79cd3913f
--- /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 100755
index 000000000..537e17296
--- /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/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/constants/Makefile b/Examples/lua/constants/Makefile
index 51b83be2e..7e36e15a1 100644
--- a/Examples/lua/constants/Makefile
+++ b/Examples/lua/constants/Makefile
@@ -1,9 +1,9 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
-LIBS =
+LIBS =
check: build
$(MAKE) -f $(TOP)/Makefile lua_run
diff --git a/Examples/lua/dual/dual.cpp b/Examples/lua/dual/dual.cpp
index ad7897953..b54e44de1 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 <stdio.h>
#include <stdlib.h>
-// 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);
diff --git a/Examples/lua/embed/embed.c b/Examples/lua/embed/embed.c
index f21c933a5..507567489 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.
@@ -28,8 +28,8 @@ 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) {
@@ -58,11 +58,11 @@ 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");
+ printf("[C] let's load the file 'runme.lua'\n");
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));
@@ -70,16 +70,16 @@ int main(int argc,char* argv[]) {
}
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/embed2.c b/Examples/lua/embed2/embed2.c
index 3145d3b10..100a1fb33 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.
@@ -35,12 +35,12 @@ We will be using the luaL_dostring()/lua_dostring() function to call into lua
#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) {
@@ -78,7 +78,7 @@ int call_add(lua_State *L,int a,int b,int* res) {
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, ...) {
@@ -189,7 +189,7 @@ 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");
+ printf("[C] let's load the file 'runme.lua'\n");
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));
@@ -197,12 +197,12 @@ int main(int argc,char* argv[]) {
}
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/embed3.cpp b/Examples/lua/embed3/embed3.cpp
index cdf56268d..d559167d1 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.
@@ -33,12 +33,12 @@ extern "C" {
/* The SWIG external runtime is generated by using.
swig -lua -externalruntime swigluarun.h
-It contains useful function used by SWIG in its wrappering
+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
@@ -100,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
@@ -113,7 +113,7 @@ 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");
+ printf("[C++] now let's load the file 'runme.lua'\n");
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));
@@ -122,7 +122,7 @@ int main(int argc, char* argv[]) {
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..3dbebb4e5 100644
--- a/Examples/lua/exception/Makefile
+++ b/Examples/lua/exception/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
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..8b51e73e8 100644
--- a/Examples/lua/funcptr3/Makefile
+++ b/Examples/lua/funcptr3/Makefile
@@ -3,7 +3,7 @@ SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
-LIBS =
+LIBS =
check: build
$(MAKE) -f $(TOP)/Makefile lua_run
diff --git a/Examples/lua/functest/Makefile b/Examples/lua/functest/Makefile
index 00bfe7992..8b51e73e8 100644
--- a/Examples/lua/functest/Makefile
+++ b/Examples/lua/functest/Makefile
@@ -3,7 +3,7 @@ SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
-LIBS =
+LIBS =
check: build
$(MAKE) -f $(TOP)/Makefile lua_run
diff --git a/Examples/lua/functor/Makefile b/Examples/lua/functor/Makefile
index 9220dfe51..4e4edbfa5 100644
--- a/Examples/lua/functor/Makefile
+++ b/Examples/lua/functor/Makefile
@@ -1,10 +1,10 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile lua_run
diff --git a/Examples/lua/import/Makefile b/Examples/lua/import/Makefile
index 0bf47c1a5..0a9aebd57 100644
--- a/Examples/lua/import/Makefile
+++ b/Examples/lua/import/Makefile
@@ -2,7 +2,7 @@ TOP = ../..
SWIG = $(TOP)/../preinst-swig
SWIGOPT =
LIBS =
-
+
check: build
$(MAKE) -f $(TOP)/Makefile lua_run
diff --git a/Examples/lua/nspace/Makefile b/Examples/lua/nspace/Makefile
index 72129b1d6..57875ec49 100644
--- a/Examples/lua/nspace/Makefile
+++ b/Examples/lua/nspace/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
diff --git a/Examples/lua/owner/runme.lua b/Examples/lua/owner/runme.lua
index ed745f7b2..847645448 100644
--- a/Examples/lua/owner/runme.lua
+++ b/Examples/lua/owner/runme.lua
@@ -9,15 +9,15 @@ else
require('example')
end
-print "ok, lets test Lua's ownership of C++ objects"
+print "ok, let's test Lua's ownership of C++ objects"
print("Currently there are",example.Shape_nshapes,"shapes (there should be 0)")
-print "\nLets make a couple"
+print "\nLet's make a couple"
a=example.Square(10)
b=example.Circle(1)
print("Currently there are",example.Shape_nshapes,"shapes (there should be 2)")
-print "\nNote lets use the createX functions"
+print "\nNote let's use the createX functions"
c=example.createCircle(5)
d=example.createSquare(3)
print("Currently there are",example.Shape_nshapes,"shapes (there should be 4)")
@@ -26,12 +26,12 @@ print "\nWe will run the garbage collector & see if they are till here"
collectgarbage()
print("Currently there are",example.Shape_nshapes,"shapes (there should be 4)")
-print "\nLets get rid of them all, collect garbage & see if they are till here"
+print "\nLet's get rid of them all, collect garbage & see if they are till here"
a,b,c,d=nil,nil,nil,nil
collectgarbage()
print("Currently there are",example.Shape_nshapes,"shapes (there should be 0)")
-print "\nLets start putting stuff into the ShapeOwner"
+print "\nLet's start putting stuff into the ShapeOwner"
print "The ShapeOwner now owns the shapes, but Lua still has pointers to them"
o=example.ShapeOwner()
a=example.Square(10)
@@ -41,7 +41,7 @@ o:add(b)
o:add(example.createSquare(5))
print("Currently there are",example.Shape_nshapes,"shapes (there should be 3)")
-print "\nWe will nil our references,run the garbage collector & see if they are till here"
+print "\nWe will nil our references,run the garbage collector & see if they are still here"
print "they should be, as the ShapeOwner owns them"
a,b=nil,nil
collectgarbage()
@@ -101,4 +101,4 @@ print "done"
o,sh=nil,nil
collectgarbage()
print("Currently there are",example.Shape_nshapes,"shapes (there should be 0)")
-print "thats all folks!"
+print "that's all folks!"
diff --git a/Examples/lua/pointer/Makefile b/Examples/lua/pointer/Makefile
index 00bfe7992..8b51e73e8 100644
--- a/Examples/lua/pointer/Makefile
+++ b/Examples/lua/pointer/Makefile
@@ -3,7 +3,7 @@ SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
-LIBS =
+LIBS =
check: build
$(MAKE) -f $(TOP)/Makefile lua_run
diff --git a/Examples/modula3/class/Makefile b/Examples/modula3/class/Makefile
index 9976e6f80..af8e099cc 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
diff --git a/Examples/modula3/enum/Makefile b/Examples/modula3/enum/Makefile
index a3b499823..a351cb1b9 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
diff --git a/Examples/modula3/reference/Makefile b/Examples/modula3/reference/Makefile
index 62183931e..1a5fdeb30 100644
--- a/Examples/modula3/reference/Makefile
+++ b/Examples/modula3/reference/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = example
INTERFACE = example.i
SWIGOPT = -c++
diff --git a/Examples/modula3/simple/Makefile b/Examples/modula3/simple/Makefile
index 6a0ca4f0e..6287dac20 100644
--- a/Examples/modula3/simple/Makefile
+++ b/Examples/modula3/simple/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = example
INTERFACE = example.i
SWIGOPT =
diff --git a/Examples/modula3/typemap/Makefile b/Examples/modula3/typemap/Makefile
index 6a0ca4f0e..6287dac20 100644
--- a/Examples/modula3/typemap/Makefile
+++ b/Examples/modula3/typemap/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = example
INTERFACE = example.i
SWIGOPT =
diff --git a/Examples/mzscheme/multimap/Makefile b/Examples/mzscheme/multimap/Makefile
index d1b4a3f39..f8eeb72c3 100644
--- a/Examples/mzscheme/multimap/Makefile
+++ b/Examples/mzscheme/multimap/Makefile
@@ -3,7 +3,7 @@ SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile mzscheme_run
diff --git a/Examples/mzscheme/simple/Makefile b/Examples/mzscheme/simple/Makefile
index d1b4a3f39..f8eeb72c3 100644
--- a/Examples/mzscheme/simple/Makefile
+++ b/Examples/mzscheme/simple/Makefile
@@ -3,7 +3,7 @@ SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile mzscheme_run
diff --git a/Examples/mzscheme/std_vector/Makefile b/Examples/mzscheme/std_vector/Makefile
index 28b91158a..d2bf0a013 100644
--- a/Examples/mzscheme/std_vector/Makefile
+++ b/Examples/mzscheme/std_vector/Makefile
@@ -1,9 +1,9 @@
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
@@ -14,7 +14,7 @@ check: build
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
diff --git a/Examples/ocaml/contract/Makefile b/Examples/ocaml/contract/Makefile
index 91d39247e..1db93e38a 100644
--- a/Examples/ocaml/contract/Makefile
+++ b/Examples/ocaml/contract/Makefile
@@ -1,11 +1,11 @@
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
diff --git a/Examples/ocaml/scoped_enum/Makefile b/Examples/ocaml/scoped_enum/Makefile
index 4920e3b3b..e5de57ac2 100644
--- a/Examples/ocaml/scoped_enum/Makefile
+++ b/Examples/ocaml/scoped_enum/Makefile
@@ -1,11 +1,11 @@
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
diff --git a/Examples/ocaml/shapes/Makefile b/Examples/ocaml/shapes/Makefile
index 38230eb69..c1ab6507c 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
diff --git a/Examples/ocaml/std_string/Makefile b/Examples/ocaml/std_string/Makefile
index 0250cfd2d..89f997090 100644
--- a/Examples/ocaml/std_string/Makefile
+++ b/Examples/ocaml/std_string/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = example
INTERFACE = example.i
PROGFILE = runme.ml
diff --git a/Examples/ocaml/std_vector/Makefile b/Examples/ocaml/std_vector/Makefile
index 0250cfd2d..89f997090 100644
--- a/Examples/ocaml/std_vector/Makefile
+++ b/Examples/ocaml/std_vector/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = example
INTERFACE = example.i
PROGFILE = runme.ml
diff --git a/Examples/ocaml/stl/Makefile b/Examples/ocaml/stl/Makefile
index 545f3229a..a913611fb 100644
--- a/Examples/ocaml/stl/Makefile
+++ b/Examples/ocaml/stl/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = example
INTERFACE = example.i
PROGFILE = runme.ml
diff --git a/Examples/ocaml/string_from_ptr/Makefile b/Examples/ocaml/string_from_ptr/Makefile
index f7b808934..6d344854a 100644
--- a/Examples/ocaml/string_from_ptr/Makefile
+++ b/Examples/ocaml/string_from_ptr/Makefile
@@ -1,12 +1,12 @@
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
diff --git a/Examples/ocaml/strings_test/Makefile b/Examples/ocaml/strings_test/Makefile
index 14f55e0d9..49cc544ed 100644
--- a/Examples/ocaml/strings_test/Makefile
+++ b/Examples/ocaml/strings_test/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = example
INTERFACE = example.i
PROGFILE = runme.ml
diff --git a/Examples/perl5/funcptr/Makefile b/Examples/perl5/funcptr/Makefile
index c4d100020..366b5897c 100644
--- a/Examples/perl5/funcptr/Makefile
+++ b/Examples/perl5/funcptr/Makefile
@@ -3,7 +3,7 @@ SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile perl5_run
diff --git a/Examples/perl5/java/Makefile b/Examples/perl5/java/Makefile
index b007cfdbb..ff3aab0e7 100644
--- a/Examples/perl5/java/Makefile
+++ b/Examples/perl5/java/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
@@ -15,7 +15,7 @@ build: Example.class
clean:
$(MAKE) -f $(TOP)/Makefile perl5_clean
- rm -f *.class Example.h
+ rm -f *.class Example.h
Example.class: Example.java
gcj -fPIC -C -c -g Example.java
diff --git a/Examples/perl5/multimap/Makefile b/Examples/perl5/multimap/Makefile
index c4d100020..366b5897c 100644
--- a/Examples/perl5/multimap/Makefile
+++ b/Examples/perl5/multimap/Makefile
@@ -3,7 +3,7 @@ SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile perl5_run
diff --git a/Examples/perl5/multiple_inheritance/Makefile b/Examples/perl5/multiple_inheritance/Makefile
index 18c3058f9..62355a82c 100644
--- a/Examples/perl5/multiple_inheritance/Makefile
+++ b/Examples/perl5/multiple_inheritance/Makefile
@@ -1,9 +1,9 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
-LIBS =
+LIBS =
check: build
$(MAKE) -f $(TOP)/Makefile perl5_run
diff --git a/Examples/perl5/pointer/Makefile b/Examples/perl5/pointer/Makefile
index c4d100020..366b5897c 100644
--- a/Examples/perl5/pointer/Makefile
+++ b/Examples/perl5/pointer/Makefile
@@ -3,7 +3,7 @@ SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile perl5_run
diff --git a/Examples/perl5/reference/Makefile b/Examples/perl5/reference/Makefile
index d33dd89fe..986fab86a 100644
--- a/Examples/perl5/reference/Makefile
+++ b/Examples/perl5/reference/Makefile
@@ -4,7 +4,7 @@ CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT = -noproxy
+SWIGOPT = -noproxy
check: build
$(MAKE) -f $(TOP)/Makefile perl5_run
diff --git a/Examples/perl5/simple/Makefile b/Examples/perl5/simple/Makefile
index c4d100020..366b5897c 100644
--- a/Examples/perl5/simple/Makefile
+++ b/Examples/perl5/simple/Makefile
@@ -3,7 +3,7 @@ SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile perl5_run
diff --git a/Examples/perl5/value/Makefile b/Examples/perl5/value/Makefile
index c4d100020..366b5897c 100644
--- a/Examples/perl5/value/Makefile
+++ b/Examples/perl5/value/Makefile
@@ -3,7 +3,7 @@ SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile perl5_run
diff --git a/Examples/perl5/variables/Makefile b/Examples/perl5/variables/Makefile
index c4d100020..366b5897c 100644
--- a/Examples/perl5/variables/Makefile
+++ b/Examples/perl5/variables/Makefile
@@ -3,7 +3,7 @@ SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile perl5_run
diff --git a/Examples/php/callback/Makefile b/Examples/php/callback/Makefile
index 08b2710b2..6f7e4ad27 100644
--- a/Examples/php/callback/Makefile
+++ b/Examples/php/callback/Makefile
@@ -4,7 +4,7 @@ CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile php_run
diff --git a/Examples/php/extend/Makefile b/Examples/php/extend/Makefile
index 08b2710b2..6f7e4ad27 100644
--- a/Examples/php/extend/Makefile
+++ b/Examples/php/extend/Makefile
@@ -4,7 +4,7 @@ CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile php_run
diff --git a/Examples/pike/constants/Makefile b/Examples/pike/constants/Makefile
index 9a882bd4d..c9385ce3b 100644
--- a/Examples/pike/constants/Makefile
+++ b/Examples/pike/constants/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = example
INTERFACE = example.i
diff --git a/Examples/pike/template/Makefile b/Examples/pike/template/Makefile
index 73a31ee1a..e4fc945f7 100644
--- a/Examples/pike/template/Makefile
+++ b/Examples/pike/template/Makefile
@@ -1,10 +1,10 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile pike_run
diff --git a/Examples/python/callback/Makefile b/Examples/python/callback/Makefile
index 21e88adc5..684995801 100644
--- a/Examples/python/callback/Makefile
+++ b/Examples/python/callback/Makefile
@@ -4,7 +4,7 @@ CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/constants/Makefile b/Examples/python/constants/Makefile
index 505f199de..15ffa24c9 100644
--- a/Examples/python/constants/Makefile
+++ b/Examples/python/constants/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = example
INTERFACE = example.i
diff --git a/Examples/python/contract/Makefile b/Examples/python/contract/Makefile
index a44887736..999521ccc 100644
--- a/Examples/python/contract/Makefile
+++ b/Examples/python/contract/Makefile
@@ -3,7 +3,7 @@ SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/exception/Makefile b/Examples/python/exception/Makefile
index b2b163e2e..fb200fbaf 100644
--- a/Examples/python/exception/Makefile
+++ b/Examples/python/exception/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
diff --git a/Examples/python/exceptproxy/Makefile b/Examples/python/exceptproxy/Makefile
index 06bce6543..86a643415 100644
--- a/Examples/python/exceptproxy/Makefile
+++ b/Examples/python/exceptproxy/Makefile
@@ -1,10 +1,10 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/extend/Makefile b/Examples/python/extend/Makefile
index 21e88adc5..684995801 100644
--- a/Examples/python/extend/Makefile
+++ b/Examples/python/extend/Makefile
@@ -4,7 +4,7 @@ CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/functor/Makefile b/Examples/python/functor/Makefile
index 6ef158379..dde0d0910 100644
--- a/Examples/python/functor/Makefile
+++ b/Examples/python/functor/Makefile
@@ -1,10 +1,10 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/java/Makefile b/Examples/python/java/Makefile
index 47b865dd1..12a9b512a 100644
--- a/Examples/python/java/Makefile
+++ b/Examples/python/java/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
@@ -20,4 +20,3 @@ clean:
Example.class: Example.java
gcj -fPIC -C -c -g Example.java
gcjh Example
-
diff --git a/Examples/python/libffi/Makefile b/Examples/python/libffi/Makefile
index e0620f62d..ae51b0a60 100644
--- a/Examples/python/libffi/Makefile
+++ b/Examples/python/libffi/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = example
INTERFACE = example.i
diff --git a/Examples/python/operator/Makefile b/Examples/python/operator/Makefile
index 6ef158379..dde0d0910 100644
--- a/Examples/python/operator/Makefile
+++ b/Examples/python/operator/Makefile
@@ -1,10 +1,10 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/smartptr/Makefile b/Examples/python/smartptr/Makefile
index 140d482c9..aaba9cbbc 100644
--- a/Examples/python/smartptr/Makefile
+++ b/Examples/python/smartptr/Makefile
@@ -4,7 +4,7 @@ CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/std_map/Makefile b/Examples/python/std_map/Makefile
index 06bce6543..86a643415 100644
--- a/Examples/python/std_map/Makefile
+++ b/Examples/python/std_map/Makefile
@@ -1,10 +1,10 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/std_vector/Makefile b/Examples/python/std_vector/Makefile
index 06bce6543..86a643415 100644
--- a/Examples/python/std_vector/Makefile
+++ b/Examples/python/std_vector/Makefile
@@ -1,10 +1,10 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/swigrun/Makefile b/Examples/python/swigrun/Makefile
index fe9f64e94..c58f39caf 100644
--- a/Examples/python/swigrun/Makefile
+++ b/Examples/python/swigrun/Makefile
@@ -4,7 +4,7 @@ CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/template/Makefile b/Examples/python/template/Makefile
index 06bce6543..86a643415 100644
--- a/Examples/python/template/Makefile
+++ b/Examples/python/template/Makefile
@@ -1,10 +1,10 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/varargs/Makefile b/Examples/python/varargs/Makefile
index 505f199de..15ffa24c9 100644
--- a/Examples/python/varargs/Makefile
+++ b/Examples/python/varargs/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = example
INTERFACE = example.i
diff --git a/Examples/ruby/constants/Makefile b/Examples/ruby/constants/Makefile
index e0f6a03ae..7af9ec89e 100644
--- a/Examples/ruby/constants/Makefile
+++ b/Examples/ruby/constants/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = example
INTERFACE = example.i
diff --git a/Examples/ruby/exception_class/Makefile b/Examples/ruby/exception_class/Makefile
index 46bb7995d..f0ae7e573 100644
--- a/Examples/ruby/exception_class/Makefile
+++ b/Examples/ruby/exception_class/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
diff --git a/Examples/ruby/hashargs/Makefile b/Examples/ruby/hashargs/Makefile
index cee97f28e..3933cf279 100644
--- a/Examples/ruby/hashargs/Makefile
+++ b/Examples/ruby/hashargs/Makefile
@@ -1,10 +1,10 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-SRCS =
+SRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile ruby_run
diff --git a/Examples/ruby/import/Makefile b/Examples/ruby/import/Makefile
index fc6a9f10f..cd7719b5c 100644
--- a/Examples/ruby/import/Makefile
+++ b/Examples/ruby/import/Makefile
@@ -2,7 +2,7 @@ TOP = ../..
SWIG = $(TOP)/../preinst-swig
SWIGOPT =
LIBS =
-
+
check: build
$(MAKE) -f $(TOP)/Makefile ruby_run
diff --git a/Examples/ruby/import_template/Makefile b/Examples/ruby/import_template/Makefile
index fc6a9f10f..cd7719b5c 100644
--- a/Examples/ruby/import_template/Makefile
+++ b/Examples/ruby/import_template/Makefile
@@ -2,7 +2,7 @@ TOP = ../..
SWIG = $(TOP)/../preinst-swig
SWIGOPT =
LIBS =
-
+
check: build
$(MAKE) -f $(TOP)/Makefile ruby_run
diff --git a/Examples/ruby/java/Makefile b/Examples/ruby/java/Makefile
index c06bfb7bf..4d2493493 100644
--- a/Examples/ruby/java/Makefile
+++ b/Examples/ruby/java/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
@@ -20,4 +20,3 @@ clean:
Example.class: Example.java
gcj -fPIC -C -c -g Example.java
gcjh Example
-
diff --git a/Examples/ruby/operator/Makefile b/Examples/ruby/operator/Makefile
index c7a21d0a4..5fd4b077b 100644
--- a/Examples/ruby/operator/Makefile
+++ b/Examples/ruby/operator/Makefile
@@ -1,10 +1,10 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile ruby_run
diff --git a/Examples/ruby/std_vector/Makefile b/Examples/ruby/std_vector/Makefile
index f7b148062..208a64495 100644
--- a/Examples/ruby/std_vector/Makefile
+++ b/Examples/ruby/std_vector/Makefile
@@ -1,10 +1,10 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile ruby_run
diff --git a/Examples/ruby/template/Makefile b/Examples/ruby/template/Makefile
index f7b148062..208a64495 100644
--- a/Examples/ruby/template/Makefile
+++ b/Examples/ruby/template/Makefile
@@ -1,10 +1,10 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
-SWIGOPT =
+SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile ruby_run
diff --git a/Examples/tcl/java/Makefile b/Examples/tcl/java/Makefile
index 1578dfd18..3a9212381 100644
--- a/Examples/tcl/java/Makefile
+++ b/Examples/tcl/java/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
@@ -23,4 +23,3 @@ run:
Example.class: Example.java
gcj -fPIC -C -c -g Example.java
gcjh Example
-
diff --git a/Examples/tcl/operator/Makefile b/Examples/tcl/operator/Makefile
index 6fa350bf0..6c91c3d21 100644
--- a/Examples/tcl/operator/Makefile
+++ b/Examples/tcl/operator/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
diff --git a/Examples/tcl/std_vector/Makefile b/Examples/tcl/std_vector/Makefile
index 9ff99e2f2..a150fc956 100644
--- a/Examples/tcl/std_vector/Makefile
+++ b/Examples/tcl/std_vector/Makefile
@@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
-CXXSRCS =
+CXXSRCS =
TARGET = my_tclsh
DLTARGET = example
INTERFACE = example.i
diff --git a/Examples/test-suite/c_delete.i b/Examples/test-suite/c_delete.i
index 632340629..0c69f9f41 100644
--- a/Examples/test-suite/c_delete.i
+++ b/Examples/test-suite/c_delete.i
@@ -2,9 +2,9 @@
/* check C++ delete keyword is okay in C wrappers */
-#pragma SWIG nowarn=SWIGWARN_PARSE_KEYWORD
+%warnfilter(SWIGWARN_PARSE_KEYWORD) delete;
-#if !defined(SWIGOCTAVE) /* Octave compiles wrappers as C++ */
+#if !defined(SWIGOCTAVE) && !defined(SWIG_JAVASCRIPT_V8) /* Octave and Javascript/v8 compiles wrappers as C++ */
%inline %{
struct delete {
diff --git a/Examples/test-suite/c_delete_function.i b/Examples/test-suite/c_delete_function.i
index 3739ceadc..8164d066b 100644
--- a/Examples/test-suite/c_delete_function.i
+++ b/Examples/test-suite/c_delete_function.i
@@ -2,7 +2,9 @@
/* check C++ delete keyword is okay in C wrappers */
-#if !defined(SWIGOCTAVE) /* Octave compiles wrappers as C++ */
+%warnfilter(SWIGWARN_PARSE_KEYWORD) delete;
+
+#if !defined(SWIGOCTAVE) && !defined(SWIG_JAVASCRIPT_V8) /* Octave and Javascript/v8 compiles wrappers as C++ */
%inline %{
double delete(double d) { return d; }
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
index 67f99b0b1..2a4591524 100644
--- a/Examples/test-suite/common.mk
+++ b/Examples/test-suite/common.mk
@@ -197,6 +197,7 @@ CPP_TEST_CASES += \
disown \
dynamic_cast \
empty \
+ enum_ignore \
enum_plus \
enum_rename \
enum_scope_template \
@@ -587,6 +588,7 @@ C_TEST_CASES += \
global_functions \
immutable_values \
inctest \
+ infinity \
integers \
keyword_rename \
lextype \
@@ -613,6 +615,7 @@ C_TEST_CASES += \
simple_array \
sizeof_pointer \
sneaky1 \
+ string_simple \
struct_rename \
struct_initialization \
typedef_struct \
diff --git a/Examples/test-suite/constructor_copy.i b/Examples/test-suite/constructor_copy.i
index bfbd706f4..8e92e7840 100644
--- a/Examples/test-suite/constructor_copy.i
+++ b/Examples/test-suite/constructor_copy.i
@@ -73,7 +73,7 @@ public:
%include "std_vector.i"
-#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGR) || defined(SWIGOCTAVE) || defined(SWIGRUBY)
+#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGR) || defined(SWIGOCTAVE) || defined(SWIGRUBY) || defined(SWIGJAVASCRIPT)
#define SWIG_GOOD_VECTOR
%ignore std::vector<Space::Flow>::vector(size_type);
%ignore std::vector<Space::Flow>::resize(size_type);
diff --git a/Examples/test-suite/cpp11_template_double_brackets.i b/Examples/test-suite/cpp11_template_double_brackets.i
index 15fe4903b..ba5caa5c5 100644
--- a/Examples/test-suite/cpp11_template_double_brackets.i
+++ b/Examples/test-suite/cpp11_template_double_brackets.i
@@ -24,6 +24,14 @@ public:
int operator<<(ABC &) { return 0; }
};
+class DEF {
+public:
+ int a;
+ int operator<<(DEF &) { return 0; }
+ int operator>>(DEF &) { return 0; }
+};
+
+
template<class T>
class ABC2 {
public:
@@ -37,3 +45,9 @@ public:
};
%}
+// Test shifts are still working
+%inline %{
+int shift_init1 = 4 << 2 >> 1;
+int shift_init2 = 4 >> 2 << 1 << 1 >> 2;
+%}
+
diff --git a/Examples/test-suite/cpp_basic.i b/Examples/test-suite/cpp_basic.i
index bd1ec453a..a228af289 100644
--- a/Examples/test-suite/cpp_basic.i
+++ b/Examples/test-suite/cpp_basic.i
@@ -30,6 +30,19 @@ class Foo {
}
int (Foo::*func_ptr)(int);
+
+ const char* __str__() const { return "Foo"; }
+};
+
+class FooSub : public Foo {
+ public:
+ FooSub() :Foo(42) {}
+};
+
+class FooSubSub : public FooSub {
+ public:
+ FooSubSub() : FooSub() {}
+ const char* __str__() const { return "FooSubSub"; }
};
%}
diff --git a/Examples/test-suite/d/operator_overload_runme.2.d b/Examples/test-suite/d/operator_overload_runme.2.d
index 2ff61cd56..d05265e58 100644
--- a/Examples/test-suite/d/operator_overload_runme.2.d
+++ b/Examples/test-suite/d/operator_overload_runme.2.d
@@ -53,7 +53,7 @@ void main() {
assert(-a == a);
assert(-b == new Op(-5));
- // Unfortunaly, there is no way to override conversion to boolean for
+ // Unfortunately, there is no way to override conversion to boolean for
// classes in D, opCast!("bool") is only used for structs.
// test []
diff --git a/Examples/test-suite/director_nspace.i b/Examples/test-suite/director_nspace.i
index fdea75e2f..f24227c68 100644
--- a/Examples/test-suite/director_nspace.i
+++ b/Examples/test-suite/director_nspace.i
@@ -40,7 +40,7 @@ namespace TopLevel
%include <std_string.i>
// nspace feature only supported by these languages
-#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGLUA)
+#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGLUA) || defined(SWIGJAVASCRIPT)
%nspace TopLevel::Bar::Foo;
%nspace TopLevel::Bar::FooBar;
#else
diff --git a/Examples/test-suite/director_nspace_director_name_collision.i b/Examples/test-suite/director_nspace_director_name_collision.i
index 8fd27c968..190bdf4fa 100644
--- a/Examples/test-suite/director_nspace_director_name_collision.i
+++ b/Examples/test-suite/director_nspace_director_name_collision.i
@@ -34,7 +34,7 @@ namespace TopLevel
%include <std_string.i>
// nspace feature only supported by these languages
-#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGLUA)
+#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGLUA) || defined(SWIGJAVASCRIPT)
%nspace TopLevel::A::Foo;
%nspace TopLevel::B::Foo;
#else
diff --git a/Examples/test-suite/enum_forward.i b/Examples/test-suite/enum_forward.i
index 1609fa8e9..c82e17be7 100644
--- a/Examples/test-suite/enum_forward.i
+++ b/Examples/test-suite/enum_forward.i
@@ -1,7 +1,7 @@
%module enum_forward
-/* This contains C code that is not valid C++03 and Octave wrappers are always compiled as C++ */
-#if !defined(SWIGOCTAVE)
+/* This contains C code that is not valid C++03 and Octave, and Javascript(v8) wrappers are always compiled as C++ */
+#if !defined(SWIGOCTAVE) && !defined(SWIG_JAVASCRIPT_V8)
%{
enum ForwardEnum1 { AAA, BBB };
enum ForwardEnum2 { CCC, DDD };
diff --git a/Examples/test-suite/enum_ignore.i b/Examples/test-suite/enum_ignore.i
new file mode 100644
index 000000000..6d11f6a97
--- /dev/null
+++ b/Examples/test-suite/enum_ignore.i
@@ -0,0 +1,20 @@
+%module enum_ignore
+
+// Similar to enum_missing C test, but with namespaces and using %ignore
+
+%ignore N::C;
+
+%inline %{
+ namespace N {
+ enum C { Red, Green, Blue };
+
+ struct Draw {
+ void DrawBW() {}
+ void DrawC(C c) {}
+ void DrawC_Ptr(C* c) {}
+ void DrawC_ConstRef(C const& c) {}
+ };
+ }
+%}
+
+
diff --git a/Examples/test-suite/errors/cpp_extra_brackets.i b/Examples/test-suite/errors/cpp_extra_brackets.i
new file mode 100644
index 000000000..32cf7f72d
--- /dev/null
+++ b/Examples/test-suite/errors/cpp_extra_brackets.i
@@ -0,0 +1,6 @@
+%module cpp_extra_brackets
+
+// Extra brackets was segfaulting in SWIG-3.0.0
+struct ABC {
+ int operator<<(ABC &))) { return 0; }
+};
diff --git a/Examples/test-suite/errors/cpp_extra_brackets.stderr b/Examples/test-suite/errors/cpp_extra_brackets.stderr
new file mode 100644
index 000000000..12bb1f327
--- /dev/null
+++ b/Examples/test-suite/errors/cpp_extra_brackets.stderr
@@ -0,0 +1 @@
+cpp_extra_brackets.i:5: Error: Syntax error in input(3).
diff --git a/Examples/test-suite/errors/cpp_extra_brackets2.i b/Examples/test-suite/errors/cpp_extra_brackets2.i
new file mode 100644
index 000000000..17a5d5918
--- /dev/null
+++ b/Examples/test-suite/errors/cpp_extra_brackets2.i
@@ -0,0 +1,9 @@
+%module cpp_extra_brackets
+
+// Extra brackets was segfaulting in SWIG-3.0.0
+struct ABC {
+;
+)))
+int operator<<(ABC &) { return 0; }
+int operator>>(ABC &) { return 0; }
+};
diff --git a/Examples/test-suite/errors/cpp_extra_brackets2.stderr b/Examples/test-suite/errors/cpp_extra_brackets2.stderr
new file mode 100644
index 000000000..c2eaf741c
--- /dev/null
+++ b/Examples/test-suite/errors/cpp_extra_brackets2.stderr
@@ -0,0 +1 @@
+cpp_extra_brackets2.i:6: Error: Syntax error in input(3).
diff --git a/Examples/test-suite/infinity.i b/Examples/test-suite/infinity.i
new file mode 100644
index 000000000..726150f02
--- /dev/null
+++ b/Examples/test-suite/infinity.i
@@ -0,0 +1,47 @@
+%module infinity
+
+/* C99 defines INFINITY
+ Because INFINITY may be defined by compiler built-ins, we can't use #define.
+ Instead, expose the variable MYINFINITY and then use %rename to make it INFINITY in the scripting language.
+*/
+%rename(INFINITY) MYINFINITY;
+
+%{
+#include <math.h>
+
+/* C99 math.h defines INFINITY. If not available, this is the fallback. */
+#ifndef INFINITY
+ #ifdef _MSC_VER
+ union MSVC_EVIL_FLOAT_HACK
+ {
+ unsigned __int8 Bytes[4];
+ float Value;
+ };
+ static union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};
+ #define INFINITY (INFINITY_HACK.Value)
+ #endif
+
+ #ifdef __GNUC__
+ #define INFINITY (__builtin_inf())
+ #elif defined(__clang__)
+ #if __has_builtin(__builtin_inf)
+ #define INFINITY (__builtin_inf())
+ #endif
+ #endif
+
+ #ifndef INFINITY
+ #define INFINITY (1e1000)
+ #endif
+#endif
+%}
+
+%inline %{
+/* This will allow us to bind the real INFINITY value through SWIG via MYINFINITY. Use %rename to fix the name. */
+const double MYINFINITY = INFINITY;
+
+/* Use of float is intentional because the original bug was in the float conversion due to overflow checking. */
+float use_infinity(float inf_val)
+{
+ return inf_val;
+}
+%}
diff --git a/Examples/test-suite/javascript/Makefile.in b/Examples/test-suite/javascript/Makefile.in
new file mode 100755
index 000000000..7368ea9a3
--- /dev/null
+++ b/Examples/test-suite/javascript/Makefile.in
@@ -0,0 +1,114 @@
+#######################################################################
+# Makefile for javascript test-suite
+#######################################################################
+
+LANGUAGE = javascript
+NODEGYP = @NODEGYP@
+SCRIPTSUFFIX = _runme.js
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+top_builddir = @top_builddir@
+SWIG = $(top_builddir)/preinst_swig
+
+ifneq (, $(ENGINE))
+ JSENGINE=$(ENGINE)
+else
+ JSENGINE=node
+endif
+
+include $(srcdir)/../common.mk
+
+_setup = \
+ if [ -f $(srcdir)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
+ echo "$(ACTION)ing $(LANGUAGE) ($(JSENGINE)) testcase $* (with run test)" ; \
+ else \
+ echo "$(ACTION)ing $(LANGUAGE) ($(JSENGINE)) testcase $*" ; \
+ fi;
+
+ifneq (jsc,$(ENGINE))
+
+ # This test can not be run with v8 as it uses v8 API incompatible output typemaps
+ typemap_variables.cpptest:
+ echo "skipping $(LANGUAGE) ($(JSENGINE)) testcase typemap_variables" ;
+
+endif
+
+ifeq (node,$(JSENGINE))
+
+ SWIGOPT += -v8 -DBUILDING_NODE_EXTENSION=1
+
+ # shut up some warnings
+ # contract macro has an empty 'else' at the end...
+ aggregate.cpptest: GYP_CFLAGS = \"-Wno-empty-body\"
+ contract.cpptest: GYP_CFLAGS = \"-Wno-empty-body\"
+
+ # dunno... ignoring generously
+ apply_signed_char.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\"
+ constant_pointers.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\"
+ enum_thorough.cpptest: GYP_CFLAGS = \"-Wno-ignored-qualifiers\"
+
+ # Note: we need to use swig in C parse mode, but make node-gyp believe it is c++ (via file extension)
+ swig_and_compile_c = \
+ sh ./setup_test.sh $* $(GYP_CFLAGS); \
+ $(SWIG) -javascript $(SWIGOPT) -o $*_wrap.cxx ../$*.i; \
+ $(NODEGYP) --loglevel=silent --directory $* configure build 1>>/dev/null
+
+ swig_and_compile_cpp = \
+ sh ./setup_test.sh $* $(GYP_CFLAGS); \
+ $(SWIG) -c++ -javascript $(SWIGOPT) ../$*.i; \
+ $(NODEGYP) --loglevel=silent --directory $* configure build 1>>/dev/null
+
+ run_testcase = \
+ if [ -f $(srcdir)/$*$(SCRIPTSUFFIX) ]; then \
+ node $(srcdir)/$*$(SCRIPTSUFFIX); \
+ fi
+
+
+ %.ctest:
+ $(_setup)
+ $(swig_and_compile_c)
+ $(run_testcase)
+
+ %.cpptest:
+ $(_setup)
+ $(swig_and_compile_cpp)
+ $(run_testcase)
+
+ %.multicpptest:
+ $(_setup)
+
+else
+
+ SWIGOPT += -$(JSENGINE)
+
+ run_testcase = \
+ if [ -f $(srcdir)/$*$(SCRIPTSUFFIX) ]; then \
+ $(top_srcdir)/Tools/javascript/javascript -$(JSENGINE) $(srcdir)/$*$(SCRIPTSUFFIX); \
+ fi
+
+ %.ctest:
+ $(_setup)
+ +$(swig_and_compile_c)
+ $(run_testcase)
+
+ %.cpptest:
+ $(_setup)
+ +$(swig_and_compile_cpp)
+ $(run_testcase)
+
+ %.multicpptest:
+ $(_setup)
+ +$(swig_and_compile_multi_cpp)
+ $(run_testcase)
+
+endif
+
+
+%.clean:
+ rm -rf $*
+
+clean:
+ rm -f *_wrap.cxx
+ rm -f *_wrap.c
+ rm -f *.so
+ rm -f *.o
diff --git a/Examples/test-suite/javascript/abstract_access_runme.js b/Examples/test-suite/javascript/abstract_access_runme.js
new file mode 100644
index 000000000..8f87d2105
--- /dev/null
+++ b/Examples/test-suite/javascript/abstract_access_runme.js
@@ -0,0 +1,6 @@
+var abstract_access = require("./abstract_access");
+
+var d = new abstract_access.D()
+if (d.do_x() != 1) {
+ throw "Error";
+}
diff --git a/Examples/test-suite/javascript/abstract_inherit_runme.js b/Examples/test-suite/javascript/abstract_inherit_runme.js
new file mode 100644
index 000000000..3af2eae74
--- /dev/null
+++ b/Examples/test-suite/javascript/abstract_inherit_runme.js
@@ -0,0 +1,40 @@
+var abstract_inherit = require("./abstract_inherit");
+
+// Shouldn't be able to instantiate any of these classes
+// since none of them implements the pure virtual function
+// declared in the base class (Foo).
+var Foo = abstract_inherit.Foo;
+var Bar = abstract_inherit.Bar;
+var Spam = abstract_inherit.Spam;
+
+var caughtException = false;
+try {
+ new Foo();
+} catch (err) {
+ caughtException = true;
+}
+if (!caughtException) {
+ throw new Error("Foo should be instantiated as it is abstract");
+}
+
+caughtException = false;
+try {
+ new Bar();
+} catch (err) {
+ caughtException = true;
+}
+
+if (!caughtException) {
+ throw new Error("Bar should be instantiated as it is abstract");
+}
+
+caughtException = false;
+try {
+ new Spam();
+} catch (err) {
+ caughtException = true;
+}
+
+if (!caughtException) {
+ throw new Error("Spam should be instantiated as it is abstract");
+}
diff --git a/Examples/test-suite/javascript/abstract_typedef2_runme.js b/Examples/test-suite/javascript/abstract_typedef2_runme.js
new file mode 100644
index 000000000..c177e49c3
--- /dev/null
+++ b/Examples/test-suite/javascript/abstract_typedef2_runme.js
@@ -0,0 +1,6 @@
+var abstract_typedef2 = require("./abstract_typedef2");
+
+var a = new abstract_typedef2.A_UF();
+
+if (a == undefined)
+ throw "Error";
diff --git a/Examples/test-suite/javascript/abstract_typedef_runme.js b/Examples/test-suite/javascript/abstract_typedef_runme.js
new file mode 100644
index 000000000..abcfc581d
--- /dev/null
+++ b/Examples/test-suite/javascript/abstract_typedef_runme.js
@@ -0,0 +1,8 @@
+var abstract_typedef = require("./abstract_typedef");
+
+var e = new abstract_typedef.Engine();
+var a = new abstract_typedef.A()
+
+if (a.write(e) != 1) {
+ throw "Error";
+}
diff --git a/Examples/test-suite/javascript/abstract_virtual_runme.js b/Examples/test-suite/javascript/abstract_virtual_runme.js
new file mode 100644
index 000000000..9e2814e41
--- /dev/null
+++ b/Examples/test-suite/javascript/abstract_virtual_runme.js
@@ -0,0 +1,11 @@
+var abstract_virtual = require("./abstract_virtual");
+
+d = new abstract_virtual.D()
+
+if (d == undefined)
+ throw "Error";
+
+e = new abstract_virtual.E()
+
+if (e == undefined)
+ throw "Error";
diff --git a/Examples/test-suite/javascript/array_member_runme.js b/Examples/test-suite/javascript/array_member_runme.js
new file mode 100644
index 000000000..8c4ef1da5
--- /dev/null
+++ b/Examples/test-suite/javascript/array_member_runme.js
@@ -0,0 +1,22 @@
+var array_member = require("./array_member");
+
+var f = new array_member.Foo();
+f.data = array_member.global_data;
+
+for (var i=0; i<8; i++) {
+ if (array_member.get_value(f.data,i) != array_member.get_value(array_member.global_data,i)) {
+ throw "Bad array assignment (1)";
+ }
+}
+
+for (var i=0; i<8; i++) {
+ array_member.set_value(f.data,i,-i);
+}
+
+array_member.global_data = f.data;
+
+for (var i=0; i<8; i++){
+ if (array_member.get_value(f.data,i) != array_member.get_value(array_member.global_data,i)) {
+ throw "Bad array assignment (2)";
+ }
+}
diff --git a/Examples/test-suite/javascript/arrays_global_runme.js b/Examples/test-suite/javascript/arrays_global_runme.js
new file mode 100644
index 000000000..fdb365f83
--- /dev/null
+++ b/Examples/test-suite/javascript/arrays_global_runme.js
@@ -0,0 +1,18 @@
+var arrays_global = require("./arrays_global");
+
+arrays_global.array_i = arrays_global.array_const_i;
+
+arrays_global.BeginString_FIX44a;
+arrays_global.BeginString_FIX44b;
+arrays_global.BeginString_FIX44c;
+arrays_global.BeginString_FIX44d;
+arrays_global.BeginString_FIX44d;
+arrays_global.BeginString_FIX44b = "12"+'\0'+"45";
+arrays_global.BeginString_FIX44b;
+arrays_global.BeginString_FIX44d;
+arrays_global.BeginString_FIX44e;
+arrays_global.BeginString_FIX44f;
+
+arrays_global.test_a("hello","hi","chello","chi");
+
+arrays_global.test_b("1234567","hi");
diff --git a/Examples/test-suite/javascript/callback_runme.js b/Examples/test-suite/javascript/callback_runme.js
new file mode 100644
index 000000000..9b1ef01a3
--- /dev/null
+++ b/Examples/test-suite/javascript/callback_runme.js
@@ -0,0 +1,30 @@
+var callback = require("./callback");
+
+if (callback.foo(2) !== 2) {
+ throw new Error("Failed.");
+}
+if (callback.A_bar(2) !== 4) {
+ throw new Error("Failed.");
+}
+if (callback.foobar(3, callback.foo) != callback.foo(3)) {
+ throw new Error("Failed.");
+}
+if (callback.foobar(3, foo) != callback.foo(3)) {
+ throw new Error("Failed.");
+}
+if (callback.foobar(3, callback.A_bar) != callback.A_bar(3)) {
+ throw new Error("Failed.");
+}
+if (callback.foobar(3, callback.foof) != callback.foof(3)) {
+ throw new Error("Failed.");
+}
+if (callback.foobar_i(3, callback.foo_i) != callback.foo_i(3)) {
+ throw new Error("Failed.");
+}
+if (callback.foobar_d(3.5, callback.foo_d) != callback.foo_d(3.5)) {
+ throw new Error("Failed.");
+}
+var a = new callback.A();
+if (callback.foobarm(3, a, callback.A.foom_cb_ptr) != a.foom(3)) {
+ throw new Error("Failed.");
+}
diff --git a/Examples/test-suite/javascript/char_binary_runme.js b/Examples/test-suite/javascript/char_binary_runme.js
new file mode 100644
index 000000000..42abe6060
--- /dev/null
+++ b/Examples/test-suite/javascript/char_binary_runme.js
@@ -0,0 +1,38 @@
+var char_binary = require("./char_binary");
+
+var t = new char_binary.Test();
+if (t.strlen('hile') != 4) {
+ print(t.strlen('hile'));
+ throw("bad multi-arg typemap 1");
+}
+
+if (t.strlen('hil\0') != 4) {
+ throw("bad multi-arg typemap 2");
+}
+
+/*
+ * creating a raw char*
+ */
+var pc = char_binary.new_pchar(5);
+char_binary.pchar_setitem(pc, 0, 'h');
+char_binary.pchar_setitem(pc, 1, 'o');
+char_binary.pchar_setitem(pc, 2, 'l');
+char_binary.pchar_setitem(pc, 3, 'a');
+char_binary.pchar_setitem(pc, 4, 0);
+
+
+if (t.strlen(pc) != 4) {
+ throw("bad multi-arg typemap (3)");
+}
+
+char_binary.var_pchar = pc;
+if (char_binary.var_pchar != "hola") {
+ print(char_binary.var_pchar);
+ throw("bad pointer case (1)");
+}
+
+char_binary.var_namet = pc;
+if (char_binary.var_namet != "hola") {
+ throw("bad pointer case (2)");
+}
+char_binary.delete_pchar(pc);
diff --git a/Examples/test-suite/javascript/char_strings_runme.js b/Examples/test-suite/javascript/char_strings_runme.js
new file mode 100644
index 000000000..cca50d851
--- /dev/null
+++ b/Examples/test-suite/javascript/char_strings_runme.js
@@ -0,0 +1,11 @@
+var char_strings = require("./char_strings");
+
+var assertIsEqual = function(expected, actual) {
+ if (expected !== actual) {
+ throw new Error("Expected "+expected+", was "+actual);
+ }
+};
+
+assertIsEqual("hi there", char_strings.CharPingPong("hi there"));
+assertIsEqual("hi there", char_strings.CharArrayPingPong("hi there"));
+assertIsEqual("hi there", char_strings.CharArrayDimsPingPong("hi there"));
diff --git a/Examples/test-suite/javascript/class_ignore_runme.js b/Examples/test-suite/javascript/class_ignore_runme.js
new file mode 100644
index 000000000..f0a32a1c4
--- /dev/null
+++ b/Examples/test-suite/javascript/class_ignore_runme.js
@@ -0,0 +1,6 @@
+var class_ignore = require("./class_ignore");
+
+a = new class_ignore.Bar();
+
+if (class_ignore.do_blah(a) != "Bar::blah")
+ throw "Error";
diff --git a/Examples/test-suite/javascript/class_scope_weird_runme.js b/Examples/test-suite/javascript/class_scope_weird_runme.js
new file mode 100644
index 000000000..ac745d023
--- /dev/null
+++ b/Examples/test-suite/javascript/class_scope_weird_runme.js
@@ -0,0 +1,6 @@
+var class_scope_weird = require("./class_scope_weird");
+
+f = new class_scope_weird.Foo();
+g = new class_scope_weird.Foo(3);
+if (f.bar(3) != 3)
+ throw RuntimeError;
diff --git a/Examples/test-suite/javascript/complextest_runme.js b/Examples/test-suite/javascript/complextest_runme.js
new file mode 100644
index 000000000..1fcc97648
--- /dev/null
+++ b/Examples/test-suite/javascript/complextest_runme.js
@@ -0,0 +1,22 @@
+var complextest = require("./complextest");
+
+a = [-1,2];
+
+expected = [-1, -2];
+
+a_c = complextest.Conj(a);
+if (a_c.toString() != expected.toString())
+ throw "Error in Conj(a)";
+
+a_c_f = complextest.Conjf(a);
+if (a_c_f.toString() != expected.toString())
+ throw "Error in Conjf(a)";
+
+v = new complextest.VectorStdCplx();
+v.add([1,2]);
+v.add([2,3]);
+v.add([4,3]);
+v.add(1);
+
+// TODO: how to check validity?
+complextest.Copy_h(v);
diff --git a/Examples/test-suite/javascript/constover_runme.js b/Examples/test-suite/javascript/constover_runme.js
new file mode 100644
index 000000000..764d8b328
--- /dev/null
+++ b/Examples/test-suite/javascript/constover_runme.js
@@ -0,0 +1,33 @@
+var constover = require("./constover");
+
+p = constover.test("test");
+if (p != "test") {
+ throw "test failed!";
+}
+
+p = constover.test_pconst("test");
+if (p != "test_pconst") {
+ throw "test_pconst failed!";
+}
+
+f = new constover.Foo();
+
+p = f.test("test");
+if (p != "test") {
+ throw "member-test failed!";
+}
+
+p = f.test_pconst("test");
+if (p != "test_pconst") {
+ throw "member-test_pconst failed!";
+}
+
+p = f.test_constm("test");
+if (p != "test_constmethod") {
+ throw "member-test_constm failed!";
+}
+
+p = f.test_pconstm("test");
+if (p != "test_pconstmethod") {
+ throw "member-test_pconstm failed!";
+}
diff --git a/Examples/test-suite/javascript/constructor_copy_runme.js b/Examples/test-suite/javascript/constructor_copy_runme.js
new file mode 100644
index 000000000..39dce52ce
--- /dev/null
+++ b/Examples/test-suite/javascript/constructor_copy_runme.js
@@ -0,0 +1,42 @@
+var constructor_copy = require("./constructor_copy");
+
+f1 = new constructor_copy.Foo1(3);
+f11 = new constructor_copy.Foo1(f1);
+
+if (f1.x != f11.x) {
+ throw "error in ctor copy for Foo1";
+}
+
+var good = 0;
+
+f8 = new constructor_copy.Foo8()
+try {
+ f81 = new constructor_copy.Foo8(f8);
+ good = 0;
+} catch (err) {
+ good = 1;
+}
+
+if (good == 0) {
+ throw "Error: should not allow calling copy ctor for Foo8";
+}
+
+
+bi = new constructor_copy.Bari(5);
+bc = new constructor_copy.Bari(bi);
+
+if (bi.x != bc.x) {
+ throw "Error in copy ctor of Bari";
+}
+
+bd = new constructor_copy.Bard(5);
+try {
+ bc = new constructor_copy.Bard(bd);
+ good = 0;
+} catch (err) {
+ good = 1;
+}
+
+if (good == 0) {
+ throw "Error: should not allow calling copy ctor for Bard";
+}
diff --git a/Examples/test-suite/javascript/cpp_enum_runme.js b/Examples/test-suite/javascript/cpp_enum_runme.js
new file mode 100644
index 000000000..35f7c60ac
--- /dev/null
+++ b/Examples/test-suite/javascript/cpp_enum_runme.js
@@ -0,0 +1,28 @@
+var cpp_enum = require("./cpp_enum");
+
+var f = new cpp_enum.Foo()
+
+if(f.hola != cpp_enum.Hello){
+ print(f.hola);
+ throw "Error";
+}
+
+f.hola = cpp_enum.Foo.Hi
+if(f.hola != cpp_enum.Foo.Hi){
+ print(f.hola);
+ throw "Error";
+}
+
+f.hola = cpp_enum.Hello
+
+if(f.hola != cpp_enum.Hello){
+ print(f.hola);
+ throw "Error";
+}
+
+cpp_enum.Foo.hi = cpp_enum.Hello
+if(cpp_enum.Foo.hi != cpp_enum.Hello){
+ print(cpp_enum.Foo.hi);
+ throw "Error";
+}
+
diff --git a/Examples/test-suite/javascript/cpp_namespace_runme.js b/Examples/test-suite/javascript/cpp_namespace_runme.js
new file mode 100644
index 000000000..3bdfef3e9
--- /dev/null
+++ b/Examples/test-suite/javascript/cpp_namespace_runme.js
@@ -0,0 +1,47 @@
+var cpp_namespace = require("./cpp_namespace");
+
+var n = cpp_namespace.fact(4);
+if (n != 24){
+ throw ("Bad return value error!");
+}
+if (cpp_namespace.Foo != 42){
+ throw ("Bad variable value error!");
+}
+
+t = new cpp_namespace.Test();
+if (t.method() != "Test::method"){
+ throw ("Bad method return value error!");
+}
+if (cpp_namespace.do_method(t) != "Test::method"){
+ throw ("Bad return value error!");
+}
+
+if (cpp_namespace.do_method2(t) != "Test::method"){
+ throw ("Bad return value error!");
+}
+cpp_namespace.weird("hello", 4);
+delete t;
+
+t2 = new cpp_namespace.Test2();
+t3 = new cpp_namespace.Test3();
+t4 = new cpp_namespace.Test4();
+t5 = new cpp_namespace.Test5();
+if (cpp_namespace.foo3(42) != 42){
+ throw ("Bad return value error!");
+}
+
+if (cpp_namespace.do_method3(t2,40) != "Test2::method"){
+ throw ("Bad return value error!");
+}
+
+if (cpp_namespace.do_method3(t3,40) != "Test3::method"){
+ throw ("Bad return value error!");
+}
+
+if (cpp_namespace.do_method3(t4,40) != "Test4::method"){
+ throw ("Bad return value error!");
+}
+
+if (cpp_namespace.do_method3(t5,40) != "Test5::method"){
+ throw ("Bad return value error!");
+}
diff --git a/Examples/test-suite/javascript/cpp_static_runme.js b/Examples/test-suite/javascript/cpp_static_runme.js
new file mode 100644
index 000000000..2579aeafe
--- /dev/null
+++ b/Examples/test-suite/javascript/cpp_static_runme.js
@@ -0,0 +1,9 @@
+var cpp_static = require("./cpp_static");
+
+cpp_static.StaticFunctionTest.static_func();
+cpp_static.StaticFunctionTest.static_func_2(1);
+cpp_static.StaticFunctionTest.static_func_3(1,2);
+cpp_static.StaticMemberTest.static_int = 10;
+if (cpp_static.StaticMemberTest.static_int != 10)
+throw "error";
+
diff --git a/Examples/test-suite/javascript/director_alternating_runme.js b/Examples/test-suite/javascript/director_alternating_runme.js
new file mode 100644
index 000000000..a0411eace
--- /dev/null
+++ b/Examples/test-suite/javascript/director_alternating_runme.js
@@ -0,0 +1,5 @@
+var director_alternating = require("./director_alternating");
+
+id = director_alternating.getBar().id();
+if (id != director_alternating.idFromGetBar())
+ throw ("Error, Got wrong id: " + str(id));
diff --git a/Examples/test-suite/javascript/disown_runme.js b/Examples/test-suite/javascript/disown_runme.js
new file mode 100644
index 000000000..a4a6fd880
--- /dev/null
+++ b/Examples/test-suite/javascript/disown_runme.js
@@ -0,0 +1,22 @@
+var disown = require("./disown");
+
+var a = new disown.A();
+var tmp = a.thisown;
+a.thisown = 0
+if (a.thisown) {
+ throw new Error("Failed.");
+}
+a.thisown = 1
+if (!a.thisown) {
+ throw new Error("Failed.");
+}
+a.thisown = tmp
+if (a.thisown != tmp) {
+ throw new Error("Failed.");
+}
+
+var b = new disown.B();
+b.acquire(a);
+if (a.thisown) {
+ throw new Error("Failed.");
+}
diff --git a/Examples/test-suite/javascript/dynamic_cast_runme.js b/Examples/test-suite/javascript/dynamic_cast_runme.js
new file mode 100644
index 000000000..0029cb0f8
--- /dev/null
+++ b/Examples/test-suite/javascript/dynamic_cast_runme.js
@@ -0,0 +1,12 @@
+var dynamic_cast = require("./dynamic_cast");
+
+var f = new dynamic_cast.Foo();
+var b = new dynamic_cast.Bar();
+
+var x = f.blah();
+var y = b.blah();
+
+var a = dynamic_cast.do_test(y);
+if (a != "Bar::test") {
+ throw new Error("Failed.");
+}
diff --git a/Examples/test-suite/javascript/empty_runme.js b/Examples/test-suite/javascript/empty_runme.js
new file mode 100644
index 000000000..db06b3902
--- /dev/null
+++ b/Examples/test-suite/javascript/empty_runme.js
@@ -0,0 +1 @@
+var empty = require("./empty"); \ No newline at end of file
diff --git a/Examples/test-suite/javascript/enum_template_runme.js b/Examples/test-suite/javascript/enum_template_runme.js
new file mode 100644
index 000000000..20f8c3482
--- /dev/null
+++ b/Examples/test-suite/javascript/enum_template_runme.js
@@ -0,0 +1,8 @@
+var enum_template = require("./enum_template");
+
+if (enum_template.MakeETest() != 1)
+ throw "RuntimeError";
+
+if (enum_template.TakeETest(0) != null)
+ throw "RuntimeError";
+
diff --git a/Examples/test-suite/javascript/infinity_runme.js b/Examples/test-suite/javascript/infinity_runme.js
new file mode 100644
index 000000000..7b5182ff6
--- /dev/null
+++ b/Examples/test-suite/javascript/infinity_runme.js
@@ -0,0 +1,4 @@
+var infinity = require("./infinity");
+
+var my_infinity = infinity.INFINITY;
+var ret_val = infinity.use_infinity(my_infinity);
diff --git a/Examples/test-suite/javascript/namespace_virtual_method_runme.js b/Examples/test-suite/javascript/namespace_virtual_method_runme.js
new file mode 100644
index 000000000..24d3bd487
--- /dev/null
+++ b/Examples/test-suite/javascript/namespace_virtual_method_runme.js
@@ -0,0 +1,3 @@
+var namespace_virtual_method = require("./namespace_virtual_method");
+
+x = new namespace_virtual_method.Spam();
diff --git a/Examples/test-suite/javascript/node_template/binding.gyp.in b/Examples/test-suite/javascript/node_template/binding.gyp.in
new file mode 100644
index 000000000..209774ae0
--- /dev/null
+++ b/Examples/test-suite/javascript/node_template/binding.gyp.in
@@ -0,0 +1,30 @@
+{
+ "targets": [
+ {
+ "target_name": "$testcase",
+ "sources":[ "../$testcase_wrap.cxx" ],
+ "include_dirs": ["../.."],
+ 'defines': [
+ 'BUILDING_NODE_EXTENSION=1',
+ ],
+ 'conditions': [
+ ['OS=="mac"',
+ {
+ 'xcode_settings': {
+ 'GCC_ENABLE_CPP_RTTI': 'YES',
+ 'GCC_ENABLE_CPP_EXCEPTIONS' : 'YES'
+ }
+ }
+ ],
+ ['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"',
+ {
+ 'cflags': [ "-Wno-unused-variable", "-Wno-unused-but-set-variable", "-Wno-unused-but-set-parameter", $cflags],
+ 'cflags_cc': [ "-Wno-unused-variable", "-Wno-unused-but-set-variable", "-Wno-unused-but-set-parameter", $cflags],
+ 'cflags!': [ '-fno-exceptions' ],
+ 'cflags_cc!': [ '-fno-exceptions', '-fno-rtti' ]
+ }
+ ]
+ ],
+ }
+ ],
+}
diff --git a/Examples/test-suite/javascript/node_template/index.js.in b/Examples/test-suite/javascript/node_template/index.js.in
new file mode 100644
index 000000000..72330499d
--- /dev/null
+++ b/Examples/test-suite/javascript/node_template/index.js.in
@@ -0,0 +1 @@
+module.exports = require('./build/Release/$testcase');
diff --git a/Examples/test-suite/javascript/nspace_extend_runme.js b/Examples/test-suite/javascript/nspace_extend_runme.js
new file mode 100644
index 000000000..ab81c19d3
--- /dev/null
+++ b/Examples/test-suite/javascript/nspace_extend_runme.js
@@ -0,0 +1,27 @@
+var nspace_extend = require("./nspace_extend");
+
+// constructors and destructors
+var color1 = new nspace_extend.Outer.Inner1.Color();
+var color = new nspace_extend.Outer.Inner1.Color(color1);
+delete color1;
+
+// class methods
+color.colorInstanceMethod(20.0);
+nspace_extend.Outer.Inner1.Color.colorStaticMethod(20.0);
+var created = nspace_extend.Outer.Inner1.Color.create();
+
+
+// constructors and destructors
+var color2 = new nspace_extend.Outer.Inner2.Color();
+color = new nspace_extend.Outer.Inner2.Color(color2);
+delete color2;
+
+// class methods
+color.colorInstanceMethod(20.0);
+nspace_extend.Outer.Inner2.Color.colorStaticMethod(20.0);
+created = nspace_extend.Outer.Inner2.Color.create();
+
+// Same class different namespaces
+var col1 = new nspace_extend.Outer.Inner1.Color();
+var col2 = nspace_extend.Outer.Inner2.Color.create();
+col2.colors(col1, col1, col2, col2, col2);
diff --git a/Examples/test-suite/javascript/nspace_runme.js b/Examples/test-suite/javascript/nspace_runme.js
new file mode 100644
index 000000000..f1afff428
--- /dev/null
+++ b/Examples/test-suite/javascript/nspace_runme.js
@@ -0,0 +1,76 @@
+var nspace = require("./nspace");
+
+var color1 = new nspace.Outer.Inner1.Color();
+var color = new nspace.Outer.Inner1.Color(color1);
+delete color1;
+
+// class methods
+color.colorInstanceMethod(20.0);
+nspace.Outer.Inner1.Color.colorStaticMethod(20.0);
+var created = nspace.Outer.Inner1.Color.create();
+
+// class enums
+var someClass = new nspace.Outer.SomeClass();
+var channel = someClass.GetInner1ColorChannel();
+if (channel != nspace.Outer.Inner1.Color.Transmission) {
+ throw new Error("Failed.");
+}
+
+// class anonymous enums
+var val1 = nspace.Outer.Inner1.Color.ColorEnumVal1;
+var val2 = nspace.Outer.Inner1.Color.ColorEnumVal2;
+if (val1 !== 0 || val2 !== 0x22) {
+ throw new Error("Failed.");
+}
+
+// instance member variables
+color.instanceMemberVariable = 123;
+if (color.instanceMemberVariable !== 123) {
+ throw new Error("Failed.");
+}
+
+// static member variables
+nspace.Outer.Inner1.Color.staticMemberVariable = 789;
+if (nspace.Outer.Inner1.Color.staticMemberVariable !== 789) {
+ throw new Error("Failed.");
+}
+
+if (nspace.Outer.Inner1.Color.staticConstMemberVariable !== 222) {
+ throw new Error("Failed.");
+}
+
+if (nspace.Outer.Inner1.Color.staticConstEnumMemberVariable !== nspace.Outer.Inner1.Color.Transmission) {
+ throw new Error("Failed.");
+}
+
+// Same class different namespaces
+var col1 = new nspace.Outer.Inner1.Color();
+var col2 = nspace.Outer.Inner2.Color.create();
+col2.colors(col1, col1, col2, col2, col2);
+
+nspace.Outer.Inner1.namespaceFunction(color);
+nspace.Outer.Inner1.namespaceVar = 111;
+if (nspace.Outer.Inner1.namespaceVar !== 111) {
+ throw new Error("Failed.");
+}
+
+// global enums
+var outerChannel1 = someClass.GetInner1Channel();
+if (outerChannel1 != nspace.Outer.Inner1.Transmission1) {
+ throw new Error("Failed.");
+}
+
+var outerChannel2 = someClass.GetInner2Channel();
+if (outerChannel2 !== nspace.Outer.Inner2.Transmission2) {
+ throw new Error("Failed.");
+}
+
+// turn feature off / ignoring
+var ns = new nspace.Outer.namespce();
+var nons = new nspace.NoNSpacePlease();
+
+// Derived class
+var blue3 = new nspace.Outer.Inner3.Blue();
+blue3.blueInstanceMethod();
+var blue4 = new nspace.Outer.Inner4.Blue();
+blue4.blueInstanceMethod();
diff --git a/Examples/test-suite/javascript/overload_copy_runme.js b/Examples/test-suite/javascript/overload_copy_runme.js
new file mode 100644
index 000000000..1039ffda1
--- /dev/null
+++ b/Examples/test-suite/javascript/overload_copy_runme.js
@@ -0,0 +1,4 @@
+var overload_copy = require("./overload_copy");
+
+f = new overload_copy.Foo();
+g = new overload_copy.Foo(f);
diff --git a/Examples/test-suite/javascript/preproc_include_runme.js b/Examples/test-suite/javascript/preproc_include_runme.js
new file mode 100644
index 000000000..4b827fbcc
--- /dev/null
+++ b/Examples/test-suite/javascript/preproc_include_runme.js
@@ -0,0 +1,23 @@
+var preproc_include = require("./preproc_include");
+
+if (preproc_include.multiply10(10) != 100)
+ throw "RuntimeError";
+
+if (preproc_include.multiply20(10) != 200)
+ throw "RuntimeError";
+
+if (preproc_include.multiply30(10) != 300)
+ throw "RuntimeError";
+
+if (preproc_include.multiply40(10) != 400)
+ throw "RuntimeError";
+
+if (preproc_include.multiply50(10) != 500)
+ throw "RuntimeError";
+
+if (preproc_include.multiply60(10) != 600)
+ throw "RuntimeError";
+
+if (preproc_include.multiply70(10) != 700)
+ throw "RuntimeError";
+
diff --git a/Examples/test-suite/javascript/preproc_runme.js b/Examples/test-suite/javascript/preproc_runme.js
new file mode 100644
index 000000000..669f9d1f0
--- /dev/null
+++ b/Examples/test-suite/javascript/preproc_runme.js
@@ -0,0 +1,14 @@
+var preproc = require("./preproc");
+
+if (preproc.endif != 1)
+ throw "RuntimeError";
+
+if (preproc.define != 1)
+ throw "RuntimeError";
+
+if (preproc.defined != 1)
+ throw "RuntimeError";
+
+if (2*preproc.one != preproc.two)
+ throw "RuntimeError";
+
diff --git a/Examples/test-suite/javascript/rename1_runme.js b/Examples/test-suite/javascript/rename1_runme.js
new file mode 100644
index 000000000..8374e6a89
--- /dev/null
+++ b/Examples/test-suite/javascript/rename1_runme.js
@@ -0,0 +1,68 @@
+var rename = require("./rename1");
+
+function part1() {
+ var xyz = new rename.XYZInt();
+ notxyz = new rename.NotXYZInt();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother2();
+ xyz.opT2();
+ xyz.tMethod2(0);
+ xyz.tMethodNotXYZ2(notxyz);
+ xyz.opNotXYZ2();
+ xyz.opXYZ2();
+}
+
+function part2() {
+ var xyz = new rename.XYZDouble();
+ var notxyz = new rename.NotXYZDouble();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother1();
+ xyz.opT1();
+ xyz.tMethod1(0);
+ xyz.tMethodNotXYZ1(notxyz);
+ xyz.opNotXYZ1();
+ xyz.opXYZ1();
+}
+
+function part3(){
+ var xyz = new rename.XYZKlass();
+ var notxyz = new rename.NotXYZKlass();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother3();
+ xyz.opT3();
+ xyz.tMethod3(new rename.Klass());
+ xyz.tMethodNotXYZ3(notxyz);
+ xyz.opNotXYZ3();
+ xyz.opXYZ3();
+}
+
+function part4() {
+ var xyz = new rename.XYZEnu();
+ var notxyz = new rename.NotXYZEnu();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother4();
+ xyz.opT4();
+ xyz.tMethod4(rename.En1);
+ xyz.tMethodNotXYZ4(notxyz);
+ xyz.opNotXYZ4();
+ xyz.opXYZ4();
+}
+
+function part5() {
+ var abc = new rename.ABC();
+ abc.methodABC(abc);
+ var k = new rename.Klass();
+ abc.methodKlass(k);
+ var a = abc.opABC();
+ k = abc.opKlass();
+}
+
+part1();
+part2();
+part3();
+part4();
+part5();
diff --git a/Examples/test-suite/javascript/rename2_runme.js b/Examples/test-suite/javascript/rename2_runme.js
new file mode 100644
index 000000000..bc6a95a59
--- /dev/null
+++ b/Examples/test-suite/javascript/rename2_runme.js
@@ -0,0 +1,68 @@
+var rename = require("./rename2");
+
+function part1() {
+ var xyz = new rename.XYZInt();
+ notxyz = new rename.NotXYZInt();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother2();
+ xyz.opT2();
+ xyz.tMethod2(0);
+ xyz.tMethodNotXYZ2(notxyz);
+ xyz.opNotXYZ2();
+ xyz.opXYZ2();
+}
+
+function part2() {
+ var xyz = new rename.XYZDouble();
+ var notxyz = new rename.NotXYZDouble();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother1();
+ xyz.opT1();
+ xyz.tMethod1(0);
+ xyz.tMethodNotXYZ1(notxyz);
+ xyz.opNotXYZ1();
+ xyz.opXYZ1();
+}
+
+function part3(){
+ var xyz = new rename.XYZKlass();
+ var notxyz = new rename.NotXYZKlass();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother3();
+ xyz.opT3();
+ xyz.tMethod3(new rename.Klass());
+ xyz.tMethodNotXYZ3(notxyz);
+ xyz.opNotXYZ3();
+ xyz.opXYZ3();
+}
+
+function part4() {
+ var xyz = new rename.XYZEnu();
+ var notxyz = new rename.NotXYZEnu();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother4();
+ xyz.opT4();
+ xyz.tMethod4(rename.En1);
+ xyz.tMethodNotXYZ4(notxyz);
+ xyz.opNotXYZ4();
+ xyz.opXYZ4();
+}
+
+function part5() {
+ var abc = new rename.ABC();
+ abc.methodABC(abc);
+ var k = new rename.Klass();
+ abc.methodKlass(k);
+ var a = abc.opABC();
+ k = abc.opKlass();
+}
+
+part1();
+part2();
+part3();
+part4();
+part5();
diff --git a/Examples/test-suite/javascript/rename3_runme.js b/Examples/test-suite/javascript/rename3_runme.js
new file mode 100644
index 000000000..9e57e80ea
--- /dev/null
+++ b/Examples/test-suite/javascript/rename3_runme.js
@@ -0,0 +1,68 @@
+var rename = require("./rename3");
+
+function part1() {
+ var xyz = new rename.XYZInt();
+ notxyz = new rename.NotXYZInt();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother2();
+ xyz.opT2();
+ xyz.tMethod2(0);
+ xyz.tMethodNotXYZ2(notxyz);
+ xyz.opNotXYZ2();
+ xyz.opXYZ2();
+}
+
+function part2() {
+ var xyz = new rename.XYZDouble();
+ var notxyz = new rename.NotXYZDouble();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother1();
+ xyz.opT1();
+ xyz.tMethod1(0);
+ xyz.tMethodNotXYZ1(notxyz);
+ xyz.opNotXYZ1();
+ xyz.opXYZ1();
+}
+
+function part3(){
+ var xyz = new rename.XYZKlass();
+ var notxyz = new rename.NotXYZKlass();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother3();
+ xyz.opT3();
+ xyz.tMethod3(new rename.Klass());
+ xyz.tMethodNotXYZ3(notxyz);
+ xyz.opNotXYZ3();
+ xyz.opXYZ3();
+}
+
+function part4() {
+ var xyz = new rename.XYZEnu();
+ var notxyz = new rename.NotXYZEnu();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother4();
+ xyz.opT4();
+ xyz.tMethod4(rename.En1);
+ xyz.tMethodNotXYZ4(notxyz);
+ xyz.opNotXYZ4();
+ xyz.opXYZ4();
+}
+
+function part5() {
+ var abc = new rename.ABC();
+ abc.methodABC(abc);
+ var k = new rename.Klass();
+ abc.methodKlass(k);
+ var a = abc.opABC();
+ k = abc.opKlass();
+}
+
+part1();
+part2();
+part3();
+part4();
+part5();
diff --git a/Examples/test-suite/javascript/rename4_runme.js b/Examples/test-suite/javascript/rename4_runme.js
new file mode 100644
index 000000000..d651fc7a1
--- /dev/null
+++ b/Examples/test-suite/javascript/rename4_runme.js
@@ -0,0 +1,68 @@
+var rename = require("./rename4");
+
+function part1() {
+ var xyz = new rename.XYZInt();
+ notxyz = new rename.NotXYZInt();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother2();
+ xyz.opT2();
+ xyz.tMethod2(0);
+ xyz.tMethodNotXYZ2(notxyz);
+ xyz.opNotXYZ2();
+ xyz.opXYZ2();
+}
+
+function part2() {
+ var xyz = new rename.XYZDouble();
+ var notxyz = new rename.NotXYZDouble();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother1();
+ xyz.opT1();
+ xyz.tMethod1(0);
+ xyz.tMethodNotXYZ1(notxyz);
+ xyz.opNotXYZ1();
+ xyz.opXYZ1();
+}
+
+function part3(){
+ var xyz = new rename.XYZKlass();
+ var notxyz = new rename.NotXYZKlass();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother3();
+ xyz.opT3();
+ xyz.tMethod3(new rename.Klass());
+ xyz.tMethodNotXYZ3(notxyz);
+ xyz.opNotXYZ3();
+ xyz.opXYZ3();
+}
+
+function part4() {
+ var xyz = new rename.XYZEnu();
+ var notxyz = new rename.NotXYZEnu();
+ xyz.opIntPtrA();
+ xyz.opIntPtrB();
+ xyz.opAnother4();
+ xyz.opT4();
+ xyz.tMethod4(rename.En1);
+ xyz.tMethodNotXYZ4(notxyz);
+ xyz.opNotXYZ4();
+ xyz.opXYZ4();
+}
+
+function part5() {
+ var abc = new rename.ABC();
+ abc.methodABC(abc);
+ var k = new rename.Klass();
+ abc.methodKlass(k);
+ var a = abc.opABC();
+ k = abc.opKlass();
+}
+
+part1();
+part2();
+part3();
+part4();
+part5();
diff --git a/Examples/test-suite/javascript/rename_scope_runme.js b/Examples/test-suite/javascript/rename_scope_runme.js
new file mode 100644
index 000000000..c0226df69
--- /dev/null
+++ b/Examples/test-suite/javascript/rename_scope_runme.js
@@ -0,0 +1,17 @@
+var rename_scope = require("./rename_scope");
+
+var a = new rename_scope.Natural_UP();
+var b = new rename_scope.Natural_BP();
+
+if (a.rtest() !== 1) {
+ throw new Error("a.rtest(): Expected 1, was " + a.rtest());
+}
+
+if (b.rtest() !== 1) {
+ throw new Error("b.rtest(): Expected 1, was " + b.rtest());
+}
+
+var f = rename_scope.equals;
+if (f === undefined) {
+ throw new Error("Equality operator has not been renamed.");
+}
diff --git a/Examples/test-suite/javascript/rename_simple_runme.js b/Examples/test-suite/javascript/rename_simple_runme.js
new file mode 100644
index 000000000..918dd68a5
--- /dev/null
+++ b/Examples/test-suite/javascript/rename_simple_runme.js
@@ -0,0 +1,50 @@
+var rename_simple = require("./rename_simple");
+var NewStruct = rename_simple.NewStruct;
+
+var s = new NewStruct();
+
+// renamed instance variable
+if (s.NewInstanceVariable !== 111) {
+ throw new Error("NewInstanceVariable: Expected 111, was " + s.NewInstanceVariable);
+}
+
+// renamed instance method
+if (s.NewInstanceMethod() !== 222) {
+ throw new Error("NewInstanceMethod(): Expected 222, was " + s.NewInstanceMethod());
+}
+
+// renamed static method
+if (NewStruct.NewStaticMethod() !== 333) {
+ throw new Error("NewInstanceMethod(): Expected 333, was " + NewStruct.NewStaticMethod());
+}
+
+// renamed static variable
+if (NewStruct.NewStaticVariable !== 444) {
+ throw new Error("NewInstanceMethod(): Expected 444, was " + NewStruct.NewStaticVariable);
+}
+
+// renamed global function
+if (rename_simple.NewFunction() !== 555) {
+ throw new Error("rename_simple.NewFunction(): Expected 555, was " + rename_simple.NewFunction());
+}
+
+// renamed global variable
+if (rename_simple.NewGlobalVariable !== 666) {
+ throw new Error("rename_simple.NewGlobalVariable: Expected 666, was " + rename_simple.NewGlobalVariable);
+}
+
+// setting renamed variables
+s.NewInstanceVariable = 1111;
+if (s.NewInstanceVariable !== 1111) {
+ throw new Error("NewInstanceVariable: Expected 1111, was " + s.NewInstanceVariable);
+}
+
+NewStruct.NewStaticVariable = 4444;
+if (NewStruct.NewStaticVariable !== 4444) {
+ throw new Error("NewInstanceMethod(): Expected 4444, was " + NewStruct.NewStaticVariable);
+}
+
+rename_simple.NewGlobalVariable = 6666;
+if (rename_simple.NewGlobalVariable !== 6666) {
+ throw new Error("rename_simple.NewGlobalVariable: Expected 6666, was " + rename_simple.NewGlobalVariable);
+}
diff --git a/Examples/test-suite/javascript/ret_by_value_runme.js b/Examples/test-suite/javascript/ret_by_value_runme.js
new file mode 100644
index 000000000..d9a77a20b
--- /dev/null
+++ b/Examples/test-suite/javascript/ret_by_value_runme.js
@@ -0,0 +1,8 @@
+var ret_by_value = require("./ret_by_value");
+
+a = ret_by_value.get_test();
+if (a.myInt != 100)
+ throw "RuntimeError";
+
+if (a.myShort != 200)
+ throw "RuntimeError";
diff --git a/Examples/test-suite/javascript/setup_test.sh b/Examples/test-suite/javascript/setup_test.sh
new file mode 100644
index 000000000..913a74c4b
--- /dev/null
+++ b/Examples/test-suite/javascript/setup_test.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+if [ ! -d $1 ]; then
+ mkdir $1;
+fi
+sed -e "s/\$testcase/$1/" -e "s/\$cflags/$2/" < node_template/binding.gyp.in > $1/binding.gyp
+sed s/\$testcase/$1/ node_template/index.js.in > $1/index.js
diff --git a/Examples/test-suite/javascript/string_simple_runme.js b/Examples/test-suite/javascript/string_simple_runme.js
new file mode 100644
index 000000000..dbdd4136d
--- /dev/null
+++ b/Examples/test-suite/javascript/string_simple_runme.js
@@ -0,0 +1,10 @@
+var string_simple = require("./string_simple");
+
+// Test unicode string
+var str = "olé";
+
+var copy = string_simple.copy_string(str);
+
+if (str !== copy) {
+ throw "Error: copy is not equal: original="+str+", copy="+copy;
+}
diff --git a/Examples/test-suite/javascript/struct_value_runme.js b/Examples/test-suite/javascript/struct_value_runme.js
new file mode 100644
index 000000000..d6b26f726
--- /dev/null
+++ b/Examples/test-suite/javascript/struct_value_runme.js
@@ -0,0 +1,11 @@
+var struct_value = require("./struct_value");
+
+b = new struct_value.Bar();
+
+b.a.x = 3;
+if (b.a.x != 3)
+throw "RuntimeError";
+
+b.b.x = 3;
+if (b.b.x != 3)
+throw "RuntimeError"
diff --git a/Examples/test-suite/javascript/template_static_runme.js b/Examples/test-suite/javascript/template_static_runme.js
new file mode 100644
index 000000000..477d97249
--- /dev/null
+++ b/Examples/test-suite/javascript/template_static_runme.js
@@ -0,0 +1,3 @@
+var template_static = require("./template_static");
+
+template_static.Foo.bar_double(1);
diff --git a/Examples/test-suite/javascript/typedef_class_runme.js b/Examples/test-suite/javascript/typedef_class_runme.js
new file mode 100644
index 000000000..3e4dc9093
--- /dev/null
+++ b/Examples/test-suite/javascript/typedef_class_runme.js
@@ -0,0 +1,7 @@
+var typedef_class = require("./typedef_class");
+
+a = new typedef_class.RealA();
+a.a = 3;
+
+b = new typedef_class.B();
+b.testA(a);
diff --git a/Examples/test-suite/javascript/typedef_inherit_runme.js b/Examples/test-suite/javascript/typedef_inherit_runme.js
new file mode 100644
index 000000000..4abcc2536
--- /dev/null
+++ b/Examples/test-suite/javascript/typedef_inherit_runme.js
@@ -0,0 +1,23 @@
+var typedef_inherit = require("./typedef_inherit");
+
+a = new typedef_inherit.Foo();
+b = new typedef_inherit.Bar();
+
+x = typedef_inherit.do_blah(a);
+if (x != "Foo::blah")
+ print("Whoa! Bad return" + x);
+
+x = typedef_inherit.do_blah(b);
+if (x != "Bar::blah")
+ print("Whoa! Bad return" + x);
+
+c = new typedef_inherit.Spam();
+d = new typedef_inherit.Grok();
+
+x = typedef_inherit.do_blah2(c);
+if (x != "Spam::blah")
+ print("Whoa! Bad return" + x);
+
+x = typedef_inherit.do_blah2(d);
+if (x != "Grok::blah")
+ print ("Whoa! Bad return" + x);
diff --git a/Examples/test-suite/javascript/typedef_scope_runme.js b/Examples/test-suite/javascript/typedef_scope_runme.js
new file mode 100644
index 000000000..0ac56884c
--- /dev/null
+++ b/Examples/test-suite/javascript/typedef_scope_runme.js
@@ -0,0 +1,12 @@
+var typedef_scope = require("./typedef_scope");
+
+b = new typedef_scope.Bar();
+x = b.test1(42,"hello");
+if (x != 42)
+ print("Failed!!");
+
+x = b.test2(42,"hello");
+if (x != "hello")
+ print("Failed!!");
+
+
diff --git a/Examples/test-suite/javascript/typemap_arrays_runme.js b/Examples/test-suite/javascript/typemap_arrays_runme.js
new file mode 100644
index 000000000..cd6827ac9
--- /dev/null
+++ b/Examples/test-suite/javascript/typemap_arrays_runme.js
@@ -0,0 +1,5 @@
+var typemap_arrays = require("./typemap_arrays");
+
+if (typemap_arrays.sumA(null) != 60)
+ throw "RuntimeError, Sum is wrong";
+
diff --git a/Examples/test-suite/javascript/typemap_delete_runme.js b/Examples/test-suite/javascript/typemap_delete_runme.js
new file mode 100644
index 000000000..4b3174956
--- /dev/null
+++ b/Examples/test-suite/javascript/typemap_delete_runme.js
@@ -0,0 +1,5 @@
+var typemap_delete = require("./typemap_delete");
+
+r = new typemap_delete.Rect(123);
+if (r.val != 123)
+ throw "RuntimeError";
diff --git a/Examples/test-suite/javascript/typemap_namespace_runme.js b/Examples/test-suite/javascript/typemap_namespace_runme.js
new file mode 100644
index 000000000..614e0ffeb
--- /dev/null
+++ b/Examples/test-suite/javascript/typemap_namespace_runme.js
@@ -0,0 +1,7 @@
+var typemap_namespace = require("./typemap_namespace");
+
+if (typemap_namespace.test1("hello") != "hello")
+ throw "RuntimeError";
+
+if (typemap_namespace.test2("hello") != "hello")
+ throw "RuntimeError";
diff --git a/Examples/test-suite/javascript/typemap_ns_using_runme.js b/Examples/test-suite/javascript/typemap_ns_using_runme.js
new file mode 100644
index 000000000..9115c16ae
--- /dev/null
+++ b/Examples/test-suite/javascript/typemap_ns_using_runme.js
@@ -0,0 +1,4 @@
+var typemap_ns_using = require("./typemap_ns_using");
+
+if (typemap_ns_using.spam(37) != 37)
+ throw "RuntimeError";
diff --git a/Examples/test-suite/javascript/using1_runme.js b/Examples/test-suite/javascript/using1_runme.js
new file mode 100644
index 000000000..a2e37fcb6
--- /dev/null
+++ b/Examples/test-suite/javascript/using1_runme.js
@@ -0,0 +1,4 @@
+var using1 = require("./using1");
+
+if (using1.spam(37) != 37)
+ throw "RuntimeError";
diff --git a/Examples/test-suite/javascript/using2_runme.js b/Examples/test-suite/javascript/using2_runme.js
new file mode 100644
index 000000000..aa5e9b15f
--- /dev/null
+++ b/Examples/test-suite/javascript/using2_runme.js
@@ -0,0 +1,4 @@
+var using2 = require("./using2");
+
+if (using2.spam(37) != 37)
+ throw "RuntimeError";
diff --git a/Examples/test-suite/javascript/varargs_runme.js b/Examples/test-suite/javascript/varargs_runme.js
new file mode 100644
index 000000000..69d761e63
--- /dev/null
+++ b/Examples/test-suite/javascript/varargs_runme.js
@@ -0,0 +1,44 @@
+var varargs = require("./varargs");
+
+if (varargs.test("Hello") != "Hello") {
+ throw new Error("Failed");
+}
+
+var f = new varargs.Foo("Greetings")
+if (f.str != "Greetings") {
+ throw new Error("Failed");
+}
+
+if (f.test("Hello") != "Hello") {
+ throw new Error("Failed");
+}
+
+if (varargs.test_def("Hello",1) != "Hello") {
+ throw new Error("Failed");
+}
+
+if (varargs.test_def("Hello") != "Hello") {
+ throw new Error("Failed");
+}
+
+if (varargs.test_plenty("Hello") != "Hello") {
+ throw new Error("Failed");
+}
+
+if (varargs.test_plenty("Hello", 1) != "Hello") {
+ throw new Error("Failed");
+}
+
+if (varargs.test_plenty("Hello", 1, 2) != "Hello") {
+ throw new Error("Failed");
+}
+
+var thrown = false;
+try {
+ varargs.test_plenty("Hello", 1, 2, 3);
+} catch (err) {
+ thrown = true;
+}
+if (!thrown) {
+ throw new Error("Failed");
+}
diff --git a/Examples/test-suite/lua/cpp_basic_runme.lua b/Examples/test-suite/lua/cpp_basic_runme.lua
index 8a72f1bad..c7e0325c5 100644
--- a/Examples/test-suite/lua/cpp_basic_runme.lua
+++ b/Examples/test-suite/lua/cpp_basic_runme.lua
@@ -76,3 +76,13 @@ assert(cb.test_func_ptr(f,2)==-8)
-- Test that __tostring metamethod produce no internal asserts
f2_name = tostring(f2)
+
+f3 = cb.FooSub()
+f3_name = tostring(f3)
+
+f4 = cb.FooSubSub()
+f4_name = tostring(f4)
+
+assert( f2_name == "Foo" )
+assert( f3_name == "Foo" )
+assert( f4_name == "FooSubSub" )
diff --git a/Examples/test-suite/lua/operator_overload_runme.lua b/Examples/test-suite/lua/operator_overload_runme.lua
index 983daa1e5..5ba06ff08 100644
--- a/Examples/test-suite/lua/operator_overload_runme.lua
+++ b/Examples/test-suite/lua/operator_overload_runme.lua
@@ -78,6 +78,38 @@ assert(i(1,2)==6)
assert(tostring(Op(1))=="Op(1)")
assert(tostring(Op(-3))=="Op(-3)")
+
+-- check that operator overloads are correctly propogated down inheritance hierarchy
+
+a_d=OpDerived()
+b_d=OpDerived(5)
+c_d=OpDerived(5)
+d_d=OpDerived(2)
+-- test equality
+assert(a_d~=b_d)
+assert(b_d==c_d)
+assert(a_d~=d_d)
+
+-- test <
+assert(a_d<b_d)
+assert(a_d<=b_d)
+assert(b_d<=c_d)
+assert(b_d>=c_d)
+assert(b_d>d_d)
+assert(b_d>=d_d)
+--
+-- test + inheritance
+f_d=OpDerived(1)
+g_d=OpDerived(1)
+assert(f_d+g_d==Op(2))
+assert(f_d-g_d==Op(0))
+assert(f_d*g_d==Op(1))
+assert(f_d/g_d==Op(1))
+--
+-- plus add some code to check the __str__ fn inheritance
+assert(tostring(OpDerived(1))=="Op(1)")
+assert(tostring(OpDerived(-3))=="Op(-3)")
+
--[[
/* Sample test code in C++
diff --git a/Examples/test-suite/nspace.i b/Examples/test-suite/nspace.i
index 1520b3652..25e7104b2 100644
--- a/Examples/test-suite/nspace.i
+++ b/Examples/test-suite/nspace.i
@@ -2,7 +2,7 @@
%module nspace
// nspace feature only supported by these languages
-#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGLUA)
+#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGLUA) || defined(SWIGJAVASCRIPT)
#if defined(SWIGJAVA)
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
diff --git a/Examples/test-suite/nspace_extend.i b/Examples/test-suite/nspace_extend.i
index e92ff8c1d..2f7c6fbe1 100644
--- a/Examples/test-suite/nspace_extend.i
+++ b/Examples/test-suite/nspace_extend.i
@@ -2,7 +2,7 @@
%module nspace_extend
// nspace feature only supported by these languages
-#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGLUA)
+#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD) || defined(SWIGLUA) || defined(SWIGJAVASCRIPT)
#if defined(SWIGJAVA)
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
diff --git a/Examples/test-suite/operator_overload.i b/Examples/test-suite/operator_overload.i
index 006662109..061e7024c 100644
--- a/Examples/test-suite/operator_overload.i
+++ b/Examples/test-suite/operator_overload.i
@@ -230,10 +230,10 @@ __rshift__,__lshift__ >>,<<
__getitem__,__setitem__ for operator[]
-Operators overloaded without C++ equivilents
+Operators overloaded without C++ equivalents
__pow__ for power operator
__str__ converts object to a string (should return a const char*)
-__concat__ for contatenation (if language supports)
+__concat__ for concatenation (if language supports)
*/
diff --git a/Examples/test-suite/php/arrays_runme.php b/Examples/test-suite/php/arrays_runme.php
index 23490e61e..ae17d05e7 100644
--- a/Examples/test-suite/php/arrays_runme.php
+++ b/Examples/test-suite/php/arrays_runme.php
@@ -12,6 +12,7 @@ check::classname(simplestruct,$ss);
$as=new arraystruct();
$as->array_c="abc";
check::equal($as->array_c,"a",'$as->array_c=="a"');
+check::equal(isset($as->array_const_i),TRUE,'isset($as->array_const_i)');
check::done();
?>
diff --git a/Examples/test-suite/string_simple.i b/Examples/test-suite/string_simple.i
new file mode 100644
index 000000000..c319aa1ef
--- /dev/null
+++ b/Examples/test-suite/string_simple.i
@@ -0,0 +1,13 @@
+%module string_simple
+
+%newobject copy_string;
+
+%inline %{
+#include <string.h>
+const char* copy_string(const char* str) {
+ size_t len = strlen(str);
+ char* newstring = (char*) malloc(len + 1);
+ strcpy(newstring, str);
+ return newstring;
+}
+%}
diff --git a/Lib/exception.i b/Lib/exception.i
index 050042dab..437eee6f0 100644
--- a/Lib/exception.i
+++ b/Lib/exception.i
@@ -15,7 +15,7 @@
#ifdef SWIGPHP
%{
#include "zend_exceptions.h"
-#define SWIG_exception(code, msg) { zend_throw_exception(NULL, (char*)msg, code TSRMLS_CC); }
+#define SWIG_exception(code, msg) zend_throw_exception(NULL, (char*)msg, code TSRMLS_CC)
%}
#endif
diff --git a/Lib/inttypes.i b/Lib/inttypes.i
index 8450cb840..85bd5adaf 100644
--- a/Lib/inttypes.i
+++ b/Lib/inttypes.i
@@ -41,12 +41,6 @@ extern "C" {
/* Return the `imaxdiv_t' representation of the value of NUMER over DENOM. */
extern imaxdiv_t imaxdiv (intmax_t numer, intmax_t denom);
- /* Like `strtol' but convert to `intmax_t'. */
- extern intmax_t strtoimax (const char *nptr, char **endptr, int base);
-
- /* Like `strtoul' but convert to `uintmax_t'. */
- extern uintmax_t strtoumax (const char *nptr, char ** endptr, int base);
-
#ifdef SWIG_WCHAR
/* Like `wcstol' but convert to `intmax_t'. */
extern intmax_t wcstoimax (const wchar_t *nptr, wchar_t **endptr, int base);
@@ -84,7 +78,7 @@ extern "C" {
extern uintmax_t wcstoumax (const wchar_t *nptr, wchar_t **endptr, int base);
#endif
-#endif /* SWIGWORDSIZE32 */
+#endif /* SWIGWORDSIZE64 */
#ifdef __cplusplus
}
diff --git a/Lib/javascript/jsc/arrays_javascript.i b/Lib/javascript/jsc/arrays_javascript.i
new file mode 100644
index 000000000..b9199d86b
--- /dev/null
+++ b/Lib/javascript/jsc/arrays_javascript.i
@@ -0,0 +1,123 @@
+/* -----------------------------------------------------------------------------
+ * arrays_javascript.i
+ *
+ * These typemaps give more natural support for arrays. The typemaps are not efficient
+ * as there is a lot of copying of the array values whenever the array is passed to C/C++
+ * from JavaScript and vice versa. The JavaScript array is expected to be the same size as the C array.
+ * An exception is thrown if they are not.
+ *
+ * Example usage:
+ * Wrapping:
+ *
+ * %include <arrays_javascript.i>
+ * %inline %{
+ * extern int FiddleSticks[3];
+ * %}
+ *
+ * Use from JavaScript like this:
+ *
+ * var fs = [10, 11, 12];
+ * example.FiddleSticks = fs;
+ * fs = example.FiddleSticks;
+ * ----------------------------------------------------------------------------- */
+
+%fragment("SWIG_JSCGetIntProperty", "header", fragment=SWIG_AsVal_frag(int)) {}
+%fragment("SWIG_JSCGetNumberProperty", "header", fragment=SWIG_AsVal_frag(double)) {}
+
+%typemap(in, fragment="SWIG_JSCGetIntProperty") int[], int[ANY]
+ (int length = 0, JSObjectRef array, JSValueRef jsvalue, int i = 0, int res = 0, $*1_ltype temp) {
+ if (JSValueIsObject(context, $input))
+ {
+ // Convert into Array
+ array = JSValueToObject(context, $input, NULL);
+
+ length = $1_dim0;
+
+ $1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length);
+
+ // Get each element from array
+ for (i = 0; i < length; i++)
+ {
+ jsvalue = JSObjectGetPropertyAtIndex(context, array, i, NULL);
+
+ // Get primitive value from JSObject
+ res = SWIG_AsVal(int)(jsvalue, &temp);
+ if (!SWIG_IsOK(res))
+ {
+ SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double");
+ }
+ arg$argnum[i] = temp;
+ }
+
+ }
+ else
+ {
+ SWIG_exception_fail(SWIG_ERROR, "$input is not JSObjectRef");
+ }
+}
+
+%typemap(freearg) int[], int[ANY] {
+ free($1);
+}
+
+%typemap(out, fragment=SWIG_From_frag(int)) int[], int[ANY] (int length = 0, int i = 0)
+{
+ length = $1_dim0;
+ JSValueRef values[length];
+
+ for (i = 0; i < length; i++)
+ {
+ values[i] = SWIG_From(int)($1[i]);
+ }
+
+ $result = JSObjectMakeArray(context, length, values, NULL);
+}
+
+%typemap(in, fragment="SWIG_JSCGetNumberProperty") double[], double[ANY]
+ (int length = 0, JSObjectRef array, JSValueRef jsvalue, int i = 0, int res = 0, $*1_ltype temp) {
+ if (JSValueIsObject(context, $input))
+ {
+ // Convert into Array
+ array = JSValueToObject(context, $input, NULL);
+
+ length = $1_dim0;
+
+ $1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length);
+
+ // Get each element from array
+ for (i = 0; i < length; i++)
+ {
+ jsvalue = JSObjectGetPropertyAtIndex(context, array, i, NULL);
+
+ // Get primitive value from JSObject
+ res = SWIG_AsVal(double)(jsvalue, &temp);
+ if (!SWIG_IsOK(res))
+ {
+ SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double");
+ }
+ arg$argnum[i] = temp;
+ }
+
+ }
+ else
+ {
+ SWIG_exception_fail(SWIG_ERROR, "$input is not JSObjectRef");
+ }
+}
+
+%typemap(freearg) double[], double[ANY] {
+ free($1);
+}
+
+%typemap(out, fragment=SWIG_From_frag(double)) double[], double[ANY] (int length = 0, int i = 0)
+{
+ length = $1_dim0;
+ JSValueRef values[length];
+
+ for (i = 0; i < length; i++)
+ {
+ values[i] = SWIG_From(double)($1[i]);
+ }
+
+ $result = JSObjectMakeArray(context, length, values, NULL);
+}
diff --git a/Lib/javascript/jsc/ccomplex.i b/Lib/javascript/jsc/ccomplex.i
new file mode 100644
index 000000000..50f0f95fe
--- /dev/null
+++ b/Lib/javascript/jsc/ccomplex.i
@@ -0,0 +1,26 @@
+/* -----------------------------------------------------------------------------
+ * ccomplex.i
+ *
+ * C complex typemaps
+ * ISO C99: 7.3 Complex arithmetic <complex.h>
+ * ----------------------------------------------------------------------------- */
+
+
+%include <javascriptcomplex.swg>
+
+%{
+#include <complex.h>
+%}
+
+
+/* C complex constructor */
+#define CCplxConst(r, i) ((r) + I*(i))
+
+%swig_cplxflt_convn(float complex, CCplxConst, creal, cimag);
+%swig_cplxdbl_convn(double complex, CCplxConst, creal, cimag);
+%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
+
+/* declaring the typemaps */
+%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);
diff --git a/Lib/javascript/jsc/cdata.i b/Lib/javascript/jsc/cdata.i
new file mode 100644
index 000000000..367965990
--- /dev/null
+++ b/Lib/javascript/jsc/cdata.i
@@ -0,0 +1 @@
+%include <typemaps/cdata.swg>
diff --git a/Lib/javascript/jsc/complex.i b/Lib/javascript/jsc/complex.i
new file mode 100644
index 000000000..4c3b3c5e2
--- /dev/null
+++ b/Lib/javascript/jsc/complex.i
@@ -0,0 +1,6 @@
+#ifdef __cplusplus
+%include <std_complex.i>
+#else
+%include <ccomplex.i>
+#endif
+
diff --git a/Lib/javascript/jsc/exception.i b/Lib/javascript/jsc/exception.i
new file mode 100644
index 000000000..0246cfde8
--- /dev/null
+++ b/Lib/javascript/jsc/exception.i
@@ -0,0 +1 @@
+%include <typemaps/exception.swg>
diff --git a/Lib/javascript/jsc/javascript.swg b/Lib/javascript/jsc/javascript.swg
new file mode 100644
index 000000000..3a83b6495
--- /dev/null
+++ b/Lib/javascript/jsc/javascript.swg
@@ -0,0 +1,19 @@
+/* -----------------------------------------------------------------------------
+ * javascript.swg
+ *
+ * Javascript typemaps
+ * ----------------------------------------------------------------------------- */
+
+%include <typemaps/swigmacros.swg>
+
+%include <javascripttypemaps.swg>
+
+%include <javascriptruntime.swg>
+
+%include <javascripthelpers.swg>
+
+%include <javascriptkw.swg>
+
+%include <javascriptcode.swg>
+
+%include <javascriptinit.swg>
diff --git a/Lib/javascript/jsc/javascriptcode.swg b/Lib/javascript/jsc/javascriptcode.swg
new file mode 100644
index 000000000..738b54d70
--- /dev/null
+++ b/Lib/javascript/jsc/javascriptcode.swg
@@ -0,0 +1,418 @@
+/* -----------------------------------------------------------------------------
+ * js_ctor: template for wrapping a ctor.
+ * - $jswrapper: wrapper of called ctor
+ * - $jslocals: locals part of wrapper
+ * - $jscode: code part of wrapper
+ * - $jsargcount: number of arguments
+ * - $jsmangledtype: mangled type of class
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_ctor", "templates")
+%{
+JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
+{
+ $jslocals
+ if(argc != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
+
+ $jscode
+ return SWIG_JSC_NewPointerObj(context, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN);
+ goto fail;
+ fail:
+ return NULL;
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_veto_ctor: a vetoing ctor for abstract classes
+ * - $jswrapper: name of wrapper
+ * - $jsname: class name
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_veto_ctor", "templates")
+%{
+JSObjectRef $jswrapper(JSContextRef context, JSObjectRef ctorObject,
+ size_t argc, const JSValueRef argv[], JSValueRef* exception)
+{
+ SWIG_exception(SWIG_ERROR, "Class $jsname can not be instantiated");
+ return 0;
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_ctor_dispatcher: dispatcher for overloaded constructors
+ * - $jswrapper: name of wrapper
+ * - $jsname: class name
+ * - $jsdispatchcases: part containing code for dispatching
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_ctor_dispatcher", "templates")
+%{
+JSObjectRef $jswrapper(JSContextRef context, JSObjectRef ctorObject,
+ size_t argc, const JSValueRef argv[], JSValueRef* exception)
+{
+ JSObjectRef thisObject = NULL;
+
+ // switch all cases by means of series of if-returns.
+ $jsdispatchcases
+
+ // default:
+ SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for construction of $jsname");
+
+ fail:
+ return thisObject;
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_overloaded_ctor: template for wrapping a ctor.
+ * - $jswrapper: wrapper of called ctor
+ * - $jslocals: locals part of wrapper
+ * - $jscode: code part of wrapper
+ * - $jsargcount: number of arguments
+ * - $jsmangledtype: mangled type of class
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_overloaded_ctor", "templates")
+%{
+JSObjectRef $jswrapper(JSContextRef context, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
+{
+ $jslocals
+ $jscode
+ return SWIG_JSC_NewPointerObj(context, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN);
+
+ goto fail;
+ fail:
+ return NULL;
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_ctor_dispatch_case: template for a dispatch case for calling an overloaded ctor.
+ * - $jsargcount: number of arguments of called ctor
+ * - $jswrapper: wrapper of called ctor
+ *
+ * Note: a try-catch-like mechanism is used to switch cases
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_ctor_dispatch_case", "templates")
+%{
+ if(argc == $jsargcount) {
+ thisObject = $jswrapper(context, NULL, argc, argv, exception);
+ if(thisObject != NULL) { *exception=0; return thisObject; } /* reset exception and return */
+ }
+%}
+
+
+/* -----------------------------------------------------------------------------
+ * js_dtor: template for a destructor wrapper
+ * - $jsmangledname: mangled class name
+ * - $jstype: class type
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_dtor", "templates")
+%{
+void $jswrapper(JSObjectRef thisObject)
+{
+ SwigPrivData* t = (SwigPrivData*) JSObjectGetPrivate(thisObject);
+ if(t && t->swigCMemOwn) free (($jstype)t->swigCObject);
+ if(t) free(t);
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_dtor: template for a destructor wrapper
+ * - $jsmangledname: mangled class name
+ * - $jstype: class type
+ * - ${destructor_action}: The custom destructor action to invoke.
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_dtoroverride", "templates")
+%{
+void $jswrapper(JSObjectRef thisObject)
+{
+ SwigPrivData* t = (SwigPrivData*) JSObjectGetPrivate(thisObject);
+ if(t && t->swigCMemOwn) {
+ $jstype arg1 = ($jstype)t->swigCObject;
+ ${destructor_action}
+ }
+ if(t) free(t);
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_getter: template for getter function wrappers
+ * - $jswrapper: wrapper function name
+ * - $jslocals: locals part of wrapper
+ * - $jscode: code part of wrapper
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_getter", "templates")
+%{
+JSValueRef $jswrapper(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
+{
+ $jslocals
+ JSValueRef jsresult;
+
+ $jscode
+ return jsresult;
+
+ goto fail;
+ fail:
+ return NULL;
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_setter: template for setter function wrappers
+ * - $jswrapper: wrapper function name
+ * - $jslocals: locals part of wrapper
+ * - $jscode: code part of wrapper
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_setter", "templates")
+%{
+bool $jswrapper(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
+{
+ $jslocals
+ $jscode
+
+ return true;
+
+ goto fail;
+ fail:
+ return false;
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_function: template for function wrappers
+ * - $jswrapper: wrapper function name
+ * - $jslocals: locals part of wrapper
+ * - $jscode: code part of wrapper
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_function", "templates")
+%{
+JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
+{
+ $jslocals
+ JSValueRef jsresult;
+
+ if(argc != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
+
+ $jscode
+ return jsresult;
+
+ goto fail;
+ fail:
+ return NULL;
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_function_dispatcher: template for a function dispatcher for overloaded functions
+ * - $jswrapper: wrapper function name
+ * - $jsname: name of the wrapped function
+ * - $jslocals: locals part of wrapper
+ * - $jscode: code part of wrapper
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_function_dispatcher", "templates")
+%{
+JSValueRef $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
+{
+ $jslocals
+ JSValueRef jsresult;
+ int res;
+ $jscode
+
+ SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for function $jsname.");
+ return jsresult;
+
+ goto fail;
+ fail:
+ return NULL;
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_overloaded_function: template for a overloaded function
+ * - $jswrapper: wrapper function name
+ * - $jslocals: locals part of wrapper
+ * - $jscode: code part of wrapper
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_overloaded_function", "templates")
+%{
+int $jswrapper(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception, JSValueRef* p_result)
+{
+ $jslocals
+ JSValueRef jsresult;
+
+ if(argc != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
+
+ $jscode
+ *p_result = jsresult;
+ return SWIG_OK;
+
+ goto fail;
+ fail:
+ return SWIG_TypeError;
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_function_dispatch_case: template for a case used in the function dispatcher
+ * - $jswrapper: wrapper function name
+ * - $jsargcount: number of arguments of overloaded function
+ * - $jscode: code part of wrapper
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_function_dispatch_case", "templates")
+%{
+ if(argc == $jsargcount) {
+ res = $jswrapper(context, function, thisObject, argc, argv, exception, &jsresult);
+ if(res == SWIG_OK) { *exception = 0; return jsresult; }
+ }
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsc_variable_declaration: template for a variable table entry
+ * - $jsname: name of the variable
+ * - $jsgetter: wrapper of getter function
+ * - $jssetter: wrapper of setter function
+ * ----------------------------------------------------------------------------- */
+%fragment ("jsc_variable_declaration", "templates")
+%{
+ {"$jsname", $jsgetter, $jssetter, kJSPropertyAttributeNone},
+%}
+
+
+/* -----------------------------------------------------------------------------
+ * jsc_function_declaration: template for a function table entry
+ * - $jsname: name of the variable
+ * - $jswrapper: wrapper function
+ * ----------------------------------------------------------------------------- */
+%fragment ("jsc_function_declaration", "templates")
+%{
+ {"$jsname", $jswrapper, kJSPropertyAttributeNone},
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsc_classtemplate_declaration: template for a namespace declaration
+ * - $jsmangledname: mangled class name
+ * ----------------------------------------------------------------------------- */
+%fragment ("jsc_class_declaration", "templates")
+%{
+JSClassDefinition $jsmangledname_classDefinition;
+
+JSClassDefinition $jsmangledname_objectDefinition;
+
+JSClassRef $jsmangledname_classRef;
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsc_class_tables: template for a namespace declaration
+ * - $jsmangledname: mangled class name
+ * - $jsstaticclassvariables: list of static variable entries
+ * - $jsstaticclassfunctions: list of static function entries
+ * - $jsclassvariables: list of member variable entries
+ * - $jsclassfunctions: list of member function entries
+ * ----------------------------------------------------------------------------- */
+%fragment ("jsc_class_tables", "templates")
+%{
+JSStaticValue $jsmangledname_staticValues[] = {
+ $jsstaticclassvariables
+ { 0, 0, 0, 0 }
+};
+
+JSStaticFunction $jsmangledname_staticFunctions[] = {
+ $jsstaticclassfunctions
+ { 0, 0, 0 }
+};
+
+JSStaticValue $jsmangledname_values[] = {
+ $jsclassvariables
+ { 0, 0, 0, 0 }
+};
+
+JSStaticFunction $jsmangledname_functions[] = {
+ $jsclassfunctions
+ { 0, 0, 0 }
+};
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsc_define_class_template: template for defining a class template
+ * - $jsmangledname: mangled class name
+ * - $jsmangledtype: mangled class type
+ * - $jsctor: wrapper of ctor
+ * - $jsbaseclass: mangled name of base class
+ * ----------------------------------------------------------------------------- */
+%fragment ("jsc_class_definition", "templates")
+%{
+ $jsmangledname_classDefinition.staticFunctions = $jsmangledname_staticFunctions;
+ $jsmangledname_classDefinition.staticValues = $jsmangledname_staticValues;
+ $jsmangledname_classDefinition.callAsConstructor = $jsctor;
+ $jsmangledname_classDefinition.finalize = $jsdtor;
+ $jsmangledname_objectDefinition.staticValues = $jsmangledname_values;
+ $jsmangledname_objectDefinition.staticFunctions = $jsmangledname_functions;
+ $jsclass_inheritance
+ JSClassRef $jsmangledname_classRef = JSClassCreate(&$jsmangledname_objectDefinition);
+ SWIGTYPE_$jsmangledtype->clientdata = $jsmangledname_classRef;
+%}
+
+%fragment ("jsc_class_inherit", templates)
+%{
+ if (SWIGTYPE_p$jsbaseclassmangled != NULL) {
+ $jsmangledname_objectDefinition.parentClass = (JSClassRef) SWIGTYPE_p$jsbaseclassmangled->clientdata;
+ }
+%}
+
+%fragment ("jsc_class_noinherit", templates)
+%{
+ $jsmangledname_objectDefinition.parentClass = _SwigObject_classRef;
+%}
+
+
+/* -----------------------------------------------------------------------------
+ * jsc_register_class: template for registration of a class
+ * - $jsname: class name
+ * - $jsmangledname: mangled class name
+ * - $jsnspace: mangled name of namespace
+ * ----------------------------------------------------------------------------- */
+%fragment ("jsc_class_registration", "templates")
+%{
+ JS_registerClass(context, $jsnspace_object, "$jsname", &$jsmangledname_classDefinition);
+%}
+
+
+/* -----------------------------------------------------------------------------
+ * jsc_nspace_declaration: template for a namespace declaration
+ * - $jsnspace: mangled name of the namespace
+ * - $jsglobalvariables: list of variable entries
+ * - $jsglobalfunctions: list if fuction entries
+ * ----------------------------------------------------------------------------- */
+%fragment ("jsc_nspace_declaration", "templates")
+%{
+JSStaticValue $jsnspace_values[] = {
+ $jsglobalvariables
+ { 0, 0, 0, 0 }
+};
+
+JSStaticFunction $jsnspace_functions[] = {
+ $jsglobalfunctions
+ { 0, 0, 0 }
+};
+
+JSClassDefinition $jsnspace_classDefinition;
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsc_nspace_definition: template for definition of a namespace object
+ * - $jsmangledname: mangled name of namespace
+ * ----------------------------------------------------------------------------- */
+%fragment ("jsc_nspace_definition", "templates")
+%{
+ $jsmangledname_classDefinition.staticFunctions = $jsmangledname_functions;
+ $jsmangledname_classDefinition.staticValues = $jsmangledname_values;
+ JSObjectRef $jsmangledname_object = JSObjectMake(context, JSClassCreate(&$jsmangledname_classDefinition), NULL);
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsc_nspace_registration: template for registration of a namespace object
+ * - $jsname: name of namespace
+ * - $jsmangledname: mangled name of namespace
+ * - $jsparent: mangled name of parent namespace
+ * ----------------------------------------------------------------------------- */
+%fragment ("jsc_nspace_registration", "templates")
+%{
+ JS_registerNamespace(context, $jsmangledname_object, $jsparent_object, "$jsname");
+%}
diff --git a/Lib/javascript/jsc/javascriptcomplex.swg b/Lib/javascript/jsc/javascriptcomplex.swg
new file mode 100644
index 000000000..7d165dce4
--- /dev/null
+++ b/Lib/javascript/jsc/javascriptcomplex.swg
@@ -0,0 +1,146 @@
+/*
+ Defines the As/From converters for double/float complex, you need to
+ provide complex Type, the Name you want to use in the converters,
+ the complex Constructor method, and the Real and Imag complex
+ accessor methods.
+
+ See the std_complex.i and ccomplex.i for concret examples.
+*/
+
+/* the common from converter */
+%define %swig_fromcplx_conv(Type, Real, Imag)
+%fragment(SWIG_From_frag(Type),"header",
+ fragment=SWIG_From_frag(double))
+{
+SWIGINTERNINLINE JSObjectRef
+SWIG_From_dec(Type)(%ifcplusplus(const Type&, Type) c)
+{
+ JSValueRef vals[2];
+ vals[0] = SWIG_From(double)(Real(c));
+ vals[1] = SWIG_From(double)(Imag(c));
+ return JSObjectMakeArray(context, 2, vals, NULL);
+}
+}
+%enddef
+
+/* the double case */
+%define %swig_cplxdbl_conv(Type, Constructor, Real, Imag)
+%fragment(SWIG_AsVal_frag(Type),"header",
+ fragment=SWIG_AsVal_frag(double))
+{
+SWIGINTERN int
+SWIG_AsVal_dec(Type) (JSValueRef o, Type* val)
+{
+ if (JSValueIsObject(context, o)) {
+ JSObjectRef array;
+ JSValueRef exception, js_re, js_im;
+ double re, im;
+ int res;
+
+ exception = 0;
+ res = 0;
+
+ array = JSValueToObject(context, o, &exception);
+ if(exception != 0)
+ return SWIG_TypeError;
+
+ js_re = JSObjectGetPropertyAtIndex(context, array, 0, &exception);
+ if(exception != 0)
+ return SWIG_TypeError;
+
+ js_im = JSObjectGetPropertyAtIndex(context, array, 1, &exception);
+ if(exception != 0)
+ return SWIG_TypeError;
+
+ res = SWIG_AsVal(double)(js_re, &re);
+ if(!SWIG_IsOK(res)) {
+ return SWIG_TypeError;
+ }
+
+ res = SWIG_AsVal(double)(js_im, &im);
+ if(!SWIG_IsOK(res)) {
+ return SWIG_TypeError;
+ }
+
+ if (val) *val = Constructor(re, im);
+ return SWIG_OK;
+ } else {
+ double d;
+ int res = SWIG_AddCast(SWIG_AsVal(double)(o, &d));
+ if (SWIG_IsOK(res)) {
+ if (val) *val = Constructor(d, 0.0);
+ return res;
+ }
+ }
+ return SWIG_TypeError;
+}
+}
+%swig_fromcplx_conv(Type, Real, Imag);
+%enddef
+
+/* the float case */
+%define %swig_cplxflt_conv(Type, Constructor, Real, Imag)
+%fragment(SWIG_AsVal_frag(Type),"header",
+ fragment=SWIG_AsVal_frag(float)) {
+SWIGINTERN int
+SWIG_AsVal_dec(Type)(JSValueRef o, Type *val)
+{
+ if (JSValueIsObject(context, o)) {
+ JSObjectRef array;
+ JSValueRef exception, js_re, js_im;
+ double re, im;
+ int res;
+
+ exception = 0;
+ res = 0;
+
+ array = JSValueToObject(context, o, &exception);
+ if(exception != 0)
+ return SWIG_TypeError;
+
+ js_re = JSObjectGetPropertyAtIndex(context, array, 0, &exception);
+ if(exception != 0)
+ return SWIG_TypeError;
+
+ js_im = JSObjectGetPropertyAtIndex(context, array, 1, &exception);
+ if(exception != 0)
+ return SWIG_TypeError;
+
+ res = SWIG_AsVal(double)(js_re, &re);
+ if(!SWIG_IsOK(res)) {
+ return SWIG_TypeError;
+ }
+
+ res = SWIG_AsVal(double)(js_im, &im);
+ if(!SWIG_IsOK(res)) {
+ return SWIG_TypeError;
+ }
+
+ if ((-FLT_MAX <= re && re <= FLT_MAX) && (-FLT_MAX <= im && im <= FLT_MAX)) {
+ if (val) *val = Constructor(%numeric_cast(re, float),
+ %numeric_cast(im, float));
+ return SWIG_OK;
+ } else {
+ return SWIG_OverflowError;
+ }
+ } else {
+ float re;
+ int res = SWIG_AddCast(SWIG_AsVal(float)(o, &re));
+ if (SWIG_IsOK(res)) {
+ if (val) *val = Constructor(re, 0.0);
+ return res;
+ }
+ }
+ return SWIG_TypeError;
+}
+}
+
+%swig_fromcplx_conv(Type, Real, Imag);
+%enddef
+
+#define %swig_cplxflt_convn(Type, Constructor, Real, Imag) \
+%swig_cplxflt_conv(Type, Constructor, Real, Imag)
+
+
+#define %swig_cplxdbl_convn(Type, Constructor, Real, Imag) \
+%swig_cplxdbl_conv(Type, Constructor, Real, Imag)
diff --git a/Lib/javascript/jsc/javascriptfragments.swg b/Lib/javascript/jsc/javascriptfragments.swg
new file mode 100644
index 000000000..4778bf033
--- /dev/null
+++ b/Lib/javascript/jsc/javascriptfragments.swg
@@ -0,0 +1,23 @@
+/*
+
+ Create a file with this name, 'javascriptfragments.swg', in your working
+ directory and add all the %fragments you want to take precedence
+ over the default ones defined by swig.
+
+ For example, if you add:
+
+ %fragment(SWIG_AsVal_frag(int),"header") {
+ SWIGINTERNINLINE int
+ SWIG_AsVal(int)(PyObject *obj, int *val)
+ {
+ <your code here>;
+ }
+ }
+
+ this will replace the code used to retrieve an integer value for all
+ the typemaps that need it, including:
+
+ int, std::vector<int>, std::list<std::pair<int,int> >, etc.
+
+
+*/
diff --git a/Lib/javascript/jsc/javascripthelpers.swg b/Lib/javascript/jsc/javascripthelpers.swg
new file mode 100644
index 000000000..820075ca6
--- /dev/null
+++ b/Lib/javascript/jsc/javascripthelpers.swg
@@ -0,0 +1,69 @@
+%insert(wrapper) %{
+
+bool JS_registerClass(JSGlobalContextRef context, JSObjectRef parentObject,
+ const char* className,
+ JSClassDefinition* definition) {
+
+ JSStringRef js_className = JSStringCreateWithUTF8CString(className);
+ JSObjectRef classObject = JSObjectMake(context, JSClassCreate(definition), NULL);
+ JSObjectSetProperty(context, parentObject,
+ js_className, classObject,
+ kJSPropertyAttributeNone, NULL);
+ JSStringRelease(js_className);
+
+ return true;
+}
+
+bool JS_registerNamespace(JSGlobalContextRef context,
+ JSObjectRef namespaceObj, JSObjectRef parentNamespace,
+ const char* name)
+{
+ JSStringRef js_name = JSStringCreateWithUTF8CString(name);
+ JSObjectSetProperty(context, parentNamespace,
+ js_name, namespaceObj,
+ kJSPropertyAttributeNone, NULL);
+ JSStringRelease(js_name);
+
+ return true;
+}
+
+
+bool JS_registerFunction(JSGlobalContextRef context, JSObjectRef object,
+ const char* functionName, JSObjectCallAsFunctionCallback callback)
+{
+ JSStringRef js_functionName = JSStringCreateWithUTF8CString(functionName);
+ JSObjectSetProperty(context, object, js_functionName,
+ JSObjectMakeFunctionWithCallback(context, js_functionName, callback),
+ kJSPropertyAttributeNone, NULL);
+ JSStringRelease(js_functionName);
+ return true;
+}
+
+bool JS_veto_set_variable(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
+{
+ char buffer[256];
+ char msg[512];
+ int res;
+
+ JSStringGetUTF8CString(propertyName, buffer, 256);
+ res = sprintf(msg, "Tried to write read-only variable: %s.", buffer);
+
+ if(res<0) {
+ SWIG_exception(SWIG_ERROR, "Tried to write read-only variable.");
+ } else {
+ SWIG_exception(SWIG_ERROR, msg);
+ }
+
+ return false;
+}
+
+JSValueRef JS_CharPtrToJSValue(JSContextRef context, char* cstr) {
+ JSValueRef val;
+
+ JSStringRef jsstring = JSStringCreateWithUTF8CString((char*) cstr);
+ val = JSValueMakeString(context, jsstring);
+ JSStringRelease(jsstring);
+
+ return val;
+}
+%}
diff --git a/Lib/javascript/jsc/javascriptinit.swg b/Lib/javascript/jsc/javascriptinit.swg
new file mode 100644
index 000000000..a32ba336c
--- /dev/null
+++ b/Lib/javascript/jsc/javascriptinit.swg
@@ -0,0 +1,67 @@
+%insert(init) %{
+SWIGRUNTIME void
+SWIG_JSC_SetModule(swig_module_info *swig_module) {}
+
+SWIGRUNTIME swig_module_info *
+SWIG_JSC_GetModule(void) {
+ return 0;
+}
+
+#define SWIG_GetModule(clientdata) SWIG_JSC_GetModule()
+#define SWIG_SetModule(clientdata, pointer) SWIG_JSC_SetModule(pointer)
+%}
+
+%insert(init) "swiginit.swg"
+
+%fragment ("js_initializer_define", "templates") %{
+#define SWIGJSC_INIT $jsname_initialize
+%}
+
+// Open the initializer function
+%insert(init)
+%{
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+bool SWIGJSC_INIT (JSGlobalContextRef context, JSObjectRef *exports) {
+ SWIG_InitializeModule(0);
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_initializer: template for the module initializer function
+ * - $jsname: module name
+ * - $jscreatenamespaces: part with code for creating namespace objects
+ * - $jscreateclasses: part with code for creating classes
+ * - $jsregisternamespaces: part with code for registration of namespaces
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_initializer", "templates") %{
+ /* Initialize the base swig type object */
+ _SwigObject_objectDefinition.staticFunctions = _SwigObject_functions;
+ _SwigObject_objectDefinition.staticValues = _SwigObject_values;
+ _SwigObject_classRef = JSClassCreate(&_SwigObject_objectDefinition);
+
+ /* Initialize the PackedData class */
+ _SwigPackedData_objectDefinition.staticFunctions = _SwigPackedData_functions;
+ _SwigPackedData_objectDefinition.staticValues = _SwigPackedData_values;
+ _SwigPackedData_objectDefinition.finalize = _wrap_SwigPackedData_delete;
+ _SwigPackedData_classRef = JSClassCreate(&_SwigPackedData_objectDefinition);
+
+ /* Create objects for namespaces */
+ $jscreatenamespaces
+
+ /* Register classes */
+ $jsregisterclasses
+
+ /* Register namespaces */
+ $jsregisternamespaces
+
+ *exports = exports_object;
+
+ return true;
+}
+#ifdef __cplusplus
+}
+#endif
+%}
diff --git a/Lib/javascript/jsc/javascriptkw.swg b/Lib/javascript/jsc/javascriptkw.swg
new file mode 100644
index 000000000..c3c118391
--- /dev/null
+++ b/Lib/javascript/jsc/javascriptkw.swg
@@ -0,0 +1,40 @@
+#ifndef JAVASCRIPT_JAVASCRIPTKW_SWG_
+#define JAVASCRIPT_JAVASCRIPTKW_SWG_
+
+/* Warnings for Java keywords */
+#define JAVASCRIPTKW(x) %keywordwarn("'" `x` "' is a javascript keyword, renaming to '_"`x`"'",rename="_%s") `x`
+
+/* Taken from https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Reserved_Words */
+
+JAVASCRIPTKW(break);
+JAVASCRIPTKW(case);
+JAVASCRIPTKW(catch);
+JAVASCRIPTKW(continue);
+JAVASCRIPTKW(default);
+JAVASCRIPTKW(delete);
+JAVASCRIPTKW(do);
+JAVASCRIPTKW(else);
+JAVASCRIPTKW(finally);
+JAVASCRIPTKW(for);
+JAVASCRIPTKW(function);
+JAVASCRIPTKW(if);
+JAVASCRIPTKW(in);
+JAVASCRIPTKW(instanceof);
+JAVASCRIPTKW(new);
+JAVASCRIPTKW(return);
+JAVASCRIPTKW(switch);
+JAVASCRIPTKW(this);
+JAVASCRIPTKW(throw);
+JAVASCRIPTKW(try);
+JAVASCRIPTKW(typeof);
+JAVASCRIPTKW(var);
+JAVASCRIPTKW(void);
+JAVASCRIPTKW(while);
+JAVASCRIPTKW(with);
+
+/* others bad names if any*/
+// for example %namewarn("321:clone() is a javascript bad method name") *::clone();
+
+#undef JAVASCRIPTKW
+
+#endif //JAVASCRIPT_JAVASCRIPTKW_SWG_
diff --git a/Lib/javascript/jsc/javascriptprimtypes.swg b/Lib/javascript/jsc/javascriptprimtypes.swg
new file mode 100644
index 000000000..7e9898a24
--- /dev/null
+++ b/Lib/javascript/jsc/javascriptprimtypes.swg
@@ -0,0 +1,182 @@
+/* ------------------------------------------------------------
+ * Primitive Types
+ * ------------------------------------------------------------ */
+
+/* boolean */
+
+%fragment(SWIG_From_frag(bool),"header") {
+SWIGINTERNINLINE
+JSValueRef SWIG_From_dec(bool)(bool value)
+{
+ return JSValueMakeBoolean(context, value);
+}
+}
+
+%fragment(SWIG_AsVal_frag(bool),"header",
+ fragment=SWIG_AsVal_frag(long)) {
+SWIGINTERN
+int SWIG_AsVal_dec(bool)(JSValueRef obj, bool *val)
+{
+ if(!JSValueIsBoolean(context, obj)) {
+ return SWIG_ERROR;
+ }
+ if (val) *val = JSValueToBoolean(context, obj);
+ return SWIG_OK;
+}
+}
+
+/* int */
+
+%fragment(SWIG_From_frag(int),"header") {
+SWIGINTERNINLINE JSValueRef
+ SWIG_From_dec(int)(int value)
+{
+ return JSValueMakeNumber(context, value);
+}
+}
+
+/* long */
+
+%fragment(SWIG_From_frag(long),"header") {
+SWIGINTERNINLINE JSValueRef
+SWIG_From_dec(long)(long value)
+{
+ return JSValueMakeNumber(context, value);
+}
+}
+
+%fragment(SWIG_AsVal_frag(long),"header",
+ fragment="SWIG_CanCastAsInteger") {
+SWIGINTERN int
+SWIG_AsVal_dec(long)(JSValueRef obj, long* val)
+{
+ if (!JSValueIsNumber(context, obj)) {
+ return SWIG_TypeError;
+ }
+ if(val) *val = (long) JSValueToNumber(context, obj, NULL);
+
+ return SWIG_OK;
+}
+}
+
+/* unsigned long */
+
+%fragment(SWIG_From_frag(unsigned long),"header",
+ fragment=SWIG_From_frag(long)) {
+SWIGINTERNINLINE JSValueRef
+SWIG_From_dec(unsigned long)(unsigned long value)
+{
+ return (value > LONG_MAX) ?
+ JSValueMakeNumber(context, value) : JSValueMakeNumber(context, %numeric_cast(value,long));
+}
+}
+
+%fragment(SWIG_AsVal_frag(unsigned long),"header",
+ fragment="SWIG_CanCastAsInteger") {
+SWIGINTERN int
+SWIG_AsVal_dec(unsigned long)(JSValueRef obj, unsigned long *val)
+{
+ if(!JSValueIsNumber(context, obj)) {
+ return SWIG_TypeError;
+ }
+
+ long longVal = (long) JSValueToNumber(context, obj, NULL);
+
+ if(longVal < 0) {
+ return SWIG_OverflowError;
+ }
+
+ if(val) *val = longVal;
+
+ return SWIG_OK;
+}
+}
+
+/* long long */
+// Note: these are copied from 'long' and probably need fixing
+
+%fragment(SWIG_From_frag(long long),"header",
+ fragment=SWIG_From_frag(long),
+ fragment="<limits.h>") {
+SWIGINTERNINLINE JSValueRef
+SWIG_From_dec(long long)(long long value)
+{
+ return JSValueMakeNumber(context, value);
+}
+}
+
+%fragment(SWIG_AsVal_frag(long long),"header",
+ fragment=SWIG_AsVal_frag(long),
+ fragment="SWIG_CanCastAsInteger",
+ fragment="<limits.h>") {
+SWIGINTERN int
+SWIG_AsVal_dec(long long)(JSValueRef obj, long long* val)
+{
+ if (!JSValueIsNumber(context, obj)) {
+ return SWIG_TypeError;
+ }
+ if(val) *val = (long long) JSValueToNumber(context, obj, NULL);
+
+ return SWIG_OK;
+}
+}
+
+/* unsigned long long */
+// Note: these are copied from 'unsigned long' and probably need fixing
+
+%fragment(SWIG_From_frag(unsigned long long),"header",
+ fragment=SWIG_From_frag(long long),
+ fragment="<limits.h>") {
+SWIGINTERN JSValueRef
+SWIG_From_dec(unsigned long long)(unsigned long long value)
+{
+ return (value > LONG_MAX) ?
+ JSValueMakeNumber(context, value) : JSValueMakeNumber(context, %numeric_cast(value,long));
+}
+}
+
+%fragment(SWIG_AsVal_frag(unsigned long long),"header",
+ fragment=SWIG_AsVal_frag(unsigned long),
+ fragment="SWIG_CanCastAsInteger",
+ fragment="<limits.h>") {
+SWIGINTERN int
+SWIG_AsVal_dec(unsigned long long)(JSValueRef obj, unsigned long long *val)
+{
+ if(!JSValueIsNumber(context, obj)) {
+ return SWIG_TypeError;
+ }
+
+ long long longVal = (unsigned long long) JSValueToNumber(context, obj, NULL);
+
+ if(longVal < 0) {
+ return SWIG_OverflowError;
+ }
+
+ if(val) *val = longVal;
+
+ return SWIG_OK;
+}
+}
+
+/* double */
+
+%fragment(SWIG_From_frag(double),"header") {
+SWIGINTERN JSValueRef
+SWIG_From_dec(double) (double val)
+{
+ return JSValueMakeNumber(context, val);
+}
+}
+
+%fragment(SWIG_AsVal_frag(double),"header") {
+SWIGINTERN int
+SWIG_AsVal_dec(double)(JSValueRef obj, double *val)
+{
+ if(!JSValueIsNumber(context, obj)) {
+ return SWIG_TypeError;
+ }
+ if(val) *val = JSValueToNumber(context, obj, NULL);
+
+ return SWIG_OK;
+}
+}
diff --git a/Lib/javascript/jsc/javascriptrun.swg b/Lib/javascript/jsc/javascriptrun.swg
new file mode 100644
index 000000000..3463d2351
--- /dev/null
+++ b/Lib/javascript/jsc/javascriptrun.swg
@@ -0,0 +1,298 @@
+/* ----------------------------------------------------------------------------
+ * Errors and exceptions
+ *
+ * ---------------------------------------------------------------------------*/
+
+#define SWIG_Error(code, msg) SWIG_JSC_exception(context, exception, code, msg)
+#define SWIG_exception(code, msg) SWIG_JSC_exception(context, exception, code, msg)
+#define SWIG_fail goto fail
+
+void SWIG_Javascript_Raise(JSContextRef context, JSValueRef *exception, const char* type) {
+ JSStringRef message = JSStringCreateWithUTF8CString(type);
+ *exception = JSValueMakeString(context, message);
+ JSStringRelease(message);
+}
+
+void SWIG_JSC_exception(JSContextRef context, JSValueRef *exception, int code, const char* msg) {
+ SWIG_Javascript_Raise(context, exception, msg);
+}
+
+/* ----------------------------------------------------------------------------
+ * The parent class of all Proxies
+ *
+ * ---------------------------------------------------------------------------*/
+
+typedef struct {
+ bool swigCMemOwn;
+ void *swigCObject;
+ swig_type_info *info;
+} SwigPrivData;
+
+JSValueRef _wrap_SwigObject_disown(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
+{
+ JSValueRef jsresult;
+
+ JSObjectRef obj = JSValueToObject(context, thisObject, NULL);
+ SwigPrivData *cdata = (SwigPrivData *) JSObjectGetPrivate(obj);
+
+ cdata->swigCMemOwn = false;
+
+ jsresult = JSValueMakeUndefined(context);
+ return jsresult;
+}
+
+JSValueRef _wrap_SwigObject_getCPtr(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
+{
+ JSValueRef jsresult;
+ long result;
+
+ JSObjectRef obj = JSValueToObject(context, thisObject, NULL);
+ SwigPrivData *cdata = (SwigPrivData*) JSObjectGetPrivate(obj);
+
+ result = (long) cdata->swigCObject;
+ jsresult = JSValueMakeNumber(context, result);
+
+ return jsresult;
+}
+
+JSValueRef _wrap_SwigObject_equals(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exception)
+{
+ JSValueRef jsresult;
+ bool result;
+
+ JSObjectRef obj = JSValueToObject(context, thisObject, NULL);
+ SwigPrivData *cdata = (SwigPrivData*) JSObjectGetPrivate(obj);
+
+ JSObjectRef obj2 = JSValueToObject(context, argv[0], NULL);
+ SwigPrivData *cdata2 = (SwigPrivData*) JSObjectGetPrivate(obj2);
+
+ result = (cdata->swigCObject == cdata2->swigCObject);
+ jsresult = JSValueMakeBoolean(context, result);
+
+ return jsresult;
+}
+
+JSStaticValue _SwigObject_values[] = {
+ {
+ 0, 0, 0, 0
+ }
+};
+
+JSStaticFunction _SwigObject_functions[] = {
+ {
+ "disown",_wrap_SwigObject_disown, kJSPropertyAttributeNone
+ },
+ {
+ "equals",_wrap_SwigObject_equals, kJSPropertyAttributeNone
+ },
+ {
+ "getCPtr",_wrap_SwigObject_getCPtr, kJSPropertyAttributeNone
+ },
+ {
+ 0, 0, 0
+ }
+};
+
+JSClassDefinition _SwigObject_objectDefinition;
+
+JSClassRef _SwigObject_classRef;
+
+
+int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef objRef, void** ptr, swig_type_info *info, int flags) {
+ SwigPrivData *cdata = (SwigPrivData *) JSObjectGetPrivate(objRef);
+ if(cdata == NULL) {
+ return SWIG_ERROR;
+ }
+ if(cdata->info != info) {
+ bool type_valid = false;
+ swig_cast_info *t = info->cast;
+ while(t != NULL) {
+ if(t->type == cdata->info) {
+ type_valid = true;
+ break;
+ }
+ t = t->next;
+ }
+ if(!type_valid) {
+ return SWIG_TypeError;
+ }
+ }
+
+ *ptr = cdata->swigCObject;
+
+ if(flags & SWIG_POINTER_DISOWN) {
+ cdata->swigCMemOwn = false;
+ }
+
+ return SWIG_OK;
+}
+
+int SWIG_JSC_ConvertPtr(JSContextRef context, JSValueRef valRef, void** ptr, swig_type_info *info, int flags) {
+ if(!JSValueIsObject(context, valRef)) {
+ return SWIG_TypeError;
+ }
+
+ JSObjectRef objRef = JSValueToObject(context, valRef, NULL);
+ if(objRef == NULL) {
+ return SWIG_ERROR;
+ }
+
+ return SWIG_JSC_ConvertInstancePtr(context, objRef, ptr, info, flags);
+}
+
+JSObjectRef SWIG_JSC_NewPointerObj(JSContextRef context, void *ptr, swig_type_info *info, int flags) {
+
+ JSClassRef classRef;
+ if(info->clientdata == NULL) {
+ classRef = _SwigObject_classRef;
+ } else {
+ classRef = (JSClassRef) info->clientdata;
+ }
+
+ JSObjectRef result = JSObjectMake(context, classRef, NULL);
+
+ SwigPrivData* cdata = (SwigPrivData*) malloc(sizeof(SwigPrivData));
+ cdata->swigCObject = ptr;
+ cdata->swigCMemOwn = (flags & SWIG_POINTER_OWN) ? 1 : 0;
+ cdata->info = info;
+
+ JSObjectSetPrivate(result, cdata);
+
+ return result;
+}
+
+#define SWIG_ConvertPtr(obj, ptr, info, flags) SWIG_JSC_ConvertPtr(context, obj, ptr, info, flags)
+#define SWIG_NewPointerObj(ptr, info, flags) SWIG_JSC_NewPointerObj(context, ptr, info, flags)
+
+#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_JSC_ConvertInstancePtr(context, obj, pptr, type, flags)
+#define SWIG_NewInstanceObj(thisvalue, type, flags) SWIG_JSC_NewPointerObj(context, thisvalue, type, flags)
+
+#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_JSC_ConvertPtr(context, obj, pptr, type, 0)
+#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_JSC_NewPointerObj(context, ptr, type, 0)
+
+/* ----------------------------------------------------------------------------
+ * A class for packed data
+ *
+ * ---------------------------------------------------------------------------*/
+
+typedef struct {
+ void *data;
+ size_t size;
+ swig_type_info *type;
+} SwigPackedData;
+
+JSStaticValue _SwigPackedData_values[] = {
+ {
+ 0, 0, 0, 0
+ }
+};
+JSStaticFunction _SwigPackedData_functions[] = {
+ {
+ 0, 0, 0
+ }
+};
+JSClassDefinition _SwigPackedData_objectDefinition;
+JSClassRef _SwigPackedData_classRef;
+
+SWIGRUNTIMEINLINE
+int SwigJSCPacked_Check(JSContextRef context, JSValueRef valRef) {
+ return JSValueIsObjectOfClass(context, valRef, _SwigPackedData_classRef);
+}
+
+SWIGRUNTIME
+swig_type_info* SwigJSCPacked_UnpackData(JSContextRef context, JSValueRef valRef, void *ptr, size_t size) {
+ if (SwigJSCPacked_Check(context, valRef)) {
+ JSObjectRef objRef = JSValueToObject(context, valRef, NULL);
+ SwigPackedData *sobj = (SwigPackedData *) JSObjectGetPrivate(objRef);
+ if (sobj->size != size) return 0;
+ memcpy(ptr, sobj->data, size);
+ return sobj->type;
+ } else {
+ return 0;
+ }
+}
+
+SWIGRUNTIME
+int SWIG_JSC_ConvertPacked(JSContextRef context, JSValueRef valRef, void *ptr, size_t sz, swig_type_info *ty) {
+ swig_type_info *to = SwigJSCPacked_UnpackData(context, valRef, ptr, sz);
+ if (!to) return SWIG_ERROR;
+ if (ty) {
+ if (to != ty) {
+ /* check type cast? */
+ swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
+ if (!tc) return SWIG_ERROR;
+ }
+ }
+ return SWIG_OK;
+}
+
+SWIGRUNTIME
+JSValueRef SWIG_JSC_NewPackedObj(JSContextRef context, void *data, size_t size, swig_type_info *type) {
+
+ JSClassRef classRef = _SwigObject_classRef;
+ JSObjectRef result = JSObjectMake(context, classRef, NULL);
+
+ SwigPackedData* cdata = (SwigPackedData*) malloc(sizeof(SwigPackedData));
+ cdata->data = data;
+ cdata->size = size;
+ cdata->type = type;
+
+ JSObjectSetPrivate(result, cdata);
+
+ return result;
+}
+
+/* SwigPackedData wrappers */
+
+void _wrap_SwigPackedData_delete(JSObjectRef obj)
+{
+ SwigPackedData* cdata = (SwigPackedData*) JSObjectGetPrivate(obj);
+ if (cdata) {
+ free(cdata->data);
+ }
+}
+
+/* for C++ member pointers, ie, member methods */
+
+#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_JSC_ConvertPacked(context, obj, ptr, sz, ty)
+#define SWIG_NewMemberObj(ptr, sz, type) SWIG_JSC_NewPackedObj(context, ptr, sz, type)
+
+
+/* ---------------------------------------------------------------------------
+ * Support for IN/OUTPUT typemaps (see Lib/typemaps/inoutlist.swg)
+ *
+ * ---------------------------------------------------------------------------*/
+
+unsigned int SWIGJSC_ArrayLength(JSContextRef context, JSObjectRef arr) {
+ static JSStringRef LENGTH = 0;
+ JSValueRef exception = NULL;
+ JSValueRef js_length;
+ double length;
+
+ if (LENGTH == 0) {
+ LENGTH = JSStringCreateWithUTF8CString("length");
+ }
+
+ js_length = JSObjectGetProperty(context, arr, LENGTH, &exception);
+ if (exception == 0 && JSValueIsNumber(context, js_length)) {
+ length = JSValueToNumber(context, js_length, 0);
+ return (unsigned int) length;
+ } else {
+ return 0;
+ }
+}
+
+SWIGRUNTIME
+JSValueRef SWIGJSC_AppendOutput(JSContextRef context, JSValueRef value, JSValueRef obj) {
+ JSObjectRef arr;
+ unsigned int length;
+
+ if (JSValueIsUndefined(context, value)) {
+ arr = JSObjectMakeArray(context, 0, 0, 0);
+ } else {
+ arr = JSValueToObject(context, value, 0);
+ }
+
+ length = SWIGJSC_ArrayLength(context, arr);
+ JSObjectSetPropertyAtIndex(context, arr, length, obj, 0);
+}
diff --git a/Lib/javascript/jsc/javascriptruntime.swg b/Lib/javascript/jsc/javascriptruntime.swg
new file mode 100644
index 000000000..8f8390890
--- /dev/null
+++ b/Lib/javascript/jsc/javascriptruntime.swg
@@ -0,0 +1,19 @@
+/* -----------------------------------------------------------------------------
+ * javascriptruntime.swg
+ *
+ * Javascript support code
+ * ----------------------------------------------------------------------------- */
+
+%insert(runtime) %{
+#include <JavaScriptCore/JavaScript.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <limits.h>
+%}
+
+%insert(runtime) "swigrun.swg"; /* SWIG API */
+%insert(runtime) "swigerrors.swg"; /* SWIG errors */
+
+%insert(runtime) "javascriptrun.swg"; /* SWIG errors */
diff --git a/Lib/javascript/jsc/javascriptstrings.swg b/Lib/javascript/jsc/javascriptstrings.swg
new file mode 100644
index 000000000..0581c1920
--- /dev/null
+++ b/Lib/javascript/jsc/javascriptstrings.swg
@@ -0,0 +1,184 @@
+/* ------------------------------------------------------------
+ * utility methods for char strings
+ * ------------------------------------------------------------ */
+%fragment("SWIG_AsCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
+SWIGINTERN int
+SWIG_JSC_AsCharPtrAndSize(JSContextRef context, JSValueRef valRef, char** cptr, size_t* psize, int *alloc)
+{
+ if(JSValueIsString(context, valRef)) {
+ JSStringRef js_str = JSValueToStringCopy(context, valRef, NULL);
+ size_t len = JSStringGetMaximumUTF8CStringSize(js_str);
+ char* cstr = (char*) malloc(len * sizeof(char));
+ /* JSStringGetUTF8CString returns the length including 0-terminator */
+ len = JSStringGetUTF8CString(js_str, cstr, len);
+
+ if(alloc) *alloc = SWIG_NEWOBJ;
+ if(psize) *psize = len;
+ if(cptr) *cptr = cstr;
+
+ return SWIG_OK;
+ } else {
+ if(JSValueIsObject(context, valRef)) {
+ JSObjectRef obj = JSValueToObject(context, valRef, NULL);
+ // try if the object is a wrapped char[]
+ swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
+ if (pchar_descriptor) {
+ void* vptr = 0;
+ if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) {
+ if (cptr) *cptr = (char *) vptr;
+ if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0;
+ if (alloc) *alloc = SWIG_OLDOBJ;
+ return SWIG_OK;
+ }
+ }
+ return SWIG_TypeError;
+ } else {
+ return SWIG_TypeError;
+ }
+ }
+}
+}
+
+%fragment("SWIG_FromCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
+SWIGINTERNINLINE JSValueRef
+SWIG_JSC_FromCharPtrAndSize(JSContextRef context, const char* carray, size_t size)
+{
+ if (carray) {
+ if (size > INT_MAX) {
+ // TODO: handle extra long strings
+ //swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
+ //return pchar_descriptor ?
+ // SWIG_InternalNewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void();
+ return JSValueMakeUndefined(context);
+ } else {
+ JSStringRef jsstring;
+ if(size < 2) {
+ char c[size+1];
+ int i;
+ for(i=0;i<size;++i) {
+ c[i] = carray[i];
+ }
+ c[size] = 0;
+ jsstring = JSStringCreateWithUTF8CString(c);
+ } else {
+ jsstring = JSStringCreateWithUTF8CString(carray);
+ }
+ JSValueRef result = JSValueMakeString(context, jsstring);
+ JSStringRelease(jsstring);
+ return result;
+ }
+ } else {
+ return JSValueMakeUndefined(context);
+ }
+}
+}
+
+%define %_typemap2_string(StringCode, CharCode,
+ Char, CharName,
+ SWIG_AsCharPtrAndSize,
+ SWIG_FromCharPtrAndSize,
+ SWIG_CharPtrLen,
+ SWIG_CharBufLen,
+ SWIG_NewCopyCharArray,
+ SWIG_DeleteCharArray,
+ FragLimits, CHAR_MIN, CHAR_MAX)
+
+%fragment("SWIG_From"#CharName"Ptr","header",fragment=#SWIG_FromCharPtrAndSize) {
+SWIGINTERNINLINE SWIG_Object
+SWIG_JSC_From##CharName##Ptr(JSContextRef context, const Char *cptr)
+{
+ return SWIG_JSC_FromCharPtrAndSize(context, cptr, (cptr ? SWIG_CharPtrLen(cptr) : 0));
+}
+}
+
+%fragment("SWIG_From"#CharName"Array","header",fragment=#SWIG_FromCharPtrAndSize) {
+SWIGINTERNINLINE SWIG_Object
+SWIG_JSC_From##CharName##Array(JSContextRef context, const Char *cptr, size_t size)
+{
+ return SWIG_JSC_FromCharPtrAndSize(context, cptr, size);
+}
+}
+
+%fragment("SWIG_As" #CharName "Ptr","header",fragment=#SWIG_AsCharPtrAndSize) {
+%define_as(SWIG_As##CharName##Ptr(obj, val, alloc), SWIG_JSC_AsCharPtrAndSize(context, obj, val, NULL, alloc))
+}
+
+%fragment("SWIG_As" #CharName "Array","header",fragment=#SWIG_AsCharPtrAndSize) {
+SWIGINTERN int
+SWIG_JSC_As##CharName##Array(JSContextRef context, SWIG_Object obj, Char *val, size_t size)
+{
+ Char* cptr = 0; size_t csize = 0; int alloc = SWIG_OLDOBJ;
+ int res = SWIG_JSC_AsCharPtrAndSize(context, obj, &cptr, &csize, &alloc);
+ if (SWIG_IsOK(res)) {
+ if ((csize == size + 1) && cptr && !(cptr[csize-1])) --csize;
+ if (csize <= size) {
+ if (val) {
+ if (csize) memcpy(val, cptr, csize*sizeof(Char));
+ if (csize < size) memset(val + csize, 0, (size - csize)*sizeof(Char));
+ }
+ if (alloc == SWIG_NEWOBJ) {
+ SWIG_DeleteCharArray(cptr);
+ res = SWIG_DelNewMask(res);
+ }
+ return res;
+ }
+ if (alloc == SWIG_NEWOBJ) SWIG_DeleteCharArray(cptr);
+ }
+ return SWIG_TypeError;
+}
+
+#define SWIG_As##CharName##Array(obj, val, size) SWIG_JSC_As##CharName##Array(context, obj, val, size)
+}
+
+/* Char */
+
+%fragment(SWIG_From_frag(Char),"header",fragment=#SWIG_FromCharPtrAndSize) {
+SWIGINTERNINLINE SWIG_Object
+SWIG_From_dec(Char)(Char c)
+{
+ return SWIG_JSC_FromCharPtrAndSize(context, &c,1);
+}
+}
+
+%fragment(SWIG_AsVal_frag(Char),"header",
+ fragment="SWIG_As"#CharName"Array",
+ fragment=FragLimits,
+ fragment=SWIG_AsVal_frag(long)) {
+SWIGINTERN int
+SWIG_AsVal_dec(Char)(SWIG_Object obj, Char *val)
+{
+ int res = SWIG_As##CharName##Array(obj, val, 1);
+ if (!SWIG_IsOK(res)) {
+ long v;
+ res = SWIG_AddCast(SWIG_AsVal(long)(obj, &v));
+ if (SWIG_IsOK(res)) {
+ if ((CHAR_MIN <= v) && (v <= CHAR_MAX)) {
+ if (val) *val = %numeric_cast(v, Char);
+ } else {
+ res = SWIG_OverflowError;
+ }
+ }
+ }
+ return res;
+}
+}
+
+%_typemap_string(StringCode,
+ Char,
+ SWIG_AsCharPtrAndSize,
+ SWIG_FromCharPtrAndSize,
+ SWIG_CharPtrLen,
+ SWIG_CharBufLen,
+ SWIG_As##CharName##Ptr,
+ SWIG_From##CharName##Ptr,
+ SWIG_As##CharName##Array,
+ SWIG_NewCopyCharArray,
+ SWIG_DeleteCharArray)
+
+%enddef
+
+%insert(runtime) %{
+#define SWIG_AsCharPtrAndSize(val, cptr, psize, alloc) SWIG_JSC_AsCharPtrAndSize(context, val, cptr, psize, alloc)
+#define SWIG_FromCharPtrAndSize(cptr, size) SWIG_JSC_FromCharPtrAndSize(context, cptr, size)
+#define SWIG_FromCharPtr(cptr) SWIG_JSC_FromCharPtr(context, cptr)
+%}
diff --git a/Lib/javascript/jsc/javascripttypemaps.swg b/Lib/javascript/jsc/javascripttypemaps.swg
new file mode 100644
index 000000000..e8fbbeca8
--- /dev/null
+++ b/Lib/javascript/jsc/javascripttypemaps.swg
@@ -0,0 +1,54 @@
+/* ------------------------------------------------------------
+ * Typemap specializations for Javascript
+ * ------------------------------------------------------------ */
+
+/* ------------------------------------------------------------
+ * Fragment section
+ * ------------------------------------------------------------ */
+
+/* These macros are necessary to provide an extra parameter
+ to SWIG_AsVal_dec functions (JSContextRef context).
+ They must be defined before including `typemaps/fragments.swg`
+*/
+#define SWIG_FROM_DECL_ARGS SWIG_JSC_FROM_DECL_ARGS
+#define SWIG_FROM_CALL_ARGS SWIG_JSC_FROM_CALL_ARGS
+#define SWIG_AS_DECL_ARGS SWIG_JSC_AS_DECL_ARGS
+#define SWIG_AS_CALL_ARGS SWIG_JSC_AS_CALL_ARGS
+
+/* Include fundamental fragemt definitions */
+%include <typemaps/fragments.swg>
+
+/* Look for user fragments file. */
+%include <javascriptfragments.swg>
+
+/* Javascript fragments for fundamental types */
+%include <javascriptprimtypes.swg>
+
+/* Javascript fragments for char* strings */
+%include <javascriptstrings.swg>
+
+/* ------------------------------------------------------------
+ * Unified typemap section
+ * ------------------------------------------------------------ */
+
+#define SWIG_Object JSValueRef
+#define VOID_Object JSValueMakeUndefined(context)
+
+/* append output */
+#define SWIG_AppendOutput(result, obj) SWIGJSC_AppendOutput(context, result, obj)
+
+/* set constant */
+#define SWIG_SetConstant(name, obj)
+
+/* raise */
+#define SWIG_Raise(obj, type, desc) SWIG_Javascript_Raise(context, exception, type)
+
+%insert("runtime") %{
+#define SWIG_JSC_FROM_DECL_ARGS(arg1) (JSContextRef context, arg1)
+#define SWIG_JSC_FROM_CALL_ARGS(arg1) (context, arg1)
+#define SWIG_JSC_AS_DECL_ARGS(arg1, arg2) (JSContextRef context, arg1, arg2)
+#define SWIG_JSC_AS_CALL_ARGS(arg1, arg2) (context, arg1, arg2)
+%}
+
+/* Include the unified typemap library */
+%include <typemaps/swigtypemaps.swg>
diff --git a/Lib/javascript/jsc/std_common.i b/Lib/javascript/jsc/std_common.i
new file mode 100755
index 000000000..cee11e8ca
--- /dev/null
+++ b/Lib/javascript/jsc/std_common.i
@@ -0,0 +1,5 @@
+%include <std_except.i>
+
+%apply size_t { std::size_t };
+%apply const size_t& { const std::size_t& };
+
diff --git a/Lib/javascript/jsc/std_complex.i b/Lib/javascript/jsc/std_complex.i
new file mode 100644
index 000000000..088a4fe7b
--- /dev/null
+++ b/Lib/javascript/jsc/std_complex.i
@@ -0,0 +1,19 @@
+/*
+ * STD C++ complex typemaps
+ */
+
+%include <javascriptcomplex.swg>
+
+%{
+#include <complex>
+%}
+
+/* defining the complex as/from converters */
+
+%swig_cplxdbl_convn(std::complex<double>, std::complex<double>, std::real, std::imag)
+%swig_cplxflt_convn(std::complex<float>, std::complex<float>, std::real, std::imag)
+
+/* defining the typemaps */
+
+%typemaps_primitive(%checkcode(CPLXDBL), std::complex<double>);
+%typemaps_primitive(%checkcode(CPLXFLT), std::complex<float>);
diff --git a/Lib/javascript/jsc/std_deque.i b/Lib/javascript/jsc/std_deque.i
new file mode 100644
index 000000000..cb98f6c2f
--- /dev/null
+++ b/Lib/javascript/jsc/std_deque.i
@@ -0,0 +1 @@
+%include <std/_std_deque.i>
diff --git a/Lib/javascript/jsc/std_except.i b/Lib/javascript/jsc/std_except.i
new file mode 100644
index 000000000..af98428f6
--- /dev/null
+++ b/Lib/javascript/jsc/std_except.i
@@ -0,0 +1 @@
+%include <typemaps/std_except.swg>
diff --git a/Lib/javascript/jsc/std_map.i b/Lib/javascript/jsc/std_map.i
new file mode 100755
index 000000000..e7812f38a
--- /dev/null
+++ b/Lib/javascript/jsc/std_map.i
@@ -0,0 +1,74 @@
+/* -----------------------------------------------------------------------------
+ * std_map.i
+ *
+ * SWIG typemaps for std::map
+ * ----------------------------------------------------------------------------- */
+
+%include <std_common.i>
+
+// ------------------------------------------------------------------------
+// std::map
+// ------------------------------------------------------------------------
+
+%{
+#include <map>
+#include <algorithm>
+#include <stdexcept>
+%}
+
+// exported class
+
+namespace std {
+
+ template<class K, class T> class map {
+ // add typemaps here
+ public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef K key_type;
+ typedef T mapped_type;
+ map();
+ map(const map<K,T> &);
+
+ unsigned int size() const;
+ bool empty() const;
+ void clear();
+ %extend {
+ const T& get(const K& key) throw (std::out_of_range) {
+ std::map<K,T >::iterator i = self->find(key);
+ if (i != self->end())
+ return i->second;
+ else
+ throw std::out_of_range("key not found");
+ }
+ void set(const K& key, const T& x) {
+ (*self)[key] = x;
+ }
+ void del(const K& key) throw (std::out_of_range) {
+ std::map<K,T >::iterator i = self->find(key);
+ if (i != self->end())
+ self->erase(i);
+ else
+ throw std::out_of_range("key not found");
+ }
+ bool has_key(const K& key) {
+ std::map<K,T >::iterator i = self->find(key);
+ return i != self->end();
+ }
+ }
+ };
+
+// Legacy macros (deprecated)
+%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
+#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary"
+%enddef
+
+%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
+#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary"
+%enddef
+
+%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
+#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary"
+%enddef
+
+}
diff --git a/Lib/javascript/jsc/std_pair.i b/Lib/javascript/jsc/std_pair.i
new file mode 100755
index 000000000..fe45ee676
--- /dev/null
+++ b/Lib/javascript/jsc/std_pair.i
@@ -0,0 +1,34 @@
+/* -----------------------------------------------------------------------------
+ * std_pair.i
+ *
+ * SWIG typemaps for std::pair
+ * ----------------------------------------------------------------------------- */
+
+%include <std_common.i>
+%include <exception.i>
+
+// ------------------------------------------------------------------------
+// std::pair
+// ------------------------------------------------------------------------
+
+%{
+#include <utility>
+%}
+
+namespace std {
+
+ template<class T, class U> struct pair {
+
+ pair();
+ pair(T first, U second);
+ pair(const pair& p);
+
+ template <class U1, class U2> pair(const pair<U1, U2> &p);
+
+ T first;
+ U second;
+ };
+
+ // add specializations here
+
+}
diff --git a/Lib/javascript/jsc/std_string.i b/Lib/javascript/jsc/std_string.i
new file mode 100755
index 000000000..fb1bd62b5
--- /dev/null
+++ b/Lib/javascript/jsc/std_string.i
@@ -0,0 +1,69 @@
+/* -----------------------------------------------------------------------------
+ * std_string.i
+ *
+ * Typemaps for const std::string&.
+ * To use non-const std::string references use the following %apply:
+ * %apply const std::string & {std::string &};
+ *
+ * ----------------------------------------------------------------------------- */
+
+%{
+#include <string>
+
+std::string SWIGJSC_valueToString(JSContextRef context, JSValueRef value) {
+ JSStringRef jsstring = JSValueToStringCopy(context, value, /* JSValueRef *exception */ 0);
+ unsigned int length = JSStringGetLength(jsstring);
+ char *cstr = new char[length + 1];
+ JSStringGetUTF8CString(jsstring, cstr, length + 1);
+
+ // create a copy
+ std::string result(cstr);
+
+ JSStringRelease(jsstring);
+ delete[] cstr;
+
+ return result;
+}
+
+JSValueRef SWIGJSC_stringToValue(JSContextRef context, const std::string& s)
+{
+ JSValueRef result;
+ JSStringRef jsstring = JSStringCreateWithUTF8CString(s.c_str());
+ result = JSValueMakeString(context, jsstring);
+ JSStringRelease(jsstring);
+ return result;
+}
+%}
+
+namespace std {
+ %naturalvar string;
+
+ class string;
+
+
+ %typemap(in) string
+ %{
+ $1 = SWIGJSC_valueToString(context, $input);
+ %}
+
+ %typemap(in) const string &
+ %{
+ $1 = new std::string(SWIGJSC_valueToString(context, $input));
+ %}
+
+ %typemap(freearg) const string &
+ %{
+ delete $1;
+ %}
+
+ %typemap(out) string
+ %{
+ $result = SWIGJSC_stringToValue(context, $1);
+ %}
+
+ %typemap(out) const string &
+ %{
+ $result = SWIGJSC_stringToValue(context, *$1);
+ %}
+
+}
diff --git a/Lib/javascript/jsc/std_vector.i b/Lib/javascript/jsc/std_vector.i
new file mode 100755
index 000000000..3f29b19c7
--- /dev/null
+++ b/Lib/javascript/jsc/std_vector.i
@@ -0,0 +1,85 @@
+/* -----------------------------------------------------------------------------
+ * std_vector.i
+ * ----------------------------------------------------------------------------- */
+
+%include <std_common.i>
+
+%{
+#include <vector>
+#include <stdexcept>
+%}
+
+namespace std {
+
+ template<class T> class vector {
+ public:
+ typedef size_t size_type;
+ typedef T value_type;
+ typedef const value_type& const_reference;
+ vector();
+ vector(size_type n);
+ size_type size() const;
+ size_type capacity() const;
+ void reserve(size_type n);
+ %rename(isEmpty) empty;
+ bool empty() const;
+ void clear();
+ %rename(add) push_back;
+ void push_back(const value_type& x);
+ %extend {
+ const_reference get(int i) throw (std::out_of_range) {
+ int size = int(self->size());
+ if (i>=0 && i<size)
+ return (*self)[i];
+ else
+ throw std::out_of_range("vector index out of range");
+ }
+ void set(int i, const value_type& val) throw (std::out_of_range) {
+ int size = int(self->size());
+ if (i>=0 && i<size)
+ (*self)[i] = val;
+ else
+ throw std::out_of_range("vector index out of range");
+ }
+ }
+ };
+
+ // bool specialization
+ template<> class vector<bool> {
+ public:
+ typedef size_t size_type;
+ typedef bool value_type;
+ typedef bool const_reference;
+ vector();
+ vector(size_type n);
+ size_type size() const;
+ size_type capacity() const;
+ void reserve(size_type n);
+ %rename(isEmpty) empty;
+ bool empty() const;
+ void clear();
+ %rename(add) push_back;
+ void push_back(const value_type& x);
+ %extend {
+ const_reference get(int i) throw (std::out_of_range) {
+ int size = int(self->size());
+ if (i>=0 && i<size)
+ return (*self)[i];
+ else
+ throw std::out_of_range("vector index out of range");
+ }
+ void set(int i, const value_type& val) throw (std::out_of_range) {
+ int size = int(self->size());
+ if (i>=0 && i<size)
+ (*self)[i] = val;
+ else
+ throw std::out_of_range("vector index out of range");
+ }
+ }
+ };
+}
+
+%define specialize_std_vector(T)
+#warning "specialize_std_vector - specialization for type T no longer needed"
+%enddef
+
diff --git a/Lib/javascript/jsc/stl.i b/Lib/javascript/jsc/stl.i
new file mode 100755
index 000000000..04f86014f
--- /dev/null
+++ b/Lib/javascript/jsc/stl.i
@@ -0,0 +1,10 @@
+/* -----------------------------------------------------------------------------
+ * stl.i
+ * ----------------------------------------------------------------------------- */
+
+%include <std_common.i>
+%include <std_string.i>
+%include <std_vector.i>
+%include <std_map.i>
+%include <std_pair.i>
+
diff --git a/Lib/javascript/jsc/typemaps.i b/Lib/javascript/jsc/typemaps.i
new file mode 100644
index 000000000..d3d8afb19
--- /dev/null
+++ b/Lib/javascript/jsc/typemaps.i
@@ -0,0 +1,148 @@
+/* -----------------------------------------------------------------------------
+ * typemaps.i
+ *
+ * Pointer handling
+ * These mappings provide support for input/output arguments and common
+ * uses for C/C++ pointers.
+ * ----------------------------------------------------------------------------- */
+
+// INPUT typemaps.
+// These remap a C pointer to be an "INPUT" value which is passed by value
+// instead of reference.
+
+/*
+The following methods can be applied to turn a pointer into a simple
+"input" value. That is, instead of passing a pointer to an object,
+you would use a real value instead.
+
+ int *INPUT
+ short *INPUT
+ long *INPUT
+ long long *INPUT
+ unsigned int *INPUT
+ unsigned short *INPUT
+ unsigned long *INPUT
+ unsigned long long *INPUT
+ unsigned char *INPUT
+ bool *INPUT
+ float *INPUT
+ double *INPUT
+
+To use these, suppose you had a C function like this :
+
+ double fadd(double *a, double *b) {
+ return *a+*b;
+ }
+
+You could wrap it with SWIG as follows :
+
+ %include <typemaps.i>
+ double fadd(double *INPUT, double *INPUT);
+
+or you can use the %apply directive :
+
+ %include <typemaps.i>
+ %apply double *INPUT { double *a, double *b };
+ double fadd(double *a, double *b);
+
+*/
+
+// OUTPUT typemaps. These typemaps are used for parameters that
+// are output only. The output value is appended to the result as
+// a list element.
+
+/*
+The following methods can be applied to turn a pointer into an "output"
+value. When calling a function, no input value would be given for
+a parameter, but an output value would be returned. In the case of
+multiple output values, they are returned in the form of a Python tuple.
+
+ int *OUTPUT
+ short *OUTPUT
+ long *OUTPUT
+ long long *OUTPUT
+ unsigned int *OUTPUT
+ unsigned short *OUTPUT
+ unsigned long *OUTPUT
+ unsigned long long *OUTPUT
+ unsigned char *OUTPUT
+ bool *OUTPUT
+ float *OUTPUT
+ double *OUTPUT
+
+For example, suppose you were trying to wrap the modf() function in the
+C math library which splits x into integral and fractional parts (and
+returns the integer part in one of its parameters).K:
+
+ double modf(double x, double *ip);
+
+You could wrap it with SWIG as follows :
+
+ %include <typemaps.i>
+ double modf(double x, double *OUTPUT);
+
+or you can use the %apply directive :
+
+ %include <typemaps.i>
+ %apply double *OUTPUT { double *ip };
+ double modf(double x, double *ip);
+
+The Python output of the function would be a tuple containing both
+output values.
+
+*/
+
+// INOUT
+// Mappings for an argument that is both an input and output
+// parameter
+
+/*
+The following methods can be applied to make a function parameter both
+an input and output value. This combines the behavior of both the
+"INPUT" and "OUTPUT" methods described earlier. Output values are
+returned in the form of a Python tuple.
+
+ int *INOUT
+ short *INOUT
+ long *INOUT
+ long long *INOUT
+ unsigned int *INOUT
+ unsigned short *INOUT
+ unsigned long *INOUT
+ unsigned long long *INOUT
+ unsigned char *INOUT
+ bool *INOUT
+ float *INOUT
+ double *INOUT
+
+For example, suppose you were trying to wrap the following function :
+
+ void neg(double *x) {
+ *x = -(*x);
+ }
+
+You could wrap it with SWIG as follows :
+
+ %include <typemaps.i>
+ void neg(double *INOUT);
+
+or you can use the %apply directive :
+
+ %include <typemaps.i>
+ %apply double *INOUT { double *x };
+ void neg(double *x);
+
+Unlike C, this mapping does not directly modify the input value (since
+this makes no sense in Python). Rather, the modified input value shows
+up as the return value of the function. Thus, to apply this function
+to a Python variable you might do this :
+
+ x = neg(x)
+
+Note : previous versions of SWIG used the symbol 'BOTH' to mark
+input/output arguments. This is still supported, but will be slowly
+phased out in future releases.
+
+*/
+
+%include <typemaps/typemaps.swg>
diff --git a/Lib/javascript/v8/arrays_javascript.i b/Lib/javascript/v8/arrays_javascript.i
new file mode 100644
index 000000000..22b50be8f
--- /dev/null
+++ b/Lib/javascript/v8/arrays_javascript.i
@@ -0,0 +1,125 @@
+/* -----------------------------------------------------------------------------
+ * arrays_javascript.i
+ *
+ * These typemaps give more natural support for arrays. The typemaps are not efficient
+ * as there is a lot of copying of the array values whenever the array is passed to C/C++
+ * from JavaScript and vice versa. The JavaScript array is expected to be the same size as the C array.
+ * An exception is thrown if they are not.
+ *
+ * Example usage:
+ * Wrapping:
+ *
+ * %include <arrays_javascript.i>
+ * %inline %{
+ * extern int FiddleSticks[3];
+ * %}
+ *
+ * Use from JavaScript like this:
+ *
+ * var fs = [10, 11, 12];
+ * example.FiddleSticks = fs;
+ * fs = example.FiddleSticks;
+ * ----------------------------------------------------------------------------- */
+
+%fragment("SWIG_JSCGetIntProperty", "header", fragment=SWIG_AsVal_frag(int)) {}
+%fragment("SWIG_JSCGetNumberProperty", "header", fragment=SWIG_AsVal_frag(double)) {}
+
+%typemap(in, fragment="SWIG_JSCGetIntProperty") int[], int[ANY]
+ (int length = 0, v8::Local<v8::Array> array, v8::Local<v8::Value> jsvalue, int i = 0, int res = 0, $*1_ltype temp) {
+ if ($input->IsArray())
+ {
+ // Convert into Array
+ array = v8::Local<v8::Array>::Cast($input);
+
+ length = $1_dim0;
+
+ $1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length);
+
+ // Get each element from array
+ for (i = 0; i < length; i++)
+ {
+ jsvalue = array->Get(i);
+
+ // Get primitive value from JSObject
+ res = SWIG_AsVal(int)(jsvalue, &temp);
+ if (!SWIG_IsOK(res))
+ {
+ SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double");
+ }
+ arg$argnum[i] = temp;
+ }
+
+ }
+ else
+ {
+ SWIG_exception_fail(SWIG_ERROR, "$input is not JSObjectRef");
+ }
+}
+
+%typemap(freearg) int[], int[ANY] {
+ free($1);
+}
+
+%typemap(out, fragment=SWIG_From_frag(int)) int[], int[ANY] (int length = 0, int i = 0)
+{
+ length = $1_dim0;
+ v8::Local<v8::Array> array = v8::Array::New(length);
+
+ for (i = 0; i < length; i++)
+ {
+ array->Set(i, SWIG_From(int)($1[i]));
+ }
+
+
+ $result = array;
+}
+
+%typemap(in, fragment="SWIG_JSCGetNumberProperty") double[], double[ANY]
+ (int length = 0, v8::Local<v8::Array> array, v8::Local<v8::Value> jsvalue, int i = 0, int res = 0, $*1_ltype temp) {
+ if ($input->IsArray())
+ {
+ // Convert into Array
+ array = v8::Local<v8::Array>::Cast($input);
+
+ length = $1_dim0;
+
+ $1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length);
+
+ // Get each element from array
+ for (i = 0; i < length; i++)
+ {
+ jsvalue = array->Get(i);
+
+ // Get primitive value from JSObject
+ res = SWIG_AsVal(double)(jsvalue, &temp);
+ if (!SWIG_IsOK(res))
+ {
+ SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double");
+ }
+ arg$argnum[i] = temp;
+ }
+
+ }
+ else
+ {
+ SWIG_exception_fail(SWIG_ERROR, "$input is not JSObjectRef");
+ }
+}
+
+%typemap(freearg) double[], double[ANY] {
+ free($1);
+}
+
+%typemap(out, fragment=SWIG_From_frag(double)) double[], double[ANY] (int length = 0, int i = 0)
+{
+ length = $1_dim0;
+ v8::Local<v8::Array> array = v8::Array::New(length);
+
+ for (i = 0; i < length; i++)
+ {
+ array->Set(i, SWIG_From(double)($1[i]));
+ }
+
+
+ $result = array;
+}
diff --git a/Lib/javascript/v8/ccomplex.i b/Lib/javascript/v8/ccomplex.i
new file mode 100644
index 000000000..8eda920bb
--- /dev/null
+++ b/Lib/javascript/v8/ccomplex.i
@@ -0,0 +1,26 @@
+/* -----------------------------------------------------------------------------
+ * ccomplex.i
+ *
+ * C complex typemaps
+ * ISO C99: 7.3 Complex arithmetic <complex.h>
+ * ----------------------------------------------------------------------------- */
+
+
+%include <javscriptcomplex.swg>
+
+%{
+#include <complex.h>
+%}
+
+
+/* C complex constructor */
+#define CCplxConst(r, i) ((r) + I*(i))
+
+%swig_cplxflt_convn(float complex, CCplxConst, creal, cimag);
+%swig_cplxdbl_convn(double complex, CCplxConst, creal, cimag);
+%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
+
+/* declaring the typemaps */
+%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex);
+%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);
diff --git a/Lib/javascript/v8/cdata.i b/Lib/javascript/v8/cdata.i
new file mode 100644
index 000000000..367965990
--- /dev/null
+++ b/Lib/javascript/v8/cdata.i
@@ -0,0 +1 @@
+%include <typemaps/cdata.swg>
diff --git a/Lib/javascript/v8/complex.i b/Lib/javascript/v8/complex.i
new file mode 100644
index 000000000..4c3b3c5e2
--- /dev/null
+++ b/Lib/javascript/v8/complex.i
@@ -0,0 +1,6 @@
+#ifdef __cplusplus
+%include <std_complex.i>
+#else
+%include <ccomplex.i>
+#endif
+
diff --git a/Lib/javascript/v8/exception.i b/Lib/javascript/v8/exception.i
new file mode 100644
index 000000000..0246cfde8
--- /dev/null
+++ b/Lib/javascript/v8/exception.i
@@ -0,0 +1 @@
+%include <typemaps/exception.swg>
diff --git a/Lib/javascript/v8/javascript.swg b/Lib/javascript/v8/javascript.swg
new file mode 100644
index 000000000..3a83b6495
--- /dev/null
+++ b/Lib/javascript/v8/javascript.swg
@@ -0,0 +1,19 @@
+/* -----------------------------------------------------------------------------
+ * javascript.swg
+ *
+ * Javascript typemaps
+ * ----------------------------------------------------------------------------- */
+
+%include <typemaps/swigmacros.swg>
+
+%include <javascripttypemaps.swg>
+
+%include <javascriptruntime.swg>
+
+%include <javascripthelpers.swg>
+
+%include <javascriptkw.swg>
+
+%include <javascriptcode.swg>
+
+%include <javascriptinit.swg>
diff --git a/Lib/javascript/v8/javascriptcode.swg b/Lib/javascript/v8/javascriptcode.swg
new file mode 100644
index 000000000..67a81146e
--- /dev/null
+++ b/Lib/javascript/v8/javascriptcode.swg
@@ -0,0 +1,468 @@
+/* -----------------------------------------------------------------------------
+ * js_ctor: template for wrapping a ctor.
+ * - $jswrapper: wrapper of called ctor
+ * - $jslocals: locals part of wrapper
+ * - $jscode: code part of wrapper
+ * - $jsargcount: number of arguments
+ * - $jsmangledtype: mangled type of class
+ * ----------------------------------------------------------------------------- */
+
+%fragment("js_ctor", "templates") %{
+SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) {
+ v8::HandleScope scope;
+ v8::Handle<v8::Object> self = args.Holder();
+ $jslocals
+ if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
+ $jscode
+
+ SWIGV8_SetPrivateData(self, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN);
+ SWIGV8_RETURN(self);
+
+ goto fail;
+fail:
+ SWIGV8_RETURN(v8::Undefined());
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_veto_ctor: a vetoing ctor for abstract classes
+ * - $jswrapper: name of wrapper
+ * - $jsname: class name
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_veto_ctor", "templates")
+%{
+SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) {
+ v8::HandleScope scope;
+ SWIG_exception(SWIG_ERROR, "Class $jsname can not be instantiated");
+ SWIGV8_RETURN(v8::Undefined());
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_ctor_dispatcher: dispatcher for overloaded constructors
+ * - $jswrapper: name of wrapper
+ * - $jsname: class name
+ * - $jsdispatchcases: part containing code for dispatching
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_ctor_dispatcher", "templates")
+%{
+SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) {
+ v8::HandleScope scope;
+ OverloadErrorHandler errorHandler;
+ v8::Handle<v8::Value> self;
+
+ // switch all cases by means of series of if-returns.
+ $jsdispatchcases
+
+ // default:
+ SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for construction of $jsmangledname");
+
+fail:
+ SWIGV8_RETURN(v8::Undefined());
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_overloaded_ctor: template for wrapping a ctor.
+ * - $jswrapper: wrapper of called ctor
+ * - $jslocals: locals part of wrapper
+ * - $jscode: code part of wrapper
+ * - $jsargcount: number of arguments
+ * - $jsmangledtype: mangled type of class
+ * ----------------------------------------------------------------------------- */
+%fragment("js_overloaded_ctor", "templates") %{
+SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args, V8ErrorHandler& SWIGV8_ErrorHandler) {
+ v8::HandleScope scope;
+ v8::Handle<v8::Object> self = args.Holder();
+ $jslocals
+ if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
+ $jscode
+
+ SWIGV8_SetPrivateData(self, result, SWIGTYPE_$jsmangledtype, SWIG_POINTER_OWN);
+ SWIGV8_RETURN(self);
+
+ goto fail;
+fail:
+ SWIGV8_RETURN(v8::Undefined());
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_ctor_dispatch_case: template for a dispatch case for calling an overloaded ctor.
+ * - $jsargcount: number of arguments of called ctor
+ * - $jswrapper: wrapper of called ctor
+ *
+ * Note: a try-catch-like mechanism is used to switch cases
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_ctor_dispatch_case", "templates")
+%{
+ if(args.Length() == $jsargcount) {
+ errorHandler.err.Clear();
+#if SWIG_V8_VERSION < 0x031900
+ self = $jswrapper(args, errorHandler);
+ if(errorHandler.err.IsEmpty()) {
+ return scope.Close(self);
+ }
+#else
+ $jswrapper(args, errorHandler);
+ if(errorHandler.err.IsEmpty()) {
+ return;
+ }
+#endif
+ }
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_dtor: template for a destructor wrapper
+ * - $jsmangledname: mangled class name
+ * - $jstype: class type
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_dtor", "templates")
+%{
+
+#if (SWIG_V8_VERSION < 0x031900)
+void $jswrapper(v8::Persistent< v8::Value > object, void *parameter)
+{
+ SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
+#else
+void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object > * object, SWIGV8_Proxy *proxy)
+{
+#endif
+
+ if(proxy->swigCMemOwn && proxy->swigCObject) {
+#ifdef SWIGRUNTIME_DEBUG
+ printf("Deleting wrapped instance: %s\n", proxy->info->name);
+#endif
+ $jsfree proxy->swigCObject;
+ }
+ delete proxy;
+
+ object.Clear();
+#if (SWIG_V8_VERSION < 0x031900)
+ object.Dispose();
+#elif (SWIG_V8_VERSION < 0x032100)
+ object->Dispose(isolate);
+#else
+ object->Dispose();
+#endif
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_dtoroverride: template for a destructor wrapper
+ * - $jsmangledname: mangled class name
+ * - $jstype: class type
+ * - ${destructor_action}: The custom destructor action to invoke.
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_dtoroverride", "templates")
+%{
+#if (SWIG_V8_VERSION < 0x031900)
+void $jswrapper(v8::Persistent< v8::Value > object, void *parameter)
+{
+ SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
+#else
+void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object > * object, SWIGV8_Proxy *proxy)
+{
+#endif
+ if(proxy->swigCMemOwn && proxy->swigCObject) {
+ $jstype arg1 = ($jstype)proxy->swigCObject;
+ ${destructor_action}
+ }
+ delete proxy;
+
+#if (SWIG_V8_VERSION < 0x031900)
+ object.Dispose();
+#elif (SWIG_V8_VERSION < 0x032100)
+ object->Dispose(isolate);
+#else
+ object->Dispose();
+#endif
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_getter: template for getter function wrappers
+ * - $jswrapper: wrapper function name
+ * - $jslocals: locals part of wrapper
+ * - $jscode: code part of wrapper
+ * ----------------------------------------------------------------------------- */
+%fragment("js_getter", "templates")
+%{
+SwigV8ReturnValue $jswrapper(v8::Local<v8::String> property, const SwigV8PropertyCallbackInfo& info) {
+ v8::HandleScope scope;
+ v8::Handle<v8::Value> jsresult;
+ $jslocals
+ $jscode
+ SWIGV8_RETURN_INFO(jsresult, info);
+
+ goto fail;
+fail:
+ SWIGV8_RETURN_INFO(v8::Undefined(), info);
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_setter: template for setter function wrappers
+ * - $jswrapper: wrapper function name
+ * - $jslocals: locals part of wrapper
+ * - $jscode: code part of wrapper
+ * ----------------------------------------------------------------------------- */
+%fragment("js_setter", "templates")
+%{
+void $jswrapper(v8::Local<v8::String> property, v8::Local<v8::Value> value,
+ const SwigV8PropertyCallbackInfoVoid& info) {
+ v8::HandleScope scope;
+ $jslocals
+ $jscode
+ goto fail;
+fail:
+ return;
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_function: template for function wrappers
+ * - $jswrapper: wrapper function name
+ * - $jslocals: locals part of wrapper
+ * - $jscode: code part of wrapper
+ * ----------------------------------------------------------------------------- */
+%fragment("js_function", "templates")
+%{
+SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) {
+ v8::HandleScope scope;
+ v8::Handle<v8::Value> jsresult;
+ $jslocals
+ if(args.Length() != $jsargcount) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for $jswrapper.");
+
+ $jscode
+ SWIGV8_RETURN(jsresult);
+
+ goto fail;
+fail:
+ SWIGV8_RETURN(v8::Undefined());
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_function_dispatcher: template for a function dispatcher for overloaded functions
+ * - $jswrapper: wrapper function name
+ * - $jsname: name of the wrapped function
+ * - $jslocals: locals part of wrapper
+ * - $jscode: code part of wrapper
+ * ----------------------------------------------------------------------------- */
+%fragment("js_function_dispatcher", "templates")
+%{
+SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args) {
+ v8::HandleScope scope;
+ v8::Handle<v8::Value> jsresult;
+ OverloadErrorHandler errorHandler;
+ $jscode
+
+ SWIG_exception_fail(SWIG_ERROR, "Illegal arguments for function $jsname.");
+
+ goto fail;
+fail:
+ SWIGV8_RETURN(v8::Undefined());
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_overloaded_function: template for a overloaded function
+ * - $jswrapper: wrapper function name
+ * - $jslocals: locals part of wrapper
+ * - $jscode: code part of wrapper
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_overloaded_function", "templates")
+%{
+SwigV8ReturnValue $jswrapper(const SwigV8Arguments& args, V8ErrorHandler& SWIGV8_ErrorHandler)
+{
+ v8::HandleScope scope;
+ v8::Handle<v8::Value> jsresult;
+ $jslocals
+ $jscode
+ SWIGV8_RETURN(jsresult);
+
+ goto fail;
+fail:
+ SWIGV8_RETURN(v8::Undefined());
+}
+%}
+
+/* -----------------------------------------------------------------------------
+ * js_function_dispatch_case: template for a case used in the function dispatcher
+ * - $jswrapper: wrapper function name
+ * - $jsargcount: number of arguments of overloaded function
+ * - $jscode: code part of wrapper
+ * ----------------------------------------------------------------------------- */
+%fragment ("js_function_dispatch_case", "templates")
+%{
+
+ if(args.Length() == $jsargcount) {
+ errorHandler.err.Clear();
+#if (SWIG_V8_VERSION < 0x031900)
+ jsresult = $jswrapper(args, errorHandler);
+ if(errorHandler.err.IsEmpty()) {
+ return scope.Close(jsresult);
+ }
+#else
+ $jswrapper(args, errorHandler);
+ if(errorHandler.err.IsEmpty()) {
+ return;
+ }
+#endif
+ }
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsv8_declare_class_template: template for a class template declaration.
+ * - $jsmangledname: mangled class name
+ * ----------------------------------------------------------------------------- */
+%fragment("jsv8_declare_class_template", "templates")
+%{
+ SWIGV8_ClientData $jsmangledname_clientData;
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsv8_define_class_template: template for a class template definition.
+ * - $jsmangledname: mangled class name
+ * - $jsmangledtype: mangled class type
+ * - $jsdtor: the dtor wrapper
+ * ----------------------------------------------------------------------------- */
+%fragment("jsv8_define_class_template", "templates")
+%{
+ v8::Handle<v8::FunctionTemplate> $jsmangledname_class = SWIGV8_CreateClassTemplate("$jsmangledname");
+#if (SWIG_V8_VERSION < 0x031900)
+ $jsmangledname_clientData.class_templ = v8::Persistent<v8::FunctionTemplate>::New($jsmangledname_class);
+#else
+ $jsmangledname_clientData.class_templ.Reset(v8::Isolate::GetCurrent(), $jsmangledname_class);
+#endif
+ $jsmangledname_clientData.dtor = $jsdtor;
+ if (SWIGTYPE_$jsmangledtype->clientdata == 0) {
+ SWIGTYPE_$jsmangledtype->clientdata = &$jsmangledname_clientData;
+ }
+%}
+
+
+/* -----------------------------------------------------------------------------
+ * jsv8_inherit: template for an class inherit statement.
+ * - $jsmangledname: mangled class name
+ * - $jsbaseclass: mangled name of the base class
+ * ----------------------------------------------------------------------------- */
+%fragment("jsv8_inherit", "templates")
+%{
+ if (SWIGTYPE_p$jsbaseclass->clientdata && !(static_cast<SWIGV8_ClientData *>(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ.IsEmpty()))
+ {
+#if (SWIG_V8_VERSION < 0x031900)
+ $jsmangledname_class->Inherit(static_cast<SWIGV8_ClientData *>(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ);
+#else
+ $jsmangledname_class->Inherit(
+ v8::Handle<v8::FunctionTemplate>::New(
+ v8::Isolate::GetCurrent(),
+ static_cast<SWIGV8_ClientData *>(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ)
+ );
+#endif
+
+#ifdef SWIGRUNTIME_DEBUG
+ printf("Inheritance successful $jsmangledname $jsbaseclass\n");
+#endif
+ } else {
+#ifdef SWIGRUNTIME_DEBUG
+ printf("Unable to inherit baseclass, it didn't exist $jsmangledname $jsbaseclass\n");
+#endif
+ }
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsv8_create_class_instance: template for creating an class object.
+ * - $jsname: class name
+ * - $jsmangledname: mangled class name
+ * ----------------------------------------------------------------------------- */
+%fragment("jsv8_create_class_instance", "templates")
+%{
+ v8::Handle<v8::FunctionTemplate> $jsmangledname_class_0 = SWIGV8_CreateClassTemplate("$jsname");
+ $jsmangledname_class_0->SetCallHandler($jsctor);
+ $jsmangledname_class_0->Inherit($jsmangledname_class);
+ $jsmangledname_class_0->SetHiddenPrototype(true);
+ v8::Handle<v8::Object> $jsmangledname_obj = $jsmangledname_class_0->GetFunction();
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsv8_register_class: template for a statement that registers a class in a parent namespace.
+ * - $jsname: class name
+ * - $jsmangledname: mangled class name
+ * - $jsparent: mangled name of parent namespace
+ * ----------------------------------------------------------------------------- */
+%fragment("jsv8_register_class", "templates")
+%{
+ $jsparent_obj->Set(v8::String::NewSymbol("$jsname"), $jsmangledname_obj);
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsv8_create_namespace: template for a statement that creates a namespace object.
+ * - $jsmangledname: mangled namespace name
+ * ----------------------------------------------------------------------------- */
+%fragment("jsv8_create_namespace", "templates")
+%{
+ v8::Handle<v8::Object> $jsmangledname_obj = v8::Object::New();
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsv8_register_namespace: template for a statement that registers a namespace in a parent namespace.
+ * - $jsname: name of namespace
+ * - $jsmangledname: mangled name of namespace
+ * - $jsparent: mangled name of parent namespace
+ * ----------------------------------------------------------------------------- */
+%fragment("jsv8_register_namespace", "templates")
+%{
+ $jsparent_obj->Set(v8::String::NewSymbol("$jsname"), $jsmangledname_obj);
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsv8_register_member_function: template for a statement that registers a member function.
+ * - $jsmangledname: mangled class name
+ * - $jsname: name of the function
+ * - $jswrapper: wrapper of the member function
+ * ----------------------------------------------------------------------------- */
+%fragment("jsv8_register_member_function", "templates")
+%{
+ SWIGV8_AddMemberFunction($jsmangledname_class, "$jsname", $jswrapper);
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsv8_register_member_variable: template for a statement that registers a member variable.
+ * - $jsmangledname: mangled class name
+ * - $jsname: name of the function
+ * - $jsgetter: wrapper of the getter function
+ * - $jssetter: wrapper of the setter function
+ * ----------------------------------------------------------------------------- */
+%fragment("jsv8_register_member_variable", "templates")
+%{
+ SWIGV8_AddMemberVariable($jsmangledname_class, "$jsname", $jsgetter, $jssetter);
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsv8_register_static_function: template for a statement that registers a static class function.
+ * - $jsname: function name
+ * - $jswrapper: wrapper of the function
+ * - $jsparent: mangled name of parent namespace
+ *
+ * Note: this template is also used for global functions.
+ * ----------------------------------------------------------------------------- */
+%fragment("jsv8_register_static_function", "templates")
+%{
+ SWIGV8_AddStaticFunction($jsparent_obj, "$jsname", $jswrapper);
+%}
+
+/* -----------------------------------------------------------------------------
+ * jsv8_register_static_variable: template for a statement that registers a static variable.
+ * - $jsname: variable name
+ * - $jsparent: mangled name of parent namespace
+ * - $jsgetter: wrapper of the getter function
+ * - $jssetter: wrapper of the setter function
+ *
+ * Note: this template is also used for global variables.
+ * ----------------------------------------------------------------------------- */
+%fragment("jsv8_register_static_variable", "templates")
+%{
+ SWIGV8_AddStaticVariable($jsparent_obj, "$jsname", $jsgetter, $jssetter);
+%}
diff --git a/Lib/javascript/v8/javascriptcomplex.swg b/Lib/javascript/v8/javascriptcomplex.swg
new file mode 100644
index 000000000..70c5baffb
--- /dev/null
+++ b/Lib/javascript/v8/javascriptcomplex.swg
@@ -0,0 +1,123 @@
+/*
+ Defines the As/From converters for double/float complex, you need to
+ provide complex Type, the Name you want to use in the converters,
+ the complex Constructor method, and the Real and Imag complex
+ accessor methods.
+
+ See the std_complex.i and ccomplex.i for concret examples.
+*/
+
+/* the common from converter */
+%define %swig_fromcplx_conv(Type, Real, Imag)
+%fragment(SWIG_From_frag(Type),"header",
+ fragment=SWIG_From_frag(double))
+{
+SWIGINTERNINLINE v8::Handle<v8::Value>
+SWIG_From_dec(Type)(%ifcplusplus(const Type&, Type) c)
+{
+ v8::HandleScope scope;
+ v8::Local<v8::Array> vals = v8::Array::New(2);
+
+ vals->Set(0, SWIG_From(double)(Real(c)));
+ vals->Set(1, SWIG_From(double)(Imag(c)));
+ return scope.Close(vals);
+}
+}
+%enddef
+
+/* the double case */
+%define %swig_cplxdbl_conv(Type, Constructor, Real, Imag)
+%fragment(SWIG_AsVal_frag(Type),"header",
+ fragment=SWIG_AsVal_frag(double))
+{
+SWIGINTERN int
+SWIG_AsVal_dec(Type) (v8::Handle<v8::Value> o, Type* val)
+{
+ v8::HandleScope scope;
+
+ if (o->IsArray()) {
+ v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(o);
+
+ if(array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2].");
+ double re, im;
+ int res;
+
+ res = SWIG_AsVal(double)(array->Get(0), &re);
+ if(!SWIG_IsOK(res)) {
+ return SWIG_TypeError;
+ }
+
+ res = SWIG_AsVal(double)(array->Get(1), &im);
+ if(!SWIG_IsOK(res)) {
+ return SWIG_TypeError;
+ }
+
+ if (val) *val = Constructor(re, im);
+ return SWIG_OK;
+ } else if(o->IsNumber()){
+ double d;
+ int res = SWIG_AddCast(SWIG_AsVal(double)(o, &d));
+ if (SWIG_IsOK(res)) {
+ if (val) *val = Constructor(d, 0.0);
+ return res;
+ }
+ }
+ return SWIG_TypeError;
+}
+}
+%swig_fromcplx_conv(Type, Real, Imag);
+%enddef
+
+/* the float case */
+%define %swig_cplxflt_conv(Type, Constructor, Real, Imag)
+%fragment(SWIG_AsVal_frag(Type),"header",
+ fragment=SWIG_AsVal_frag(float)) {
+SWIGINTERN int
+SWIG_AsVal_dec(Type) (v8::Handle<v8::Value> o, Type* val)
+{
+ v8::HandleScope scope;
+
+ if (o->IsArray()) {
+ v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(o);
+
+ if(array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2].");
+ double re, im;
+ int res;
+
+ res = SWIG_AsVal(double)(array->Get(0), &re);
+ if(!SWIG_IsOK(res)) {
+ return SWIG_TypeError;
+ }
+
+ res = SWIG_AsVal(double)(array->Get(1), &im);
+ if(!SWIG_IsOK(res)) {
+ return SWIG_TypeError;
+ }
+
+ if ((-FLT_MAX <= re && re <= FLT_MAX) && (-FLT_MAX <= im && im <= FLT_MAX)) {
+ if (val) *val = Constructor(%numeric_cast(re, float),
+ %numeric_cast(im, float));
+ return SWIG_OK;
+ } else {
+ return SWIG_OverflowError;
+ }
+ } else if(o->IsNumber()){
+ float re;
+ int res = SWIG_AddCast(SWIG_AsVal(float)(o, &re));
+ if (SWIG_IsOK(res)) {
+ if (val) *val = Constructor(re, 0.0);
+ return res;
+ }
+ }
+ return SWIG_TypeError;
+}
+}
+%swig_fromcplx_conv(Type, Real, Imag);
+%enddef
+
+#define %swig_cplxflt_convn(Type, Constructor, Real, Imag) \
+%swig_cplxflt_conv(Type, Constructor, Real, Imag)
+
+
+#define %swig_cplxdbl_convn(Type, Constructor, Real, Imag) \
+%swig_cplxdbl_conv(Type, Constructor, Real, Imag)
diff --git a/Lib/javascript/v8/javascriptfragments.swg b/Lib/javascript/v8/javascriptfragments.swg
new file mode 100644
index 000000000..4778bf033
--- /dev/null
+++ b/Lib/javascript/v8/javascriptfragments.swg
@@ -0,0 +1,23 @@
+/*
+
+ Create a file with this name, 'javascriptfragments.swg', in your working
+ directory and add all the %fragments you want to take precedence
+ over the default ones defined by swig.
+
+ For example, if you add:
+
+ %fragment(SWIG_AsVal_frag(int),"header") {
+ SWIGINTERNINLINE int
+ SWIG_AsVal(int)(PyObject *obj, int *val)
+ {
+ <your code here>;
+ }
+ }
+
+ this will replace the code used to retrieve an integer value for all
+ the typemaps that need it, including:
+
+ int, std::vector<int>, std::list<std::pair<int,int> >, etc.
+
+
+*/
diff --git a/Lib/javascript/v8/javascripthelpers.swg b/Lib/javascript/v8/javascripthelpers.swg
new file mode 100644
index 000000000..8da6627e2
--- /dev/null
+++ b/Lib/javascript/v8/javascripthelpers.swg
@@ -0,0 +1,87 @@
+%insert(runtime) %{
+
+// Note: since 3.19 there are new CallBack types, since 03.21.9 the old ones have been removed
+#if SWIG_V8_VERSION < 0x031900
+typedef v8::InvocationCallback SwigV8FunctionCallback;
+typedef v8::AccessorGetter SwigV8AccessorGetterCallback;
+typedef v8::AccessorSetter SwigV8AccessorSetterCallback;
+typedef v8::AccessorInfo SwigV8PropertyCallbackInfoVoid;
+#else
+typedef v8::FunctionCallback SwigV8FunctionCallback;
+typedef v8::AccessorGetterCallback SwigV8AccessorGetterCallback;
+typedef v8::AccessorSetterCallback SwigV8AccessorSetterCallback;
+typedef v8::PropertyCallbackInfo<void> SwigV8PropertyCallbackInfoVoid;
+#endif
+
+/**
+ * Creates a class template for a class with specified initialization function.
+ */
+v8::Handle<v8::FunctionTemplate> SWIGV8_CreateClassTemplate(const char* symbol) {
+ v8::HandleScope scope;
+ v8::Local<v8::FunctionTemplate> class_templ = v8::FunctionTemplate::New();
+ class_templ->SetClassName(v8::String::NewSymbol(symbol));
+
+ v8::Handle<v8::ObjectTemplate> inst_templ = class_templ->InstanceTemplate();
+ inst_templ->SetInternalFieldCount(1);
+
+ v8::Handle<v8::ObjectTemplate> equals_templ = class_templ->PrototypeTemplate();
+ equals_templ->Set(v8::String::NewSymbol("equals"), v8::FunctionTemplate::New(_SWIGV8_wrap_equals));
+
+ v8::Handle<v8::ObjectTemplate> cptr_templ = class_templ->PrototypeTemplate();
+ cptr_templ->Set(v8::String::NewSymbol("getCPtr"), v8::FunctionTemplate::New(_wrap_getCPtr));
+
+ return scope.Close(class_templ);
+}
+
+/**
+ * Registers a class method with given name for a given class template.
+ */
+void SWIGV8_AddMemberFunction(v8::Handle<v8::FunctionTemplate> class_templ, const char* symbol,
+ SwigV8FunctionCallback _func) {
+ v8::Handle<v8::ObjectTemplate> proto_templ = class_templ->PrototypeTemplate();
+ proto_templ->Set(v8::String::NewSymbol(symbol), v8::FunctionTemplate::New(_func));
+}
+
+/**
+ * Registers a class property with given name for a given class template.
+ */
+void SWIGV8_AddMemberVariable(v8::Handle<v8::FunctionTemplate> class_templ, const char* symbol,
+ SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter) {
+ v8::Handle<v8::ObjectTemplate> proto_templ = class_templ->InstanceTemplate();
+ proto_templ->SetAccessor(v8::String::NewSymbol(symbol), getter, setter);
+}
+
+/**
+ * Registers a class method with given name for a given object.
+ */
+void SWIGV8_AddStaticFunction(v8::Handle<v8::Object> obj, const char* symbol,
+ const SwigV8FunctionCallback& _func) {
+ obj->Set(v8::String::NewSymbol(symbol), v8::FunctionTemplate::New(_func)->GetFunction());
+}
+
+/**
+ * Registers a class method with given name for a given object.
+ */
+void SWIGV8_AddStaticVariable(v8::Handle<v8::Object> obj, const char* symbol,
+ SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter) {
+ obj->SetAccessor(v8::String::NewSymbol(symbol), getter, setter);
+}
+
+void JS_veto_set_variable(v8::Local<v8::String> property, v8::Local<v8::Value> value,
+ const SwigV8PropertyCallbackInfoVoid& info)
+{
+ char buffer[256];
+ char msg[512];
+ int res;
+
+ property->WriteUtf8(buffer, 256);
+ res = sprintf(msg, "Tried to write read-only variable: %s.", buffer);
+
+ if(res<0) {
+ SWIG_exception(SWIG_ERROR, "Tried to write read-only variable.");
+ } else {
+ SWIG_exception(SWIG_ERROR, msg);
+ }
+}
+
+%} // v8_helper_functions
diff --git a/Lib/javascript/v8/javascriptinit.swg b/Lib/javascript/v8/javascriptinit.swg
new file mode 100644
index 000000000..de1fe91f4
--- /dev/null
+++ b/Lib/javascript/v8/javascriptinit.swg
@@ -0,0 +1,118 @@
+%insert(init) %{
+
+#include <assert.h>
+
+SWIGRUNTIME void
+SWIG_V8_SetModule(void *, swig_module_info *swig_module) {
+ v8::Local<v8::Object> global_obj = v8::Context::GetCurrent()->Global();
+ v8::Local<v8::External> mod = v8::External::New(swig_module);
+ assert(!mod.IsEmpty());
+ global_obj->SetHiddenValue(v8::String::New("swig_module_info_data"), mod);
+}
+
+SWIGRUNTIME swig_module_info *
+SWIG_V8_GetModule(void *) {
+ v8::Local<v8::Object> global_obj = v8::Context::GetCurrent()->Global();
+ v8::Local<v8::Value> moduleinfo = global_obj->GetHiddenValue(v8::String::New("swig_module_info_data"));
+
+ if (moduleinfo.IsEmpty())
+ {
+ // It's not yet loaded
+ return 0;
+ }
+
+ v8::Local<v8::External> moduleinfo_extern = v8::Local<v8::External>::Cast(moduleinfo);
+
+ if (moduleinfo_extern.IsEmpty())
+ {
+ // Something's not right
+ return 0;
+ }
+
+ void *ptr = moduleinfo_extern->Value();
+ assert(ptr);
+ swig_module_info *retptr = static_cast<swig_module_info *>(ptr);
+ assert(retptr);
+ return retptr;
+}
+
+#define SWIG_GetModule(clientdata) SWIG_V8_GetModule(clientdata)
+#define SWIG_SetModule(clientdata, pointer) SWIG_V8_SetModule(clientdata, pointer)
+
+%}
+
+%insert(init) "swiginit.swg"
+
+// Open the initializer function definition here
+
+%fragment ("js_initializer_define", "templates") %{
+#define SWIGV8_INIT $jsname_initialize
+%}
+
+%insert(init) %{
+// Note: 'extern "C"'' disables name mangling which makes it easier to load the symbol manually
+// TODO: is it ok to do that?
+extern "C"
+#if (NODE_MODULE_VERSION < 0x000C)
+void SWIGV8_INIT (v8::Handle<v8::Object> exports)
+#else
+void SWIGV8_INIT (v8::Handle<v8::Object> exports, v8::Handle<v8::Object> /*module*/)
+#endif
+{
+ SWIG_InitializeModule(static_cast<void *>(&exports));
+
+ v8::HandleScope scope;
+ v8::Handle<v8::Object> exports_obj = exports;
+%}
+
+
+/* -----------------------------------------------------------------------------
+ * js_initializer: template for the module initializer function
+ * - $jsname: module name
+ * - $jsv8nspaces: part with code creating namespace objects
+ * - $jsv8classtemplates: part with code creating class templates
+ * - $jsv8wrappers: part with code that registers wrapper functions
+ * - $jsv8inheritance: part with inherit statements
+ * - $jsv8classinstances: part with code creating class objects
+ * - $jsv8staticwrappers: part with code adding static functions to class objects
+ * - $jsv8registerclasses: part with code that registers class objects in namespaces
+ * - $jsv8registernspaces: part with code that registers namespaces in parent namespaces
+ * ----------------------------------------------------------------------------- */
+%fragment("js_initializer", "templates")
+%{
+ // a class template for creating proxies of undefined types
+#if (SWIG_V8_VERSION < 0x031900)
+ SWIGV8_SWIGTYPE_Proxy_class_templ = v8::Persistent<v8::FunctionTemplate>::New(SWIGV8_CreateClassTemplate("SwigProxy"));
+#else
+ SWIGV8_SWIGTYPE_Proxy_class_templ.Reset(v8::Isolate::GetCurrent(), SWIGV8_CreateClassTemplate("SwigProxy"));
+#endif
+
+ /* create objects for namespaces */
+ $jsv8nspaces
+
+ /* create class templates */
+ $jsv8classtemplates
+
+ /* register wrapper functions */
+ $jsv8wrappers
+
+ /* setup inheritances */
+ $jsv8inheritance
+
+ /* class instances */
+ $jsv8classinstances
+
+ /* add static class functions and variables */
+ $jsv8staticwrappers
+
+ /* register classes */
+ $jsv8registerclasses
+
+ /* create and register namespace objects */
+ $jsv8registernspaces
+}
+
+#if defined(BUILDING_NODE_EXTENSION)
+NODE_MODULE($jsname, $jsname_initialize);
+#endif
+%}
diff --git a/Lib/javascript/v8/javascriptkw.swg b/Lib/javascript/v8/javascriptkw.swg
new file mode 100644
index 000000000..c3c118391
--- /dev/null
+++ b/Lib/javascript/v8/javascriptkw.swg
@@ -0,0 +1,40 @@
+#ifndef JAVASCRIPT_JAVASCRIPTKW_SWG_
+#define JAVASCRIPT_JAVASCRIPTKW_SWG_
+
+/* Warnings for Java keywords */
+#define JAVASCRIPTKW(x) %keywordwarn("'" `x` "' is a javascript keyword, renaming to '_"`x`"'",rename="_%s") `x`
+
+/* Taken from https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Reserved_Words */
+
+JAVASCRIPTKW(break);
+JAVASCRIPTKW(case);
+JAVASCRIPTKW(catch);
+JAVASCRIPTKW(continue);
+JAVASCRIPTKW(default);
+JAVASCRIPTKW(delete);
+JAVASCRIPTKW(do);
+JAVASCRIPTKW(else);
+JAVASCRIPTKW(finally);
+JAVASCRIPTKW(for);
+JAVASCRIPTKW(function);
+JAVASCRIPTKW(if);
+JAVASCRIPTKW(in);
+JAVASCRIPTKW(instanceof);
+JAVASCRIPTKW(new);
+JAVASCRIPTKW(return);
+JAVASCRIPTKW(switch);
+JAVASCRIPTKW(this);
+JAVASCRIPTKW(throw);
+JAVASCRIPTKW(try);
+JAVASCRIPTKW(typeof);
+JAVASCRIPTKW(var);
+JAVASCRIPTKW(void);
+JAVASCRIPTKW(while);
+JAVASCRIPTKW(with);
+
+/* others bad names if any*/
+// for example %namewarn("321:clone() is a javascript bad method name") *::clone();
+
+#undef JAVASCRIPTKW
+
+#endif //JAVASCRIPT_JAVASCRIPTKW_SWG_
diff --git a/Lib/javascript/v8/javascriptprimtypes.swg b/Lib/javascript/v8/javascriptprimtypes.swg
new file mode 100644
index 000000000..706a799b7
--- /dev/null
+++ b/Lib/javascript/v8/javascriptprimtypes.swg
@@ -0,0 +1,198 @@
+/* ------------------------------------------------------------
+ * Primitive Types
+ * ------------------------------------------------------------ */
+
+/* boolean */
+
+%fragment(SWIG_From_frag(bool),"header") {
+SWIGINTERNINLINE
+v8::Handle<v8::Value>
+SWIG_From_dec(bool)(bool value)
+{
+ return v8::Boolean::New(value);
+}
+}
+
+%fragment(SWIG_AsVal_frag(bool),"header",
+ fragment=SWIG_AsVal_frag(long)) {
+SWIGINTERN
+int SWIG_AsVal_dec(bool)(v8::Handle<v8::Value> obj, bool *val)
+{
+ if(!obj->IsBoolean()) {
+ return SWIG_ERROR;
+ }
+
+ if (val) *val = obj->BooleanValue();
+ return SWIG_OK;
+}
+}
+
+/* int */
+
+%fragment(SWIG_From_frag(int),"header") {
+SWIGINTERNINLINE
+v8::Handle<v8::Value> SWIG_From_dec(int)(int value)
+{
+ return v8::Int32::New(value);
+}
+}
+
+%fragment(SWIG_AsVal_frag(int),"header") {
+SWIGINTERN
+int SWIG_AsVal_dec(int)(v8::Handle<v8::Value> valRef, int* val)
+{
+ if (!valRef->IsNumber()) {
+ return SWIG_TypeError;
+ }
+ if(val) *val = valRef->IntegerValue();
+
+ return SWIG_OK;
+}
+}
+
+/* long */
+
+%fragment(SWIG_From_frag(long),"header") {
+SWIGINTERNINLINE
+v8::Handle<v8::Value> SWIG_From_dec(long)(long value)
+{
+ return v8::Number::New(value);
+}
+}
+
+%fragment(SWIG_AsVal_frag(long),"header",
+ fragment="SWIG_CanCastAsInteger") {
+SWIGINTERN
+int SWIG_AsVal_dec(long)(v8::Handle<v8::Value> obj, long* val)
+{
+ if (!obj->IsNumber()) {
+ return SWIG_TypeError;
+ }
+ if(val) *val = (long) obj->IntegerValue();
+
+ return SWIG_OK;
+}
+}
+
+/* unsigned long */
+
+%fragment(SWIG_From_frag(unsigned long),"header",
+ fragment=SWIG_From_frag(long)) {
+SWIGINTERNINLINE
+v8::Handle<v8::Value> SWIG_From_dec(unsigned long)(unsigned long value)
+{
+ return (value > LONG_MAX) ?
+ v8::Integer::NewFromUnsigned(value) : v8::Integer::New(%numeric_cast(value,long));
+}
+}
+
+%fragment(SWIG_AsVal_frag(unsigned long),"header",
+ fragment="SWIG_CanCastAsInteger") {
+SWIGINTERN
+int SWIG_AsVal_dec(unsigned long)(v8::Handle<v8::Value> obj, unsigned long *val)
+{
+ if(!obj->IsNumber()) {
+ return SWIG_TypeError;
+ }
+
+ long longVal = (long) obj->NumberValue();
+
+ if(longVal < 0) {
+ return SWIG_OverflowError;
+ }
+
+ if(val) *val = longVal;
+
+ return SWIG_OK;
+}
+}
+
+/* long long */
+// Note: these are copied from 'long' and probably need fixing
+
+%fragment(SWIG_From_frag(long long),"header",
+ fragment=SWIG_From_frag(long),
+ fragment="<limits.h>") {
+SWIGINTERNINLINE
+v8::Handle<v8::Value> SWIG_From_dec(long long)(long long value)
+{
+ return v8::Number::New(value);
+}
+}
+
+%fragment(SWIG_AsVal_frag(long long),"header",
+ fragment=SWIG_AsVal_frag(long),
+ fragment="SWIG_CanCastAsInteger",
+ fragment="<limits.h>") {
+SWIGINTERN
+int SWIG_AsVal_dec(long long)(v8::Handle<v8::Value> obj, long long* val)
+{
+ if (!obj->IsNumber()) {
+ return SWIG_TypeError;
+ }
+ if(val) *val = (long long) obj->IntegerValue();
+
+ return SWIG_OK;
+}
+}
+
+/* unsigned long long */
+// Note: these are copied from 'unsigned long' and probably need fixing
+
+%fragment(SWIG_From_frag(unsigned long long),"header",
+ fragment=SWIG_From_frag(long long),
+ fragment="<limits.h>") {
+SWIGINTERNINLINE
+v8::Handle<v8::Value> SWIG_From_dec(unsigned long long)(unsigned long long value)
+{
+ return (value > LONG_MAX) ?
+ v8::Integer::NewFromUnsigned(value) : v8::Integer::New(%numeric_cast(value,long));
+}
+}
+
+%fragment(SWIG_AsVal_frag(unsigned long long),"header",
+ fragment=SWIG_AsVal_frag(unsigned long),
+ fragment="SWIG_CanCastAsInteger",
+ fragment="<limits.h>") {
+SWIGINTERN
+int SWIG_AsVal_dec(unsigned long long)(v8::Handle<v8::Value> obj, unsigned long long *val)
+{
+ if(!obj->IsNumber()) {
+ return SWIG_TypeError;
+ }
+
+ long long longVal = (long long) obj->NumberValue();
+
+ if(longVal < 0) {
+ return SWIG_OverflowError;
+ }
+
+ if(val) *val = longVal;
+
+ return SWIG_OK;
+}
+}
+
+/* double */
+
+%fragment(SWIG_From_frag(double),"header") {
+SWIGINTERN
+v8::Handle<v8::Value> SWIG_From_dec(double) (double val)
+{
+ return v8::Number::New(val);
+}
+}
+
+%fragment(SWIG_AsVal_frag(double),"header") {
+SWIGINTERN
+int SWIG_AsVal_dec(double)(v8::Handle<v8::Value> obj, double *val)
+{
+ if(!obj->IsNumber()) {
+ return SWIG_TypeError;
+ }
+ if(val) *val = obj->NumberValue();
+
+ return SWIG_OK;
+}
+}
+
diff --git a/Lib/javascript/v8/javascriptrun.swg b/Lib/javascript/v8/javascriptrun.swg
new file mode 100644
index 000000000..2e0a46717
--- /dev/null
+++ b/Lib/javascript/v8/javascriptrun.swg
@@ -0,0 +1,462 @@
+/* ---------------------------------------------------------------------------
+ * Error handling
+ *
+ * ---------------------------------------------------------------------------*/
+
+#define SWIG_Error(code, msg) SWIGV8_ErrorHandler.error(code, msg)
+#define SWIG_exception(code, msg) SWIGV8_ErrorHandler.error(code, msg)
+#define SWIG_fail goto fail
+#define SWIGV8_OVERLOAD false
+
+void SWIG_V8_Raise(const char* msg) {
+ v8::ThrowException(v8::Exception::Error(v8::String::New(msg)));
+}
+
+/*
+ Note: There are two contexts for handling errors.
+ A static V8ErrorHandler is used in not overloaded methods.
+ For overloaded methods the throwing type checking mechanism is used
+ during dispatching. As V8 exceptions can not be resetted properly
+ the trick is to use a dynamic ErrorHandler with same local name as the global
+ one.
+
+ - See defintion of SWIG_Error above.
+ - See code templates 'JS_function_dispatcher', 'JS_functionwrapper_overload',
+ and 'JS_function_dispatch_case' in javascriptcode.swg
+
+*/
+class V8ErrorHandler {
+public:
+ virtual ~V8ErrorHandler() {}
+ virtual void error(int code, const char* msg) {
+ SWIG_V8_Raise(msg);
+ }
+};
+// this is used in usually
+V8ErrorHandler SWIGV8_ErrorHandler;
+
+// instances of this are used in overloaded functions
+class OverloadErrorHandler: public V8ErrorHandler {
+public:
+ virtual void error(int code, const char* msg) {
+ err = v8::Exception::Error(v8::String::New(msg));
+ if(code != SWIG_TypeError) {
+ v8::ThrowException(err);
+ }
+ }
+ v8::Handle<v8::Value> err;
+};
+
+// Note: these typedefs and defines are used to deal with v8 API changes since version 3.19.00
+
+#if (SWIG_V8_VERSION < 0x031900)
+typedef v8::Handle<v8::Value> SwigV8ReturnValue;
+typedef v8::Arguments SwigV8Arguments;
+typedef v8::AccessorInfo SwigV8PropertyCallbackInfo;
+#define SWIGV8_RETURN(val) return scope.Close(val)
+#define SWIGV8_RETURN_INFO(val, info) return scope.Close(val)
+#else
+typedef void SwigV8ReturnValue;
+typedef v8::FunctionCallbackInfo<v8::Value> SwigV8Arguments;
+typedef v8::PropertyCallbackInfo<v8::Value> SwigV8PropertyCallbackInfo;
+#define SWIGV8_RETURN(val) args.GetReturnValue().Set(val); return
+#define SWIGV8_RETURN_INFO(val, info) info.GetReturnValue().Set(val); return
+#endif
+
+
+/* ---------------------------------------------------------------------------
+ * Basic Proxy object
+ *
+ * ---------------------------------------------------------------------------*/
+
+// Note: to trigger the v8 gc more often one can tell v8 about the memory consumption
+// TODO: we could add a v8 specific parameter to control this value
+#define SWIGV8_AVG_OBJ_SIZE 1000
+
+class SWIGV8_Proxy {
+public:
+ SWIGV8_Proxy(): swigCMemOwn(false), swigCObject(0), info(0) {
+ v8::V8::AdjustAmountOfExternalAllocatedMemory(SWIGV8_AVG_OBJ_SIZE);
+ };
+
+ ~SWIGV8_Proxy() {
+#if (SWIG_V8_VERSION < 0x031900 || SWIG_V8_VERSION >= 0x032100)
+ handle.ClearWeak();
+ handle.Dispose();
+#else
+ handle.ClearWeak(v8::Isolate::GetCurrent());
+ handle.Dispose(v8::Isolate::GetCurrent());
+#endif
+
+ handle.Clear();
+ v8::V8::AdjustAmountOfExternalAllocatedMemory(-SWIGV8_AVG_OBJ_SIZE);
+ }
+
+ bool swigCMemOwn;
+ void *swigCObject;
+ swig_type_info *info;
+ v8::Persistent<v8::Object> handle;
+};
+
+class SWIGV8_ClientData {
+public:
+ v8::Persistent<v8::FunctionTemplate> class_templ;
+
+#if (SWIG_V8_VERSION < 0x031900)
+ void (*dtor) (v8::Persistent< v8::Value> object, void *parameter);
+#else
+ void (*dtor) (v8::Isolate *isolate, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy);
+#endif
+};
+
+v8::Persistent<v8::FunctionTemplate> SWIGV8_SWIGTYPE_Proxy_class_templ;
+
+int SWIG_V8_ConvertInstancePtr(v8::Handle<v8::Object> objRef, void** ptr, swig_type_info *info, int flags) {
+ v8::HandleScope scope;
+
+ if(objRef->InternalFieldCount() < 1) return SWIG_ERROR;
+
+#if (SWIG_V8_VERSION < 0x031900)
+ v8::Handle<v8::Value> cdataRef = objRef->GetInternalField(0);
+ SWIGV8_Proxy *cdata = static_cast<SWIGV8_Proxy *>(v8::External::Unwrap(cdataRef));
+#else
+ SWIGV8_Proxy *cdata = static_cast<SWIGV8_Proxy *>(objRef->GetAlignedPointerFromInternalField(0));
+#endif
+
+ if(cdata == NULL) {
+ return SWIG_ERROR;
+ }
+ if(cdata->info != info) {
+ swig_cast_info *tc = SWIG_TypeCheckStruct(cdata->info, info);
+ if (!tc && cdata->info->name) {
+ tc = SWIG_TypeCheck(cdata->info->name, info);
+ }
+ bool type_valid = tc != 0;
+ if(!type_valid) {
+ return SWIG_TypeError;
+ }
+ }
+ *ptr = cdata->swigCObject;
+ if(flags & SWIG_POINTER_DISOWN) {
+ cdata->swigCMemOwn = false;
+ }
+ return SWIG_OK;
+}
+
+#if (SWIG_V8_VERSION < 0x031900)
+void SWIGV8_Proxy_DefaultDtor(v8::Persistent< v8::Value > object, void *parameter)
+#else
+void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy)
+#endif
+{
+#if (SWIG_V8_VERSION < 0x031900)
+ SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
+#endif
+
+ delete proxy;
+}
+
+int SWIG_V8_GetInstancePtr(v8::Handle<v8::Value> valRef, void** ptr) {
+ if(!valRef->IsObject()) {
+ return SWIG_TypeError;
+ }
+ v8::Handle<v8::Object> objRef = valRef->ToObject();
+
+ if(objRef->InternalFieldCount() < 1) return SWIG_ERROR;
+
+#if (SWIG_V8_VERSION < 0x031900)
+ v8::Handle<v8::Value> cdataRef = objRef->GetInternalField(0);
+ SWIGV8_Proxy *cdata = static_cast<SWIGV8_Proxy *>(v8::External::Unwrap(cdataRef));
+#else
+ SWIGV8_Proxy *cdata = static_cast<SWIGV8_Proxy *>(objRef->GetAlignedPointerFromInternalField(0));
+#endif
+
+ if(cdata == NULL) {
+ return SWIG_ERROR;
+ }
+
+ *ptr = cdata->swigCObject;
+
+ return SWIG_OK;
+}
+
+void SWIGV8_SetPrivateData(v8::Handle<v8::Object> obj, void* ptr, swig_type_info *info, int flags) {
+ SWIGV8_Proxy* cdata = new SWIGV8_Proxy();
+ cdata->swigCObject = ptr;
+ cdata->swigCMemOwn = (flags & SWIG_POINTER_OWN) ? 1 : 0;
+ cdata->info = info;
+
+#if (SWIG_V8_VERSION < 0x031900)
+ obj->SetPointerInInternalField(0, cdata);
+ cdata->handle = v8::Persistent<v8::Object>::New(obj);
+#else
+ obj->SetAlignedPointerInInternalField(0, cdata);
+ cdata->handle.Reset(v8::Isolate::GetCurrent(), obj);
+#endif
+
+#if (SWIG_V8_VERSION < 0x031900)
+ // clientdata must be set for owned data as we need to register the dtor
+ if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) {
+ cdata->handle.MakeWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor);
+ } else {
+ cdata->handle.MakeWeak(cdata, SWIGV8_Proxy_DefaultDtor);
+ }
+ cdata->handle.MarkIndependent();
+#else
+ if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) {
+ cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor);
+ } else {
+ cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, SWIGV8_Proxy_DefaultDtor);
+ }
+
+#if (SWIG_V8_VERSION < 0x032100)
+ cdata->handle.MarkIndependent(v8::Isolate::GetCurrent());
+#else
+ cdata->handle.MarkIndependent();
+#endif
+
+#endif
+}
+
+int SWIG_V8_ConvertPtr(v8::Handle<v8::Value> valRef, void** ptr, swig_type_info *info, int flags) {
+ v8::HandleScope scope;
+
+ if(!valRef->IsObject()) {
+ return SWIG_TypeError;
+ }
+ v8::Handle<v8::Object> objRef = valRef->ToObject();
+ return SWIG_V8_ConvertInstancePtr(objRef, ptr, info, flags);
+}
+
+v8::Handle<v8::Object> SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, int flags) {
+ v8::HandleScope scope;
+ v8::Handle<v8::FunctionTemplate> class_templ;
+
+#if (SWIG_V8_VERSION < 0x031900)
+ if(info->clientdata != 0) {
+ class_templ = ((SWIGV8_ClientData*) info->clientdata)->class_templ;
+ } else {
+ class_templ = SWIGV8_SWIGTYPE_Proxy_class_templ;
+ }
+#else
+ v8::Isolate *iso = v8::Isolate::GetCurrent();
+
+ if(info->clientdata != 0) {
+ class_templ = v8::Handle<v8::FunctionTemplate>::New(iso, ((SWIGV8_ClientData*) info->clientdata)->class_templ);
+ } else {
+ class_templ = v8::Handle<v8::FunctionTemplate>::New(iso, SWIGV8_SWIGTYPE_Proxy_class_templ);
+ }
+#endif
+
+ v8::Handle<v8::Object> result = class_templ->InstanceTemplate()->NewInstance();
+ SWIGV8_SetPrivateData(result, ptr, info, flags);
+
+ return scope.Close(result);
+}
+
+#define SWIG_ConvertPtr(obj, ptr, info, flags) SWIG_V8_ConvertPtr(obj, ptr, info, flags)
+#define SWIG_NewPointerObj(ptr, info, flags) SWIG_V8_NewPointerObj(ptr, info, flags)
+
+#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_V8_ConvertInstancePtr(obj, pptr, type, flags)
+#define SWIG_NewInstanceObj(thisvalue, type, flags) SWIG_V8_NewPointerObj(thisvalue, type, flags)
+
+#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_V8_ConvertPtr(obj, pptr, type, 0)
+#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_V8_NewPointerObj(ptr, type, 0)
+
+#define SWIG_GetInstancePtr(obj, ptr) SWIG_V8_GetInstancePtr(obj, ptr)
+
+#if (SWIG_V8_VERSION < 0x031900)
+v8::Handle<v8::Value> _SWIGV8_wrap_equals(const v8::Arguments &args) {
+#else
+void _SWIGV8_wrap_equals(const v8::FunctionCallbackInfo<v8::Value>& args) {
+#endif
+ v8::HandleScope scope;
+ v8::Handle<v8::Value> jsresult;
+ void *arg1 = (void *) 0 ;
+ void *arg2 = (void *) 0 ;
+ bool result;
+ int res1;
+ int res2;
+
+ if(args.Length() != 1) SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments for equals.");
+
+ res1 = SWIG_GetInstancePtr(args.Holder(), &arg1);
+ if (!SWIG_IsOK(res1)) {
+ SWIG_exception_fail(SWIG_ERROR, "Could not get pointer from 'this' object for equals.");
+ }
+ res2 = SWIG_GetInstancePtr(args[0], &arg2);
+ if (!SWIG_IsOK(res2)) {
+ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "equals" "', argument " "1"" of type '" "void *""'");
+ }
+
+ result = (bool)(arg1 == arg2);
+ jsresult = v8::Boolean::New(result);
+
+ SWIGV8_RETURN(jsresult);
+ goto fail;
+fail:
+ SWIGV8_RETURN(v8::Undefined());
+}
+
+#if (SWIG_V8_VERSION < 0x031900)
+v8::Handle<v8::Value> _wrap_getCPtr(const v8::Arguments &args) {
+#else
+void _wrap_getCPtr(const v8::FunctionCallbackInfo<v8::Value>& args) {
+#endif
+ v8::HandleScope scope;
+ v8::Handle<v8::Value> jsresult;
+ void *arg1 = (void *) 0 ;
+ long result;
+ int res1;
+
+ res1 = SWIG_GetInstancePtr(args.Holder(), &arg1);
+ if (!SWIG_IsOK(res1)) {
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "getCPtr" "', argument " "1"" of type '" "void *""'");
+ }
+
+ result = (long)arg1;
+ jsresult = v8::Number::New(result);
+
+ SWIGV8_RETURN(jsresult);
+ goto fail;
+fail:
+ SWIGV8_RETURN(v8::Undefined());
+}
+
+/* ---------------------------------------------------------------------------
+ * PackedData object
+ *
+ * ---------------------------------------------------------------------------*/
+
+class SwigV8PackedData {
+public:
+ SwigV8PackedData(void *data, size_t size, swig_type_info *type): data(data), size(size), type(type) {};
+
+ ~SwigV8PackedData() {
+ };
+
+ void* data;
+ size_t size;
+ swig_type_info *type;
+
+ v8::Persistent<v8::Object> handle;
+};
+
+SWIGRUNTIMEINLINE
+int SwigV8Packed_Check(v8::Handle<v8::Value> valRef) {
+ v8::HandleScope scope;
+ v8::Handle<v8::Object> objRef = valRef->ToObject();
+ if(objRef->InternalFieldCount() < 1) return false;
+ v8::Handle<v8::Value> flag = objRef->GetHiddenValue(v8::String::New("__swig__packed_data__"));
+ return (flag->IsBoolean() && flag->BooleanValue());
+}
+
+SWIGRUNTIME
+swig_type_info* SwigV8Packed_UnpackData(v8::Handle<v8::Value> valRef, void *ptr, size_t size) {
+ if (SwigV8Packed_Check(valRef)) {
+ v8::HandleScope scope;
+ SwigV8PackedData *sobj;
+
+ v8::Handle<v8::Object> objRef = valRef->ToObject();
+
+#if (SWIG_V8_VERSION < 0x031900)
+ v8::Handle<v8::Value> cdataRef = objRef->GetInternalField(0);
+ sobj = static_cast<SwigV8PackedData*>(v8::External::Unwrap(cdataRef));
+#else
+ sobj = static_cast<SwigV8PackedData*>(objRef->GetAlignedPointerFromInternalField(0));
+#endif
+ if (sobj == NULL || sobj->size != size) return 0;
+ memcpy(ptr, sobj->data, size);
+ return sobj->type;
+ } else {
+ return 0;
+ }
+}
+
+SWIGRUNTIME
+int SWIGV8_ConvertPacked(v8::Handle<v8::Value> valRef, void *ptr, size_t sz, swig_type_info *ty) {
+ swig_type_info *to = SwigV8Packed_UnpackData(valRef, ptr, sz);
+ if (!to) return SWIG_ERROR;
+ if (ty) {
+ if (to != ty) {
+ /* check type cast? */
+ swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
+ if (!tc) return SWIG_ERROR;
+ }
+ }
+ return SWIG_OK;
+}
+
+#if (SWIG_V8_VERSION < 0x031900)
+void _wrap_SwigV8PackedData_delete(v8::Persistent< v8::Value > object, void *parameter)
+{
+ SwigV8PackedData *cdata = static_cast<SwigV8PackedData *>(parameter);
+#else
+void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persistent< v8::Object > * object, SwigV8PackedData *cdata)
+{
+#endif
+
+ delete cdata;
+
+#if (SWIG_V8_VERSION < 0x031900)
+ object.Clear();
+ object.Dispose();
+#elif (SWIG_V8_VERSION < 0x032100)
+ object->Dispose(isolate);
+#else
+ object->Dispose();
+#endif
+}
+
+SWIGRUNTIME
+v8::Handle<v8::Value> SWIGV8_NewPackedObj(void *data, size_t size, swig_type_info *type) {
+ v8::HandleScope scope;
+
+ SwigV8PackedData* cdata = new SwigV8PackedData(data, size, type);
+ v8::Handle<v8::Object> obj = v8::Object::New();
+
+ obj->SetHiddenValue(v8::String::New("__swig__packed_data__"), v8::Boolean::New(true));
+
+#if (SWIG_V8_VERSION < 0x031900)
+ obj->SetPointerInInternalField(0, cdata);
+ cdata->handle = v8::Persistent<v8::Object>::New(obj);
+#else
+ obj->SetAlignedPointerInInternalField(0, cdata);
+ cdata->handle.Reset(v8::Isolate::GetCurrent(), obj);
+#endif
+
+#if (SWIG_V8_VERSION < 0x031900)
+ cdata->handle.MakeWeak(cdata, _wrap_SwigV8PackedData_delete);
+ cdata->handle.MarkIndependent();
+#else
+ cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, _wrap_SwigV8PackedData_delete);
+# if (SWIG_V8_VERSION < 0x032100)
+ cdata->handle.MarkIndependent(v8::Isolate::GetCurrent());
+# else
+ cdata->handle.MarkIndependent();
+# endif
+#endif
+
+ return scope.Close(obj);
+}
+
+#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIGV8_ConvertPacked(obj, ptr, sz, ty)
+#define SWIG_NewMemberObj(ptr, sz, type) SWIGV8_NewPackedObj(ptr, sz, type)
+
+
+/* ---------------------------------------------------------------------------
+ * Support for IN/OUTPUT typemaps (see Lib/typemaps/inoutlist.swg)
+ *
+ * ---------------------------------------------------------------------------*/
+
+SWIGRUNTIME
+v8::Handle<v8::Value> SWIGV8_AppendOutput(v8::Handle<v8::Value> result, v8::Handle<v8::Value> obj) {
+ v8::HandleScope scope;
+ if (result->IsUndefined()) {
+ result = v8::Array::New();
+ }
+ v8::Handle<v8::Array> arr = v8::Handle<v8::Array>::Cast(result);
+ arr->Set(arr->Length(), obj);
+
+ return scope.Close(arr);
+}
diff --git a/Lib/javascript/v8/javascriptruntime.swg b/Lib/javascript/v8/javascriptruntime.swg
new file mode 100644
index 000000000..ea11b0837
--- /dev/null
+++ b/Lib/javascript/v8/javascriptruntime.swg
@@ -0,0 +1,55 @@
+/* -----------------------------------------------------------------------------
+ * javascriptruntime.swg
+ *
+ * ----------------------------------------------------------------------------- */
+
+// V8 Version Macro
+// ----------------
+// v8 does not (until now) provide a version macro - which is still discussed and may come soon.
+// Until then, we set a default version which can be overridden via command line using V8_VERSION:
+// swig -javascript -v8 -DV8_VERSION=0x031110
+// Or code in the interface file using SWIG_V8_VERSION:
+// %begin %{#define SWIG_V8_VERSION 0x031110%}
+
+%define %swig_v8_define_version(version)
+%insert("runtime") %{
+#ifndef SWIG_V8_VERSION
+#define SWIG_V8_VERSION version
+#endif
+%}
+%enddef
+
+#ifdef V8_VERSION
+%swig_v8_define_version(V8_VERSION)
+#else
+// HACK: defining a default version
+%swig_v8_define_version(0x031110)
+#endif
+
+
+// Node support
+// ------------
+
+#ifdef BUILDING_NODE_EXTENSION
+%insert("runtime") %{
+#include <node.h>
+%}
+#endif
+
+
+// V8 runtime
+// ----------
+
+%insert(runtime) %{
+#include <v8.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+%}
+
+%insert(runtime) "swigrun.swg"; /* SWIG API */
+%insert(runtime) "swigerrors.swg"; /* SWIG errors */
+
+%insert(runtime) "javascriptrun.swg"
+
diff --git a/Lib/javascript/v8/javascriptstrings.swg b/Lib/javascript/v8/javascriptstrings.swg
new file mode 100644
index 000000000..69b6836a8
--- /dev/null
+++ b/Lib/javascript/v8/javascriptstrings.swg
@@ -0,0 +1,59 @@
+
+/* ------------------------------------------------------------
+ * utility methods for char strings
+ * ------------------------------------------------------------ */
+%fragment("SWIG_AsCharPtrAndSize", "header", fragment="SWIG_pchar_descriptor") {
+SWIGINTERN int
+SWIG_AsCharPtrAndSize(v8::Handle<v8::Value> valRef, char** cptr, size_t* psize, int *alloc)
+{
+ if(valRef->IsString()) {
+ v8::Handle<v8::String> js_str = valRef->ToString();
+
+ size_t len = js_str->Utf8Length() + 1;
+ char* cstr = new char[len];
+ js_str->WriteUtf8(cstr, len);
+
+ if(alloc) *alloc = SWIG_NEWOBJ;
+ if(psize) *psize = len;
+ if(cptr) *cptr = cstr;
+
+ return SWIG_OK;
+ } else {
+ if(valRef->IsObject()) {
+ v8::Handle<v8::Object> obj = valRef->ToObject();
+ // try if the object is a wrapped char[]
+ swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
+ if (pchar_descriptor) {
+ void* vptr = 0;
+ if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) {
+ if (cptr) *cptr = (char *) vptr;
+ if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0;
+ if (alloc) *alloc = SWIG_OLDOBJ;
+ return SWIG_OK;
+ }
+ }
+ return SWIG_TypeError;
+ } else {
+ return SWIG_TypeError;
+ }
+ }
+}
+}
+
+%fragment("SWIG_FromCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
+SWIGINTERNINLINE v8::Handle<v8::Value>
+SWIG_FromCharPtrAndSize(const char* carray, size_t size)
+{
+ if (carray) {
+ if (size > INT_MAX) {
+ // TODO: handle extra long strings
+ return v8::Undefined();
+ } else {
+ v8::Handle<v8::String> js_str = v8::String::New(carray, size);
+ return js_str;
+ }
+ } else {
+ return v8::Undefined();
+ }
+}
+}
diff --git a/Lib/javascript/v8/javascripttypemaps.swg b/Lib/javascript/v8/javascripttypemaps.swg
new file mode 100644
index 000000000..90317a1c7
--- /dev/null
+++ b/Lib/javascript/v8/javascripttypemaps.swg
@@ -0,0 +1,43 @@
+/* ------------------------------------------------------------
+ * Typemap specializations for Javascript
+ * ------------------------------------------------------------ */
+
+/* ------------------------------------------------------------
+ * Fragment section
+ * ------------------------------------------------------------ */
+
+/* Include fundamental fragemt definitions */
+%include <typemaps/fragments.swg>
+
+/* Look for user fragments file. */
+%include <javascriptfragments.swg>
+
+/* Javascript fragments for fundamental types */
+%include <javascriptprimtypes.swg>
+
+/* Javascript fragments for char* strings */
+%include <javascriptstrings.swg>
+
+
+/* ------------------------------------------------------------
+ * Unified typemap section
+ * ------------------------------------------------------------ */
+
+/* Javascript types */
+
+#define SWIG_Object v8::Handle<v8::Value>
+#define VOID_Object v8::Undefined()
+
+/* Overload of the output/constant/exception/dirout handling */
+
+/* append output */
+#define SWIG_AppendOutput(result, obj) SWIGV8_AppendOutput(result, obj)
+
+/* set constant */
+#define SWIG_SetConstant(name, obj)
+
+/* raise */
+#define SWIG_Raise(obj, type, desc) SWIG_V8_Raise(type)
+
+/* Include the unified typemap library */
+%include <typemaps/swigtypemaps.swg>
diff --git a/Lib/javascript/v8/std_common.i b/Lib/javascript/v8/std_common.i
new file mode 100755
index 000000000..cee11e8ca
--- /dev/null
+++ b/Lib/javascript/v8/std_common.i
@@ -0,0 +1,5 @@
+%include <std_except.i>
+
+%apply size_t { std::size_t };
+%apply const size_t& { const std::size_t& };
+
diff --git a/Lib/javascript/v8/std_complex.i b/Lib/javascript/v8/std_complex.i
new file mode 100644
index 000000000..088a4fe7b
--- /dev/null
+++ b/Lib/javascript/v8/std_complex.i
@@ -0,0 +1,19 @@
+/*
+ * STD C++ complex typemaps
+ */
+
+%include <javascriptcomplex.swg>
+
+%{
+#include <complex>
+%}
+
+/* defining the complex as/from converters */
+
+%swig_cplxdbl_convn(std::complex<double>, std::complex<double>, std::real, std::imag)
+%swig_cplxflt_convn(std::complex<float>, std::complex<float>, std::real, std::imag)
+
+/* defining the typemaps */
+
+%typemaps_primitive(%checkcode(CPLXDBL), std::complex<double>);
+%typemaps_primitive(%checkcode(CPLXFLT), std::complex<float>);
diff --git a/Lib/javascript/v8/std_deque.i b/Lib/javascript/v8/std_deque.i
new file mode 100644
index 000000000..cb98f6c2f
--- /dev/null
+++ b/Lib/javascript/v8/std_deque.i
@@ -0,0 +1 @@
+%include <std/_std_deque.i>
diff --git a/Lib/javascript/v8/std_except.i b/Lib/javascript/v8/std_except.i
new file mode 100644
index 000000000..af98428f6
--- /dev/null
+++ b/Lib/javascript/v8/std_except.i
@@ -0,0 +1 @@
+%include <typemaps/std_except.swg>
diff --git a/Lib/javascript/v8/std_map.i b/Lib/javascript/v8/std_map.i
new file mode 100755
index 000000000..e7812f38a
--- /dev/null
+++ b/Lib/javascript/v8/std_map.i
@@ -0,0 +1,74 @@
+/* -----------------------------------------------------------------------------
+ * std_map.i
+ *
+ * SWIG typemaps for std::map
+ * ----------------------------------------------------------------------------- */
+
+%include <std_common.i>
+
+// ------------------------------------------------------------------------
+// std::map
+// ------------------------------------------------------------------------
+
+%{
+#include <map>
+#include <algorithm>
+#include <stdexcept>
+%}
+
+// exported class
+
+namespace std {
+
+ template<class K, class T> class map {
+ // add typemaps here
+ public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef K key_type;
+ typedef T mapped_type;
+ map();
+ map(const map<K,T> &);
+
+ unsigned int size() const;
+ bool empty() const;
+ void clear();
+ %extend {
+ const T& get(const K& key) throw (std::out_of_range) {
+ std::map<K,T >::iterator i = self->find(key);
+ if (i != self->end())
+ return i->second;
+ else
+ throw std::out_of_range("key not found");
+ }
+ void set(const K& key, const T& x) {
+ (*self)[key] = x;
+ }
+ void del(const K& key) throw (std::out_of_range) {
+ std::map<K,T >::iterator i = self->find(key);
+ if (i != self->end())
+ self->erase(i);
+ else
+ throw std::out_of_range("key not found");
+ }
+ bool has_key(const K& key) {
+ std::map<K,T >::iterator i = self->find(key);
+ return i != self->end();
+ }
+ }
+ };
+
+// Legacy macros (deprecated)
+%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
+#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary"
+%enddef
+
+%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
+#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary"
+%enddef
+
+%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
+#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary"
+%enddef
+
+}
diff --git a/Lib/javascript/v8/std_pair.i b/Lib/javascript/v8/std_pair.i
new file mode 100755
index 000000000..8d6057223
--- /dev/null
+++ b/Lib/javascript/v8/std_pair.i
@@ -0,0 +1,33 @@
+/* -----------------------------------------------------------------------------
+ * std_pair.i
+ *
+ * SWIG typemaps for std::pair
+ * ----------------------------------------------------------------------------- */
+
+%include <std_common.i>
+
+// ------------------------------------------------------------------------
+// std::pair
+// ------------------------------------------------------------------------
+
+%{
+#include <utility>
+%}
+
+namespace std {
+
+ template<class T, class U> struct pair {
+
+ pair();
+ pair(T first, U second);
+ pair(const pair& p);
+
+ template <class U1, class U2> pair(const pair<U1, U2> &p);
+
+ T first;
+ U second;
+ };
+
+ // add specializations here
+
+}
diff --git a/Lib/javascript/v8/std_string.i b/Lib/javascript/v8/std_string.i
new file mode 100755
index 000000000..5ad1ead27
--- /dev/null
+++ b/Lib/javascript/v8/std_string.i
@@ -0,0 +1,79 @@
+/* -----------------------------------------------------------------------------
+ * std_string.i
+ *
+ * Typemaps for std::string and const std::string&.
+ *
+ * To use non-const std::string references use the following %apply:
+ * %apply const std::string & {std::string &};
+ *
+ * ----------------------------------------------------------------------------- */
+
+%{
+#include <string>
+%}
+
+%fragment("SWIGV8_valueToString", "header", fragment="SWIG_AsCharPtrAndSize") {
+std::string* SWIGV8_valueToStringPtr(v8::Handle<v8::Value> val) {
+
+ if (!val->IsString()) return 0;
+
+ int alloc;
+ size_t size;
+ char* chars;
+ int res = SWIG_AsCharPtrAndSize(val, &chars, &size, &alloc);
+
+ if(res != SWIG_OK) {
+ v8::ThrowException(v8::Exception::TypeError(v8::String::New("Could not convert to string.")));
+ return 0;
+ }
+
+ // copies the data (again)
+ std::string *str = new std::string(chars);
+
+ if (alloc) delete[] chars;
+
+ return str;
+}
+}
+
+%fragment("SWIGV8_stringToValue", "header", fragment="SWIG_FromCharPtrAndSize") {
+v8::Handle<v8::Value> SWIGV8_stringToValue(const std::string &str) {
+ return SWIG_FromCharPtrAndSize(str.c_str(), str.length());
+}
+}
+
+namespace std {
+ %naturalvar string;
+
+ class string;
+
+ %typemap(in, fragment="SWIGV8_valueToString") string (std::string* tmp)
+ %{
+ tmp = SWIGV8_valueToStringPtr($input);
+ $1 = *tmp;
+ if (tmp == 0) { v8::ThrowException(v8::Exception::TypeError(v8::String::New("Null pointer."))); goto fail; }
+ if (tmp) delete tmp;
+ %}
+
+ %typemap(in, fragment="SWIGV8_valueToString") const string &
+ %{
+ $1 = SWIGV8_valueToStringPtr($input);
+ if ($1 == 0) { v8::ThrowException(v8::Exception::TypeError(v8::String::New("Null pointer."))); goto fail; }
+ %}
+
+ %typemap(freearg) const string &
+ %{
+ if ($1) delete $1;
+ %}
+
+ %typemap(out, fragment="SWIGV8_stringToValue") string
+ %{
+ $result = SWIGV8_stringToValue($1);
+ %}
+
+ %typemap(out, fragment="SWIGV8_stringToValue") const string &
+ %{
+ $result = SWIGV8_stringToValue(*$1);
+ %}
+
+}
diff --git a/Lib/javascript/v8/std_vector.i b/Lib/javascript/v8/std_vector.i
new file mode 100755
index 000000000..3f29b19c7
--- /dev/null
+++ b/Lib/javascript/v8/std_vector.i
@@ -0,0 +1,85 @@
+/* -----------------------------------------------------------------------------
+ * std_vector.i
+ * ----------------------------------------------------------------------------- */
+
+%include <std_common.i>
+
+%{
+#include <vector>
+#include <stdexcept>
+%}
+
+namespace std {
+
+ template<class T> class vector {
+ public:
+ typedef size_t size_type;
+ typedef T value_type;
+ typedef const value_type& const_reference;
+ vector();
+ vector(size_type n);
+ size_type size() const;
+ size_type capacity() const;
+ void reserve(size_type n);
+ %rename(isEmpty) empty;
+ bool empty() const;
+ void clear();
+ %rename(add) push_back;
+ void push_back(const value_type& x);
+ %extend {
+ const_reference get(int i) throw (std::out_of_range) {
+ int size = int(self->size());
+ if (i>=0 && i<size)
+ return (*self)[i];
+ else
+ throw std::out_of_range("vector index out of range");
+ }
+ void set(int i, const value_type& val) throw (std::out_of_range) {
+ int size = int(self->size());
+ if (i>=0 && i<size)
+ (*self)[i] = val;
+ else
+ throw std::out_of_range("vector index out of range");
+ }
+ }
+ };
+
+ // bool specialization
+ template<> class vector<bool> {
+ public:
+ typedef size_t size_type;
+ typedef bool value_type;
+ typedef bool const_reference;
+ vector();
+ vector(size_type n);
+ size_type size() const;
+ size_type capacity() const;
+ void reserve(size_type n);
+ %rename(isEmpty) empty;
+ bool empty() const;
+ void clear();
+ %rename(add) push_back;
+ void push_back(const value_type& x);
+ %extend {
+ const_reference get(int i) throw (std::out_of_range) {
+ int size = int(self->size());
+ if (i>=0 && i<size)
+ return (*self)[i];
+ else
+ throw std::out_of_range("vector index out of range");
+ }
+ void set(int i, const value_type& val) throw (std::out_of_range) {
+ int size = int(self->size());
+ if (i>=0 && i<size)
+ (*self)[i] = val;
+ else
+ throw std::out_of_range("vector index out of range");
+ }
+ }
+ };
+}
+
+%define specialize_std_vector(T)
+#warning "specialize_std_vector - specialization for type T no longer needed"
+%enddef
+
diff --git a/Lib/javascript/v8/stl.i b/Lib/javascript/v8/stl.i
new file mode 100755
index 000000000..04f86014f
--- /dev/null
+++ b/Lib/javascript/v8/stl.i
@@ -0,0 +1,10 @@
+/* -----------------------------------------------------------------------------
+ * stl.i
+ * ----------------------------------------------------------------------------- */
+
+%include <std_common.i>
+%include <std_string.i>
+%include <std_vector.i>
+%include <std_map.i>
+%include <std_pair.i>
+
diff --git a/Lib/javascript/v8/typemaps.i b/Lib/javascript/v8/typemaps.i
new file mode 100644
index 000000000..d3d8afb19
--- /dev/null
+++ b/Lib/javascript/v8/typemaps.i
@@ -0,0 +1,148 @@
+/* -----------------------------------------------------------------------------
+ * typemaps.i
+ *
+ * Pointer handling
+ * These mappings provide support for input/output arguments and common
+ * uses for C/C++ pointers.
+ * ----------------------------------------------------------------------------- */
+
+// INPUT typemaps.
+// These remap a C pointer to be an "INPUT" value which is passed by value
+// instead of reference.
+
+/*
+The following methods can be applied to turn a pointer into a simple
+"input" value. That is, instead of passing a pointer to an object,
+you would use a real value instead.
+
+ int *INPUT
+ short *INPUT
+ long *INPUT
+ long long *INPUT
+ unsigned int *INPUT
+ unsigned short *INPUT
+ unsigned long *INPUT
+ unsigned long long *INPUT
+ unsigned char *INPUT
+ bool *INPUT
+ float *INPUT
+ double *INPUT
+
+To use these, suppose you had a C function like this :
+
+ double fadd(double *a, double *b) {
+ return *a+*b;
+ }
+
+You could wrap it with SWIG as follows :
+
+ %include <typemaps.i>
+ double fadd(double *INPUT, double *INPUT);
+
+or you can use the %apply directive :
+
+ %include <typemaps.i>
+ %apply double *INPUT { double *a, double *b };
+ double fadd(double *a, double *b);
+
+*/
+
+// OUTPUT typemaps. These typemaps are used for parameters that
+// are output only. The output value is appended to the result as
+// a list element.
+
+/*
+The following methods can be applied to turn a pointer into an "output"
+value. When calling a function, no input value would be given for
+a parameter, but an output value would be returned. In the case of
+multiple output values, they are returned in the form of a Python tuple.
+
+ int *OUTPUT
+ short *OUTPUT
+ long *OUTPUT
+ long long *OUTPUT
+ unsigned int *OUTPUT
+ unsigned short *OUTPUT
+ unsigned long *OUTPUT
+ unsigned long long *OUTPUT
+ unsigned char *OUTPUT
+ bool *OUTPUT
+ float *OUTPUT
+ double *OUTPUT
+
+For example, suppose you were trying to wrap the modf() function in the
+C math library which splits x into integral and fractional parts (and
+returns the integer part in one of its parameters).K:
+
+ double modf(double x, double *ip);
+
+You could wrap it with SWIG as follows :
+
+ %include <typemaps.i>
+ double modf(double x, double *OUTPUT);
+
+or you can use the %apply directive :
+
+ %include <typemaps.i>
+ %apply double *OUTPUT { double *ip };
+ double modf(double x, double *ip);
+
+The Python output of the function would be a tuple containing both
+output values.
+
+*/
+
+// INOUT
+// Mappings for an argument that is both an input and output
+// parameter
+
+/*
+The following methods can be applied to make a function parameter both
+an input and output value. This combines the behavior of both the
+"INPUT" and "OUTPUT" methods described earlier. Output values are
+returned in the form of a Python tuple.
+
+ int *INOUT
+ short *INOUT
+ long *INOUT
+ long long *INOUT
+ unsigned int *INOUT
+ unsigned short *INOUT
+ unsigned long *INOUT
+ unsigned long long *INOUT
+ unsigned char *INOUT
+ bool *INOUT
+ float *INOUT
+ double *INOUT
+
+For example, suppose you were trying to wrap the following function :
+
+ void neg(double *x) {
+ *x = -(*x);
+ }
+
+You could wrap it with SWIG as follows :
+
+ %include <typemaps.i>
+ void neg(double *INOUT);
+
+or you can use the %apply directive :
+
+ %include <typemaps.i>
+ %apply double *INOUT { double *x };
+ void neg(double *x);
+
+Unlike C, this mapping does not directly modify the input value (since
+this makes no sense in Python). Rather, the modified input value shows
+up as the return value of the function. Thus, to apply this function
+to a Python variable you might do this :
+
+ x = neg(x)
+
+Note : previous versions of SWIG used the symbol 'BOTH' to mark
+input/output arguments. This is still supported, but will be slowly
+phased out in future releases.
+
+*/
+
+%include <typemaps/typemaps.swg>
diff --git a/Lib/lua/luarun.swg b/Lib/lua/luarun.swg
index 49d5848eb..d038f4af1 100644
--- a/Lib/lua/luarun.swg
+++ b/Lib/lua/luarun.swg
@@ -332,6 +332,11 @@ typedef struct {
lua_pushcfunction(L, f), \
lua_rawset(L,-3))
+#define SWIG_Lua_add_boolean(L,n,b) \
+ (lua_pushstring(L, n), \
+ lua_pushboolean(L, b), \
+ lua_rawset(L,-3))
+
/* special helper for allowing 'nil' for usertypes */
#define SWIG_isptrtype(L,I) (lua_isuserdata(L,I) || lua_isnil(L,I))
@@ -402,7 +407,7 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent
lua_rawsetp(L, parsed_tables_array, table);
int i;
int table_parsed = 0;
- int pairs_start = lua_gettop(L);
+ const int SWIGUNUSED pairs_start = lua_gettop(L);
for(i = 0;table[i].key.type != LUA_TNIL || table[i].value.type != LUA_TNIL;i++)
{
const swig_elua_entry *entry = table + i;
@@ -646,7 +651,7 @@ SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace
SWIGINTERN void SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, int reg)
{
/* 1 argument - table on the top of the stack */
- int begin = lua_gettop(L);
+ const int SWIGUNUSED begin = lua_gettop(L);
assert(lua_istable(L,-1)); /* just in case. This is supposed to be module table or parent namespace table */
lua_checkstack(L,5);
lua_newtable(L); /* namespace itself */
@@ -707,7 +712,7 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname);
SWIG_Lua_get_table(L,".bases");\
assert(lua_istable(L,-1));\
bases_count = lua_rawlen(L,-1);\
- int bases_table = lua_gettop(L);
+ const int bases_table = lua_gettop(L);
#define SWIG_LUA_GET_BASE_METATABLE(i,base_swig_type, valid)\
lua_rawgeti(L,bases_table,i+1);\
base_swig_type = 0;\
@@ -742,7 +747,8 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname);
typedef int (*swig_lua_base_iterator_func)(lua_State*,swig_type_info*, int, int *ret);
-SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, int first_arg, swig_lua_base_iterator_func func, int *const ret)
+SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info * SWIGUNUSED swig_type,
+ int first_arg, swig_lua_base_iterator_func func, int *const ret)
{
/* first_arg - position of the object in stack. Everything that is above are arguments
* and is passed to every evocation of the func */
@@ -756,7 +762,7 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, i
*ret = 0;
if(bases_count>0)
{
- int i;
+ size_t i;
int j;
int subcall_first_arg = lua_gettop(L) + 1;/* Here a copy of first_arg and arguments begin */
int valid = 1;
@@ -798,7 +804,7 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *swig_type, i
* It returns an error code. Number of function return values is passed inside 'ret'.
* first_arg is not used in this function because function always has 2 arguments.
*/
-SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int first_arg, int *ret)
+SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int SWIGUNUSED first_arg, int *ret)
{
/* there should be 2 params passed in
(1) userdata (not the meta table)
@@ -1016,7 +1022,51 @@ SWIGINTERN int SWIG_Lua_class_disown(lua_State *L)
return 0;
}
-/* gets the swig class registry (or creates it) */
+/* populate table at the top of the stack with metamethods that ought to be inherited */
+SWIGINTERN void SWIG_Lua_populate_inheritable_metamethods(lua_State *L)
+{
+ SWIG_Lua_add_boolean(L, "__add", 1);
+ SWIG_Lua_add_boolean(L, "__sub", 1);
+ SWIG_Lua_add_boolean(L, "__mul", 1);
+ SWIG_Lua_add_boolean(L, "__div", 1);
+ SWIG_Lua_add_boolean(L, "__mod", 1);
+ SWIG_Lua_add_boolean(L, "__pow", 1);
+ SWIG_Lua_add_boolean(L, "__unm", 1);
+ SWIG_Lua_add_boolean(L, "__len", 1 );
+ SWIG_Lua_add_boolean(L, "__concat", 1 );
+ SWIG_Lua_add_boolean(L, "__eq", 1);
+ SWIG_Lua_add_boolean(L, "__lt", 1);
+ SWIG_Lua_add_boolean(L, "__le", 1);
+ SWIG_Lua_add_boolean(L, "__call", 1);
+ SWIG_Lua_add_boolean(L, "__tostring", 1);
+ SWIG_Lua_add_boolean(L, "__gc", 0);
+}
+
+/* creates the swig registry */
+SWIGINTERN void SWIG_Lua_create_class_registry(lua_State *L)
+{
+ /* create main SWIG registry table */
+ lua_pushstring(L,"SWIG");
+ lua_newtable(L);
+ /* populate it with some predefined data */
+
+ /* .library table. Placeholder */
+ lua_pushstring(L,".library");
+ lua_newtable(L);
+ {
+ /* list of metamethods that class inherits from its bases */
+ lua_pushstring(L,"inheritable_metamethods");
+ lua_newtable(L);
+ /* populate with list of metamethods */
+ SWIG_Lua_populate_inheritable_metamethods(L);
+ lua_rawset(L,-3);
+ }
+ lua_rawset(L,-3);
+
+ lua_rawset(L,LUA_REGISTRYINDEX);
+}
+
+/* gets the swig registry (or creates it) */
SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L)
{
/* add this all into the swig registry: */
@@ -1025,15 +1075,27 @@ SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L)
if (!lua_istable(L,-1)) /* not there */
{ /* must be first time, so add it */
lua_pop(L,1); /* remove the result */
- lua_pushstring(L,"SWIG");
- lua_newtable(L);
- lua_rawset(L,LUA_REGISTRYINDEX);
+ SWIG_Lua_create_class_registry(L);
/* then get it */
lua_pushstring(L,"SWIG");
lua_rawget(L,LUA_REGISTRYINDEX);
}
}
+SWIGINTERN void SWIG_Lua_get_inheritable_metamethods(lua_State *L)
+{
+ SWIG_Lua_get_class_registry(L);
+ lua_pushstring(L, ".library");
+ lua_rawget(L,-2);
+ assert( !lua_isnil(L,-1) );
+ lua_pushstring(L, "inheritable_metamethods");
+ lua_rawget(L,-2);
+
+ /* Remove class registry and library table */
+ lua_remove(L,-2);
+ lua_remove(L,-2);
+}
+
/* Helper function to get the classes metatable from the register */
SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname)
{
@@ -1163,8 +1225,10 @@ SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State *L, swig_lua_class *
SWIG_Lua_add_namespace_details(L, clss->cls_static);
}
+SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss); /* forward declaration */
+
/* helper to recursively add class details (attributes & operations) */
-SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L,swig_lua_class *clss)
+SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L, swig_lua_class *clss)
{
int i;
/* Add bases to .bases table */
@@ -1201,12 +1265,195 @@ SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L,swig_lua_class
SWIG_Lua_add_function(L,clss->metatable[i].name,clss->metatable[i].func);
}
}
+
+#if !defined(SWIG_LUA_SQUASH_BASES)
+ /* Adding metamethods that are defined in base classes. If bases were squashed
+ * then it is obviously unnecessary
+ */
+ SWIG_Lua_add_class_user_metamethods(L, clss);
+#endif
+}
+
+/* Helpers to add user defined class metamedhods - __add, __sub etc. The helpers are needed
+ for the following issue: Lua runtime checks for metamethod existence with rawget function
+ ignoring our SWIG-provided __index and __newindex functions. Thus our inheritance-aware method
+ search algorithm doesn't work in such case. (Not to say that Lua runtime queries metamethod directly
+ in metatable and not in object).
+ Current solution is this: if somewhere in hierarchy metamethod __x is defined, then all descendants
+ are automatically given a special proxy __x that calls the real __x method.
+ Obvious idea - to copy __x instead of creating __x-proxy is wrong because if someone changes __x in runtime,
+ those changes must be reflected in all descendants.
+*/
+
+SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L); /*forward declaration*/
+
+/* The real function that resolves a metamethod.
+ * Function searches given class and all it's bases(recursively) for first instance of something that is
+ * not equal to SWIG_Lua_resolve_metatmethod. (Almost always this 'something' is actuall metamethod implementation
+ * and it is a SWIG-generated C function.). It returns value on the top of the L and there is no garbage below the
+ * answer.
+ * Returns 1 if found, 0 otherwise.
+ * clss is class which metatable we will search for method
+ * metamethod_name_idx is index in L where metamethod name (as string) lies
+ * skip_check allows to skip searching metamethod in givel clss and immideatelly go to searching in bases. skip_check
+ * is not caried to subsequent recursive calls - false is always passed. It is set to true only at first call from
+ * SWIG_Lua_resolve_metamethod
+ * */
+SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class *clss, int metamethod_name_idx,
+ int skip_check)
+{
+ /* This function is called recursively */
+ if (!skip_check) {
+ SWIG_Lua_get_class_metatable(L, clss->fqname);
+ lua_pushvalue(L, metamethod_name_idx);
+ lua_rawget(L,-2);
+ /* If this is cfunction and it is equal to SWIG_Lua_resolve_metamethod then
+ * this isn't the function we are looking for :)
+ * lua_tocfunction will return NULL if not cfunction
+ */
+ if (!lua_isnil(L,-1) && lua_tocfunction(L,-1) != SWIG_Lua_resolve_metamethod ) {
+ lua_remove(L,-2); /* removing class metatable */
+ return 1;
+ }
+ lua_pop(L,2); /* remove class metatable and query result */
+ }
+
+ /* Forwarding calls to bases */
+ int result = 0;
+ int i = 0;
+ for(i=0;clss->bases[i];i++)
+ {
+ result = SWIG_Lua_do_resolve_metamethod(L, clss->bases[i], metamethod_name_idx, 0);
+ if (result)
+ break;
+ }
+
+ return result;
+}
+
+/* The proxy function for metamethod. All parameters are passed as cclosure. Searches for actual method
+ * and calls it */
+SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L)
+{
+ lua_checkstack(L,5);
+ const int numargs = lua_gettop(L); /* number of arguments to pass to actuall metamethod */
+
+ /* Get upvalues from closure */
+ lua_pushvalue(L, lua_upvalueindex(1)); /*Get function name*/
+ const int metamethod_name_idx = lua_gettop(L);
+
+ lua_pushvalue(L, lua_upvalueindex(2));
+ const swig_lua_class* clss = (const swig_lua_class*)(lua_touserdata(L,-1));
+ lua_pop(L,1); /* remove lightuserdata with clss from stack */
+
+ /* Actuall work */
+ const int result = SWIG_Lua_do_resolve_metamethod(L, clss, metamethod_name_idx, 1);
+ if (!result) {
+ SWIG_Lua_pushferrstring(L,"The metamethod proxy is set, but it failed to find actuall metamethod. Memory corruption is most likely explanation.");
+ lua_error(L);
+ return 0;
+ }
+
+ lua_remove(L,-2); /* remove metamethod key */
+ lua_insert(L,1); /* move function to correct position */
+ lua_call(L, numargs, LUA_MULTRET);
+ return lua_gettop(L); /* return all results */
+}
+
+
+/* If given metamethod must be present in given class, then creates appropriate proxy
+ * Returns 1 if successfully added, 0 if not added because no base class has it, -1
+ * if method is defined in the class metatable itself
+ */
+SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *clss, const int metatable_index)
+{
+ /* metamethod name - on the top of the stack */
+ assert(lua_isstring(L,-1));
+
+ const int key_index = lua_gettop(L);
+
+ /* Check whether method is already defined in metatable */
+ lua_pushvalue(L,key_index); /* copy of the key */
+ lua_gettable(L,metatable_index);
+ if( !lua_isnil(L,-1) ) {
+ lua_pop(L,1);
+ return -1;
+ }
+ lua_pop(L,1);
+
+ /* Iterating over immediate bases */
+ int success = 0;
+ int i = 0;
+ for(i=0;clss->bases[i];i++)
+ {
+ const swig_lua_class *base = clss->bases[i];
+ SWIG_Lua_get_class_metatable(L, base->fqname);
+ lua_pushvalue(L, key_index);
+ lua_rawget(L, -2);
+ if( !lua_isnil(L,-1) ) {
+ lua_pushvalue(L, key_index);
+
+ /* Add proxy function */
+ lua_pushvalue(L, key_index); /* first closure value is function name */
+ lua_pushlightuserdata(L, clss); /* second closure value is swig_lua_class structure */
+ lua_pushcclosure(L, SWIG_Lua_resolve_metamethod, 2);
+
+ lua_rawset(L, metatable_index);
+ success = 1;
+ }
+ lua_pop(L,1); /* remove function or nil */
+ lua_pop(L,1); /* remove base class metatable */
+
+ if( success )
+ break;
+ }
+
+ return success;
+}
+
+SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss)
+{
+ SWIG_Lua_get_class_metatable(L, clss->fqname);
+ const int metatable_index = lua_gettop(L);
+ SWIG_Lua_get_inheritable_metamethods(L);
+ assert(lua_istable(L,-1));
+ const int metamethods_info_index = lua_gettop(L);
+ lua_pushnil(L); /* first key */
+ while(lua_next(L, metamethods_info_index) != 0 ) {
+ /* key at index -2, value at index -1 */
+ const int is_inheritable = lua_toboolean(L,-2);
+ lua_pop(L,1); /* remove value - we don't need it anymore */
+
+ if(is_inheritable) { /* if metamethod is inheritable */
+ SWIG_Lua_add_class_user_metamethod(L,clss,metatable_index);
+ }
+ }
+
+ lua_pop(L,1); /* remove inheritable metatmethods table */
+
+ /* Special handling for __tostring method */
+ lua_pushstring(L, "__tostring");
+ lua_pushvalue(L,-1);
+ lua_rawget(L,metatable_index);
+ const int tostring_undefined = lua_isnil(L,-1);
+ lua_pop(L,1);
+ if( tostring_undefined ) {
+ lua_pushcfunction(L, SWIG_Lua_class_tostring);
+ lua_rawset(L, metatable_index);
+ } else {
+ lua_pop(L,1); /* remove copy of the key */
+ }
+
+ /* Warning: __index and __newindex are SWIG-defined. For user-defined operator[]
+ * a __getitem/__setitem method should be defined
+ */
+ lua_pop(L,1); /* pop class metatable */
}
/* Register class static methods,attributes etc as well as constructor proxy */
SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *clss)
{
- int begin = lua_gettop(L);
+ const int SWIGUNUSED begin = lua_gettop(L);
lua_checkstack(L,5); /* just in case */
assert(lua_istable(L,-1)); /* just in case */
assert(strcmp(clss->name, clss->cls_static->name) == 0); /* in class those 2 must be equal */
@@ -1240,7 +1487,7 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *cls
*/
SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *clss)
{
- int begin = lua_gettop(L);
+ const int SWIGUNUSED begin = lua_gettop(L);
/* if name already there (class is already registered) then do nothing */
SWIG_Lua_get_class_registry(L); /* get the registry */
lua_pushstring(L,clss->fqname); /* get the name */
@@ -1266,11 +1513,11 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c
* It would get us all special methods: __getitem, __add etc.
* This would set .fn, .type, and other .xxx incorrectly, but we will overwrite it right away
*/
- int new_metatable_index = lua_absindex(L,-1);
+ const int new_metatable_index = lua_absindex(L,-1);
for(i=0;clss->bases[i];i++)
{
SWIG_Lua_get_class_metatable(L,clss->bases[i]->fqname);
- int base_metatable = lua_absindex(L,-1);
+ const int base_metatable = lua_absindex(L,-1);
SWIG_Lua_merge_tables_by_index(L,new_metatable_index, base_metatable);
lua_pop(L,1);
}
@@ -1302,12 +1549,10 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c
SWIG_Lua_add_function(L,"__index",SWIG_Lua_class_get);
SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_class_set);
SWIG_Lua_add_function(L,"__gc",SWIG_Lua_class_destruct);
- /* add tostring method for better output */
- SWIG_Lua_add_function(L,"__tostring",SWIG_Lua_class_tostring);
/* add it */
lua_rawset(L,-3); /* metatable into registry */
lua_pop(L,1); /* tidy stack (remove registry) */
- assert(lua_gettop(L)==begin);
+ assert(lua_gettop(L) == begin);
#if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
/* Now merge all symbols from .fn, .set, .get etc from bases to our tables */
@@ -1335,7 +1580,7 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss)
* | ".set" --> ....
* |=============================== ".instance"
*/
- int begin = lua_gettop(L);
+ const int SWIGUNUSED begin = lua_gettop(L);
lua_pushstring(L,clss->cls_static->name);
lua_rawget(L,-2); /* get class static table */
assert(lua_istable(L,-1));
@@ -1358,7 +1603,7 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss)
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_class *clss)
{
- int begin = lua_gettop(L);
+ const int SWIGUNUSED begin = lua_gettop(L);
/* if name already there (class is already registered) then do nothing */
SWIG_Lua_get_class_registry(L); /* get the registry */
lua_pushstring(L,clss->fqname); /* get the name */
diff --git a/Lib/lua/luaruntime.swg b/Lib/lua/luaruntime.swg
index 5c70b8b7a..26dab93f6 100644
--- a/Lib/lua/luaruntime.swg
+++ b/Lib/lua/luaruntime.swg
@@ -69,10 +69,10 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
#if defined(SWIG_LUA_ELUA_EMULATE)
lua_newtable(L);
- SWIG_Lua_elua_emulate_register(L,swig___Module.ns_methods);
+ SWIG_Lua_elua_emulate_register(L,swig_SwigModule.ns_methods);
SWIG_Lua_elua_emulate_register_clear(L);
if(globalRegister) {
- lua_pushstring(L,swig___Module.name);
+ lua_pushstring(L,swig_SwigModule.name);
lua_pushvalue(L,-2);
lua_rawset(L,-4);
}
diff --git a/Lib/typemaps/strings.swg b/Lib/typemaps/strings.swg
index e31e5037f..6bac0b98a 100644
--- a/Lib/typemaps/strings.swg
+++ b/Lib/typemaps/strings.swg
@@ -499,7 +499,7 @@
* --- String fragment methods ---
* ------------------------------------------------------------ */
-
+#ifndef %_typemap2_string
%define %_typemap2_string(StringCode, CharCode,
Char, CharName,
SWIG_AsCharPtrAndSize,
@@ -602,7 +602,7 @@ SWIG_AsVal_dec(Char)(SWIG_Object obj, Char *val)
SWIG_DeleteCharArray)
%enddef
-
+#endif
/* ------------------------------------------------------------
* String typemaps and fragments, with default allocators
diff --git a/Makefile.in b/Makefile.in
index 4407d1316..f4d0be077 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -84,6 +84,7 @@ skip-uffi = test -n "@SKIP_UFFI@"
skip-r = test -n "@SKIP_R@"
skip-go = test -n "@SKIP_GO@"
skip-d = test -n "@SKIP_D@"
+skip-javascript = test -n "@SKIP_JAVASCRIPT@"
# Additional dependencies for some tests
skip-gcj = test -n "@SKIP_GCJ@"
@@ -129,6 +130,7 @@ check-aliveness:
@$(skip-r) || ./$(TARGET) -r -help
@$(skip-go) || ./$(TARGET) -go -help
@$(skip-d) || ./$(TARGET) -d -help
+ @$(skip-javascript) || ./$(TARGET) -javascript -help
check-ccache:
test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) check)
@@ -139,6 +141,7 @@ check-versions: \
check-perl5-version \
check-python-version \
check-java-version \
+ check-javascript-version \
check-android-version \
check-guile-version \
check-mzscheme-version \
@@ -196,7 +199,8 @@ check-examples: \
check-cffi-examples \
check-r-examples \
check-go-examples \
- check-d-examples
+ check-d-examples \
+ check-javascript-examples
tcl_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/tcl/check.list)
perl5_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/perl5/check.list)
@@ -221,6 +225,7 @@ cffi_examples :=
r_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/r/check.list)
go_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/go/check.list)
d_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/d/check.list)
+javascript_examples:=$(shell sed '/^\#/d' $(srcdir)/Examples/javascript/check.list)
# all examples
check-%-examples :
@@ -274,7 +279,8 @@ check-test-suite: \
check-chicken-test-suite \
check-r-test-suite \
check-go-test-suite \
- check-d-test-suite
+ check-d-test-suite \
+ check-javascript-test-suite
check-%-test-suite:
@if test -z "$(skip-$*)"; then \
@@ -326,7 +332,8 @@ all-test-suite: \
all-chicken-test-suite \
all-r-test-suite \
all-go-test-suite \
- all-d-test-suite
+ all-d-test-suite \
+ all-javascript-test-suite
all-%-test-suite:
@$(MAKE) $(FLAGS) check-$*-test-suite ACTION=all
@@ -354,7 +361,8 @@ broken-test-suite: \
broken-chicken-test-suite \
broken-r-test-suite \
broken-go-test-suite \
- broken-d-test-suite
+ broken-d-test-suite \
+ broken-javascript-test-suite
broken-%-test-suite:
@$(MAKE) $(FLAGS) check-$*-test-suite ACTION=broken
@@ -467,7 +475,8 @@ install-main:
@$(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)$(BIN_DIR)/`echo $(TARGET_NOEXE) | sed '$(transform)'`@EXEEXT@
lib-languages = gcj typemaps tcl perl5 python guile java mzscheme ruby php ocaml octave \
- pike chicken csharp modula3 allegrocl clisp lua cffi uffi r go d
+ pike chicken csharp modula3 allegrocl clisp lua cffi uffi r go d javascript javascript/jsc \
+ javascript/v8
lib-modules = std
diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
index 0ed438e90..7e7e5633f 100644
--- a/Source/CParse/parser.y
+++ b/Source/CParse/parser.y
@@ -1418,7 +1418,7 @@ static void mark_nodes_as_extend(Node *n) {
String *nexcept;
} dtype;
struct {
- char *type;
+ const char *type;
String *filename;
int line;
} loc;
@@ -2002,8 +2002,8 @@ include_directive: includetype options string BEGINFILE {
}
;
-includetype : INCLUDE { $$.type = (char *) "include"; }
- | IMPORT { $$.type = (char *) "import"; ++import_mode;}
+includetype : INCLUDE { $$.type = "include"; }
+ | IMPORT { $$.type = "import"; ++import_mode;}
;
/* ------------------------------------------------------------
@@ -4292,7 +4292,7 @@ cpp_namespace_decl : NAMESPACE idcolon LBRACE {
| NAMESPACE LBRACE {
Hash *h;
$1 = Swig_symbol_current();
- h = Swig_symbol_clookup((char *)" ",0);
+ h = Swig_symbol_clookup(" ",0);
if (h && (Strcmp(nodeType(h),"namespace") == 0)) {
Swig_symbol_setscope(Getattr(h,"symtab"));
} else {
@@ -5271,7 +5271,7 @@ notso_direct_declarator : idcolon {
SwigType *t;
$$ = $1;
t = NewStringEmpty();
- SwigType_add_array(t,(char*)"");
+ SwigType_add_array(t,"");
if ($$.type) {
SwigType_push(t,$$.type);
Delete($$.type);
@@ -5370,7 +5370,7 @@ direct_declarator : idcolon {
SwigType *t;
$$ = $1;
t = NewStringEmpty();
- SwigType_add_array(t,(char*)"");
+ SwigType_add_array(t,"");
if ($$.type) {
SwigType_push(t,$$.type);
Delete($$.type);
@@ -5540,7 +5540,7 @@ direct_abstract_declarator : direct_abstract_declarator LBRACKET RBRACKET {
SwigType *t;
$$ = $1;
t = NewStringEmpty();
- SwigType_add_array(t,(char*)"");
+ SwigType_add_array(t,"");
if ($$.type) {
SwigType_push(t,$$.type);
Delete($$.type);
@@ -5563,7 +5563,7 @@ direct_abstract_declarator : direct_abstract_declarator LBRACKET RBRACKET {
$$.id = 0;
$$.parms = 0;
$$.have_parms = 0;
- SwigType_add_array($$.type,(char*)"");
+ SwigType_add_array($$.type,"");
}
| LBRACKET expr RBRACKET {
$$.type = NewStringEmpty();
diff --git a/Source/DOH/README b/Source/DOH/README
index 9baaabc8a..8be5f652a 100644
--- a/Source/DOH/README
+++ b/Source/DOH/README
@@ -51,7 +51,7 @@ Sequence Operations
-------------------
Getitem(list,index) Get an item
Setitem(list,index,val) Set an item
-Delitem(list,index,val) Delete an item
+Delitem(list,index) Delete an item
Insert(list,index,val) Insert an item
Append(list,val) Append to end
Push(list,val) Insert at beginning
@@ -65,7 +65,7 @@ Putc(ch,obj) Put a character
Ungetc(ch,obj) Put character back on input stream
Seek(obj,offset,whence) Seek
Tell(obj) Return file pointer
-Close(obj) Close
+Delete(obj) Decrease the reference count, close file if zero
String Operations
-----------------
diff --git a/Source/Makefile.am b/Source/Makefile.am
index 49d571236..9e02e37f0 100644
--- a/Source/Makefile.am
+++ b/Source/Makefile.am
@@ -48,6 +48,7 @@ eswig_SOURCES = CParse/cscanner.c \
Modules/go.cxx \
Modules/guile.cxx \
Modules/java.cxx \
+ Modules/javascript.cxx \
Modules/lang.cxx \
Modules/lua.cxx \
Modules/main.cxx \
diff --git a/Source/Modules/allegrocl.cxx b/Source/Modules/allegrocl.cxx
index 93477057f..c7d9ff21b 100644
--- a/Source/Modules/allegrocl.cxx
+++ b/Source/Modules/allegrocl.cxx
@@ -20,7 +20,7 @@
// #define ALLEGROCL_TYPE_DEBUG
// #define ALLEGROCL_CLASS_DEBUG
-static const char *usage = (char *) "\
+static const char *usage = "\
Allegro CL Options (available with -allegrocl)\n\
-identifier-converter <type or funcname> - \n\
Specifies the type of conversion to do on C identifiers to convert\n\
diff --git a/Source/Modules/allocate.cxx b/Source/Modules/allocate.cxx
index d3618634b..dc3820766 100644
--- a/Source/Modules/allocate.cxx
+++ b/Source/Modules/allocate.cxx
@@ -714,7 +714,7 @@ Allocate():
/* Check if base classes allow smart pointers, but might be hidden */
if (!Getattr(n, "allocate:smartpointer")) {
- Node *sp = Swig_symbol_clookup((char *) "operator ->", 0);
+ Node *sp = Swig_symbol_clookup("operator ->", 0);
if (sp) {
/* Look for parent */
Node *p = parentNode(sp);
@@ -833,7 +833,7 @@ Allocate():
or reference. We're going to chase it to see if another operator->()
can be found */
if ((SwigType_check_decl(type, "")) || (SwigType_check_decl(type, "r."))) {
- Node *nn = Swig_symbol_clookup((char *) "operator ->", Getattr(sc, "symtab"));
+ Node *nn = Swig_symbol_clookup("operator ->", Getattr(sc, "symtab"));
if (nn) {
Delete(base);
Delete(type);
diff --git a/Source/Modules/cffi.cxx b/Source/Modules/cffi.cxx
index 6b331ad19..a1be00100 100644
--- a/Source/Modules/cffi.cxx
+++ b/Source/Modules/cffi.cxx
@@ -18,7 +18,7 @@
//#define CFFI_DEBUG
//#define CFFI_WRAP_DEBUG
-static const char *usage = (char *) "\
+static const char *usage = "\
CFFI Options (available with -cffi)\n\
-generate-typedef - Use defctype to generate shortcuts according to the\n\
typedefs in the input.\n\
diff --git a/Source/Modules/chicken.cxx b/Source/Modules/chicken.cxx
index 89e583d18..986638cf3 100644
--- a/Source/Modules/chicken.cxx
+++ b/Source/Modules/chicken.cxx
@@ -15,7 +15,7 @@
#include <ctype.h>
-static const char *usage = (char *) "\
+static const char *usage = "\
\
CHICKEN Options (available with -chicken)\n\
-closprefix <prefix> - Prepend <prefix> to all clos identifiers\n\
@@ -29,7 +29,7 @@ CHICKEN Options (available with -chicken)\n\
\n";
static char *module = 0;
-static char *chicken_path = (char *) "chicken";
+static const char *chicken_path = "chicken";
static int num_methods = 0;
static File *f_begin = 0;
@@ -620,7 +620,7 @@ int CHICKEN::functionWrapper(Node *n) {
if (in_class)
clos_name = NewString(member_name);
else
- clos_name = chickenNameMapping(scmname, (char *) "");
+ clos_name = chickenNameMapping(scmname, "");
if (!any_specialized_arg) {
method_def = NewString("");
@@ -775,7 +775,7 @@ int CHICKEN::variableWrapper(Node *n) {
if (in_class)
clos_name = NewString(member_name);
else
- clos_name = chickenNameMapping(scmname, (char *) "");
+ clos_name = chickenNameMapping(scmname, "");
Node *class_node = classLookup(t);
String *clos_code = Getattr(n, "tmap:varin:closcode");
@@ -942,7 +942,7 @@ int CHICKEN::constantWrapper(Node *n) {
if (in_class)
clos_name = NewString(member_name);
else
- clos_name = chickenNameMapping(scmname, (char *) "");
+ clos_name = chickenNameMapping(scmname, "");
if (GetFlag(n, "feature:constasvar")) {
Printv(clos_methods, "(define ", clos_name, " (", chickenPrimitiveName(scmname), "))\n", NIL);
Printv(scm_const_defs, "(set! ", scmname, " (", scmname, "))\n", NIL);
@@ -1372,7 +1372,7 @@ void CHICKEN::dispatchFunction(Node *n) {
} else if (in_class)
clos_name = NewString(member_name);
else
- clos_name = chickenNameMapping(scmname, (char *) "");
+ clos_name = chickenNameMapping(scmname, "");
Iterator f;
List *prev = 0;
diff --git a/Source/Modules/clisp.cxx b/Source/Modules/clisp.cxx
index e7d971faa..7d7c69a50 100644
--- a/Source/Modules/clisp.cxx
+++ b/Source/Modules/clisp.cxx
@@ -13,7 +13,7 @@
#include "swigmod.h"
-static const char *usage = (char *) "\
+static const char *usage = "\
CLISP Options (available with -clisp)\n\
-extern-all - Create clisp definitions for all the functions and\n\
global variables otherwise only definitions for\n\
diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx
index e0d4a1ab1..d30bd18c5 100644
--- a/Source/Modules/csharp.cxx
+++ b/Source/Modules/csharp.cxx
@@ -3175,8 +3175,8 @@ public:
if (anonymous_enum) {
replacementname = NewString("int");
} else {
- // An unknown enum - one that has not been parsed (neither a C enum forward reference nor a definition)
- replacementname = SwigType_base(classnametype);
+ // An unknown enum - one that has not been parsed (neither a C enum forward reference nor a definition) or an ignored enum
+ replacementname = NewStringf("SWIGTYPE%s", SwigType_manglestr(classnametype));
Replace(replacementname, "enum ", "", DOH_REPLACE_ANY);
Setattr(swig_types_hash, replacementname, classnametype);
}
@@ -4303,7 +4303,7 @@ extern "C" Language *swig_csharp(void) {
* Static member variables
* ----------------------------------------------------------------------------- */
-const char *CSHARP::usage = (char *) "\
+const char *CSHARP::usage = "\
C# Options (available with -csharp)\n\
-dllimport <dl> - Override DllImport attribute name to <dl>\n\
-namespace <nm> - Generate wrappers into C# namespace <nm>\n\
diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx
index 3387dd755..419828ea1 100644
--- a/Source/Modules/d.cxx
+++ b/Source/Modules/d.cxx
@@ -4649,7 +4649,7 @@ extern "C" Language *swig_d(void) {
/* -----------------------------------------------------------------------------
* Usage information displayed at the command line.
* ----------------------------------------------------------------------------- */
-const char *D::usage = (char *) "\
+const char *D::usage = "\
D Options (available with -d)\n\
-d2 - Generate code for D2/Phobos (default: D1/Tango)\n\
-package <pkg> - Write generated D modules into package <pkg>\n\
diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx
index a6a74ccac..e84109faf 100644
--- a/Source/Modules/go.cxx
+++ b/Source/Modules/go.cxx
@@ -4514,10 +4514,12 @@ private:
} else if (Strcmp(t, "enum ") == 0) {
ret = NewString("int");
} else {
- // An unknown enum - one that has not been parsed (neither a C enum forward reference nor a definition)
- ret = SwigType_base(t);
- Replace(ret, "enum ", "", DOH_REPLACE_ANY);
+ // An unknown enum - one that has not been parsed (neither a C enum forward reference nor a definition) or an ignored enum
+ String *tt = Copy(t);
+ Replace(tt, "enum ", "", DOH_REPLACE_ANY);
+ ret = exportedName(tt);
Setattr(undefined_enum_types, t, ret);
+ Delete(tt);
}
} else if (SwigType_isfunctionpointer(type) || SwigType_isfunction(type)) {
ret = NewString("_swig_fnptr");
@@ -5017,7 +5019,7 @@ extern "C" Language *swig_go(void) {
* ----------------------------------------------------------------------------- */
// Usage message.
-const char * const GO::usage = (char *) "\
+const char * const GO::usage = "\
Go Options (available with -go)\n\
-gccgo - Generate code for gccgo rather than 6g/8g\n\
-go-pkgpath <p> - Like gccgo -fgo-pkgpath option\n\
diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx
index 3a82d67d8..a9e51fd1b 100644
--- a/Source/Modules/guile.cxx
+++ b/Source/Modules/guile.cxx
@@ -16,7 +16,7 @@
#include <ctype.h>
// Note string broken in half for compilers that can't handle long strings
-static const char *usage = (char *) "\
+static const char *usage = "\
Guile Options (available with -guile)\n\
-emitsetters - Emit procedures-with-setters for variables\n\
and structure slots.\n\
@@ -1018,7 +1018,7 @@ public:
if (in_class)
goops_name = NewString(memberfunction_name);
else
- goops_name = goopsNameMapping(proc_name, (char *) "");
+ goops_name = goopsNameMapping(proc_name, "");
String *primitive_name = NewString("");
if (primRenamer)
Printv(primitive_name, "primitive:", proc_name, NIL);
@@ -1204,7 +1204,7 @@ public:
// export wrapper into goops file
if (!in_class) { // only if the variable is not part of a class
String *class_name = SwigType_typedef_resolve_all(SwigType_base(t));
- String *goops_name = goopsNameMapping(proc_name, (char *) "");
+ String *goops_name = goopsNameMapping(proc_name, "");
String *primitive_name = NewString("");
if (primRenamer)
Printv(primitive_name, "primitive:", NIL);
diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx
index 53f856749..9e16bb422 100644
--- a/Source/Modules/java.cxx
+++ b/Source/Modules/java.cxx
@@ -3090,8 +3090,8 @@ public:
if (anonymous_enum) {
replacementname = NewString("int");
} else {
- // An unknown enum - one that has not been parsed (neither a C enum forward reference nor a definition)
- replacementname = SwigType_base(classnametype);
+ // An unknown enum - one that has not been parsed (neither a C enum forward reference nor a definition) or an ignored enum
+ replacementname = NewStringf("SWIGTYPE%s", SwigType_manglestr(classnametype));
Replace(replacementname, "enum ", "", DOH_REPLACE_ANY);
Setattr(swig_types_hash, replacementname, classnametype);
}
@@ -4643,7 +4643,7 @@ extern "C" Language *swig_java(void) {
* Static member variables
* ----------------------------------------------------------------------------- */
-const char *JAVA::usage = (char *) "\
+const char *JAVA::usage = "\
Java Options (available with -java)\n\
-nopgcpp - Suppress premature garbage collection prevention parameter\n\
-noproxy - Generate the low-level functional interface instead\n\
diff --git a/Source/Modules/javascript.cxx b/Source/Modules/javascript.cxx
new file mode 100644
index 000000000..20af76f9f
--- /dev/null
+++ b/Source/Modules/javascript.cxx
@@ -0,0 +1,2427 @@
+/* -----------------------------------------------------------------------------
+ * This file is part of SWIG, which is licensed as a whole under version 3
+ * (or any later version) of the GNU General Public License. Some additional
+ * terms also apply to certain portions of SWIG. The full details of the SWIG
+ * license and copyrights can be found in the LICENSE and COPYRIGHT files
+ * included with the SWIG source code as distributed by the SWIG developers
+ * and at http://www.swig.org/legal.html.
+ *
+ * javascript.cxx
+ *
+ * Javascript language module for SWIG.
+ * ----------------------------------------------------------------------------- */
+
+#include "swigmod.h"
+#include "cparse.h"
+
+/**
+ * Enables extra debugging information in typemaps.
+ */
+static bool js_template_enable_debug = false;
+
+#define ERR_MSG_ONLY_ONE_ENGINE_PLEASE "Only one engine can be specified at a time."
+
+// keywords used for state variables
+#define NAME "name"
+#define NAME_MANGLED "name_mangled"
+#define TYPE "type"
+#define TYPE_MANGLED "type_mangled"
+#define WRAPPER_NAME "wrapper"
+#define IS_IMMUTABLE "is_immutable"
+#define IS_STATIC "is_static"
+#define IS_ABSTRACT "is_abstract"
+#define GETTER "getter"
+#define SETTER "setter"
+#define PARENT "parent"
+#define CTOR "ctor"
+#define CTOR_WRAPPERS "ctor_wrappers"
+#define CTOR_DISPATCHERS "ctor_dispatchers"
+#define DTOR "dtor"
+#define ARGCOUNT "wrap:argc"
+#define HAS_TEMPLATES "has_templates"
+#define FORCE_CPP "force_cpp"
+#define RESET true
+
+// keys for global state variables
+#define CREATE_NAMESPACES "create_namespaces"
+#define REGISTER_NAMESPACES "register_namespaces"
+#define INITIALIZER "initializer"
+
+// keys for class scoped state variables
+#define MEMBER_VARIABLES "member_variables"
+#define MEMBER_FUNCTIONS "member_functions"
+#define STATIC_FUNCTIONS "static_functions"
+#define STATIC_VARIABLES "static_variables"
+
+
+/**
+ * A convenience class to manage state variables for emitters.
+ * The implementation delegates to SWIG Hash DOHs and provides
+ * named sub-hashes for class, variable, and function states.
+ */
+class JSEmitterState {
+
+public:
+ JSEmitterState();
+ ~JSEmitterState();
+ DOH *globals();
+ DOH *globals(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);
+
+private:
+ DOH *getState(const char *key, bool reset = false);
+ Hash *globalHash;
+};
+
+/**
+ * A convenience class that wraps a code snippet used as template
+ * for code generation.
+ */
+class Template {
+
+public:
+ Template(const String *code);
+ Template(const String *code, const String *templateName);
+ Template(const Template & other);
+ ~Template();
+ String *str();
+ Template & replace(const String *pattern, const String *repl);
+ Template & print(DOH *doh);
+ Template & pretty_print(DOH *doh);
+ void operator=(const Template & t);
+ Template & trim();
+
+private:
+ String *code;
+ String *templateName;
+};
+
+/**
+ * JSEmitter represents an abstraction of javascript code generators
+ * for different javascript engines.
+ **/
+class JSEmitter {
+
+protected:
+
+ typedef JSEmitterState State;
+
+ enum MarshallingMode {
+ Setter,
+ Getter,
+ Ctor,
+ Function
+ };
+
+public:
+
+ enum JSEngine {
+ JavascriptCore,
+ V8,
+ NodeJS
+ };
+
+ JSEmitter(JSEngine engine);
+
+ virtual ~ 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;
+
+ /**
+ * Switches the context for code generation.
+ *
+ * Classes, global variables and global functions may need to
+ * be registered in certain static tables.
+ * This method should be used to switch output DOHs correspondingly.
+ */
+ virtual int switchNamespace(Node *);
+
+ /**
+ * 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();
+
+protected:
+
+ /**
+ * Generates code for a constructor function.
+ */
+ virtual int emitCtor(Node *n);
+
+ /**
+ * Generates code for a destructor function.
+ */
+ virtual int emitDtor(Node *n);
+
+ /**
+ * Generates code for a function.
+ */
+ virtual int emitFunction(Node *n, bool is_member, bool is_static);
+
+ virtual int emitFunctionDispatcher(Node *n, bool /*is_member */ );
+
+ /**
+ * Generates code for a getter function.
+ */
+ virtual int emitGetter(Node *n, bool is_member, bool is_static);
+
+ /**
+ * Generates code for a setter function.
+ */
+ virtual int emitSetter(Node *n, bool is_member, bool is_static);
+
+ virtual void marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, MarshallingMode mode, bool is_member, bool is_static) = 0;
+
+ virtual String *emitInputTypemap(Node *n, Parm *params, Wrapper *wrapper, String *arg);
+
+ virtual void marshalOutput(Node *n, ParmList *params, Wrapper *wrapper, String *actioncode, const String *cresult = 0, bool emitReturnVariable = true);
+
+ virtual void emitCleanupCode(Node *n, Wrapper *wrapper, ParmList *params);
+
+ /**
+ * Helper function to retrieve the first parent class node.
+ */
+ Node *getBaseClass(Node *n);
+
+ Parm *skipIgnoredArgs(Parm *p);
+
+ virtual int createNamespace(String *scope);
+
+ virtual Hash *createNamespaceEntry(const char *name, const char *parent);
+
+ virtual int emitNamespaces() = 0;
+
+
+protected:
+
+ JSEngine engine;
+ Hash *templates;
+ State state;
+
+ // contains context specific data (DOHs)
+ // to allow generation of namespace related code
+ // which are switched on namespace change
+ Hash *namespaces;
+ Hash *current_namespace;
+ String *defaultResultName;
+ File *f_wrappers;
+};
+
+/* factory methods for concrete JSEmitters: */
+
+JSEmitter *swig_javascript_create_JSCEmitter();
+JSEmitter *swig_javascript_create_V8Emitter();
+JSEmitter *swig_javascript_create_NodeJSEmitter();
+
+/**********************************************************************
+ * JAVASCRIPT: SWIG module implementation
+ **********************************************************************/
+
+class JAVASCRIPT:public Language {
+
+public:
+
+ JAVASCRIPT():emitter(NULL) {
+ }
+ ~JAVASCRIPT() {
+ delete emitter;
+ }
+
+ virtual int functionHandler(Node *n);
+ virtual int globalfunctionHandler(Node *n);
+ virtual int variableHandler(Node *n);
+ virtual int globalvariableHandler(Node *n);
+ virtual int staticmemberfunctionHandler(Node *n);
+ virtual int classHandler(Node *n);
+ virtual int functionWrapper(Node *n);
+ virtual int constantWrapper(Node *n);
+ virtual void main(int argc, char *argv[]);
+ virtual int top(Node *n);
+
+ /**
+ * Registers all %fragments assigned to section "templates".
+ **/
+ virtual int fragmentDirective(Node *n);
+
+private:
+
+ JSEmitter *emitter;
+};
+
+/* ---------------------------------------------------------------------
+ * functionWrapper()
+ *
+ * Low level code generator for functions
+ * --------------------------------------------------------------------- */
+
+int JAVASCRIPT::functionWrapper(Node *n) {
+
+ // note: the default implementation only prints a message
+ // Language::functionWrapper(n);
+ emitter->emitWrapperFunction(n);
+
+ return SWIG_OK;
+}
+
+/* ---------------------------------------------------------------------
+ * functionHandler()
+ *
+ * Function handler for generating wrappers for functions
+ * --------------------------------------------------------------------- */
+int JAVASCRIPT::functionHandler(Node *n) {
+
+ if (GetFlag(n, "isextension") == 1) {
+ SetFlag(n, "ismember");
+ }
+
+ emitter->enterFunction(n);
+ Language::functionHandler(n);
+ emitter->exitFunction(n);
+
+ return SWIG_OK;
+}
+
+/* ---------------------------------------------------------------------
+ * globalfunctionHandler()
+ *
+ * Function handler for generating wrappers for functions
+ * --------------------------------------------------------------------- */
+
+int JAVASCRIPT::globalfunctionHandler(Node *n) {
+ emitter->switchNamespace(n);
+ Language::globalfunctionHandler(n);
+
+ return SWIG_OK;
+}
+
+/* ---------------------------------------------------------------------
+ * staticmemberfunctionHandler()
+ *
+ * Function handler for generating wrappers for static member functions
+ * --------------------------------------------------------------------- */
+
+int JAVASCRIPT::staticmemberfunctionHandler(Node *n) {
+ /*
+ * Note: storage=static is removed by Language::staticmemberfunctionHandler.
+ * So, don't rely on that after here. Instead use the state variable which is
+ * set by JSEmitter::enterFunction().
+ */
+ Language::staticmemberfunctionHandler(n);
+ return SWIG_OK;
+}
+
+/* ---------------------------------------------------------------------
+ * variableHandler()
+ *
+ * Function handler for generating wrappers for variables
+ * --------------------------------------------------------------------- */
+
+int JAVASCRIPT::variableHandler(Node *n) {
+
+ emitter->enterVariable(n);
+ Language::variableHandler(n);
+ emitter->exitVariable(n);
+
+ return SWIG_OK;
+}
+
+/* ---------------------------------------------------------------------
+ * globalvariableHandler()
+ *
+ * Function handler for generating wrappers for global variables
+ * --------------------------------------------------------------------- */
+
+int JAVASCRIPT::globalvariableHandler(Node *n) {
+ emitter->switchNamespace(n);
+ Language::globalvariableHandler(n);
+
+ return SWIG_OK;
+}
+
+/* ---------------------------------------------------------------------
+ * constantHandler()
+ *
+ * Function handler for generating wrappers for constants
+ * --------------------------------------------------------------------- */
+
+int JAVASCRIPT::constantWrapper(Node *n) {
+ emitter->switchNamespace(n);
+
+ // Note: callbacks trigger this wrapper handler
+ // TODO: handle callback declarations
+ if (Equal(Getattr(n, "kind"), "function")) {
+ return SWIG_OK;
+ }
+ // TODO: the emitter for constants must be implemented in a cleaner way
+ // currently we treat it like a read-only variable
+ // however, there is a remaining bug with function pointer constants
+ // which could be fixed with a cleaner approach
+ emitter->emitConstant(n);
+
+ return SWIG_OK;
+}
+
+/* ---------------------------------------------------------------------
+ * classHandler()
+ *
+ * Function handler for generating wrappers for class
+ * --------------------------------------------------------------------- */
+
+int JAVASCRIPT::classHandler(Node *n) {
+ emitter->switchNamespace(n);
+
+ emitter->enterClass(n);
+ Language::classHandler(n);
+ emitter->exitClass(n);
+
+ return SWIG_OK;
+}
+
+int JAVASCRIPT::fragmentDirective(Node *n) {
+
+ // catch all fragment directives that have "templates" as location
+ // and register them at the emitter.
+ String *section = Getattr(n, "section");
+
+ if (Equal(section, "templates")) {
+ emitter->registerTemplate(Getattr(n, "value"), Getattr(n, "code"));
+ } else {
+ Swig_fragment_register(n);
+ }
+
+ return SWIG_OK;
+}
+
+/* ---------------------------------------------------------------------
+ * top()
+ *
+ * Function handler for processing top node of the parse tree
+ * Wrapper code generation essentially starts from here
+ * --------------------------------------------------------------------- */
+
+int JAVASCRIPT::top(Node *n) {
+ emitter->initialize(n);
+
+ Language::top(n);
+
+ emitter->dump(n);
+ emitter->close();
+
+ return SWIG_OK;
+}
+
+static const char *usage = (char *) "\
+Javascript Options (available with -javascript)\n\
+ -jsc - creates a JavascriptCore extension \n\
+ -v8 - creates a v8 extension \n\
+ -node - creates a node.js extension \n\
+ -debug-codetemplates - generates information about the origin of code templates\n";
+
+
+/* ---------------------------------------------------------------------
+ * main()
+ *
+ * Entry point for the JAVASCRIPT module
+ * --------------------------------------------------------------------- */
+
+void JAVASCRIPT::main(int argc, char *argv[]) {
+ // Set javascript subdirectory in SWIG library
+ SWIG_library_directory("javascript");
+
+ int engine = -1;
+
+ for (int i = 1; i < argc; i++) {
+ if (argv[i]) {
+ if (strcmp(argv[i], "-v8") == 0) {
+ if (engine != -1) {
+ Printf(stderr, ERR_MSG_ONLY_ONE_ENGINE_PLEASE);
+ SWIG_exit(-1);
+ }
+ Swig_mark_arg(i);
+ engine = JSEmitter::V8;
+ } else if (strcmp(argv[i], "-jsc") == 0) {
+ if (engine != -1) {
+ Printf(stderr, ERR_MSG_ONLY_ONE_ENGINE_PLEASE);
+ SWIG_exit(-1);
+ }
+ Swig_mark_arg(i);
+ engine = JSEmitter::JavascriptCore;
+ } else if (strcmp(argv[i], "-node") == 0) {
+ if (engine != -1) {
+ Printf(stderr, ERR_MSG_ONLY_ONE_ENGINE_PLEASE);
+ SWIG_exit(-1);
+ }
+ Swig_mark_arg(i);
+ engine = JSEmitter::NodeJS;
+ } else if (strcmp(argv[i], "-debug-codetemplates") == 0) {
+ Swig_mark_arg(i);
+ js_template_enable_debug = true;
+ } else if (strcmp(argv[i], "-help") == 0) {
+ fputs(usage, stdout);
+ return;
+ }
+ }
+ }
+
+ switch (engine) {
+ case JSEmitter::V8:
+ {
+ emitter = swig_javascript_create_V8Emitter();
+ Preprocessor_define("SWIG_JAVASCRIPT_V8 1", 0);
+ SWIG_library_directory("javascript/v8");
+ // V8 API is C++, so output must be C++ compatibile even when wrapping C code
+ if (!cparse_cplusplus) {
+ Swig_cparse_cplusplusout(1);
+ }
+ break;
+ }
+ case JSEmitter::JavascriptCore:
+ {
+ emitter = swig_javascript_create_JSCEmitter();
+ Preprocessor_define("SWIG_JAVASCRIPT_JSC 1", 0);
+ SWIG_library_directory("javascript/jsc");
+ break;
+ }
+ case JSEmitter::NodeJS:
+ {
+ emitter = swig_javascript_create_V8Emitter();
+ Preprocessor_define("SWIG_JAVASCRIPT_V8 1", 0);
+ Preprocessor_define("BUILDING_NODE_EXTENSION 1", 0);
+ SWIG_library_directory("javascript/v8");
+ break;
+ }
+ default:
+ {
+ Printf(stderr, "SWIG Javascript: Unknown engine. Please specify one of '-jsc', '-v8' or '-node'.\n");
+ SWIG_exit(-1);
+ break;
+ }
+ }
+
+ // Add a symbol to the parser for conditional compilation
+ Preprocessor_define("SWIGJAVASCRIPT 1", 0);
+
+ // Add typemap definitions
+ SWIG_typemap_lang("javascript");
+
+ // Set configuration file
+ SWIG_config_file("javascript.swg");
+
+ allow_overloading();
+}
+
+/* -----------------------------------------------------------------------------
+ * swig_javascript() - Instantiate module
+ * ----------------------------------------------------------------------------- */
+
+static Language *new_swig_javascript() {
+ return new JAVASCRIPT();
+}
+
+extern "C" Language *swig_javascript(void) {
+ return new_swig_javascript();
+}
+
+/**********************************************************************
+ * Emitter implementations
+ **********************************************************************/
+
+/* -----------------------------------------------------------------------------
+ * JSEmitter()
+ * ----------------------------------------------------------------------------- */
+
+JSEmitter::JSEmitter(JSEmitter::JSEngine engine)
+: engine(engine), templates(NewHash()), namespaces(NULL), current_namespace(NULL), defaultResultName(NewString("result")), f_wrappers(NULL) {
+}
+
+/* -----------------------------------------------------------------------------
+ * ~JSEmitter()
+ * ----------------------------------------------------------------------------- */
+
+JSEmitter::~JSEmitter() {
+ Delete(templates);
+}
+
+/* -----------------------------------------------------------------------------
+ * JSEmitter::RegisterTemplate() : Registers a code template
+ *
+ * Note: this is used only by JAVASCRIPT::fragmentDirective().
+ * ----------------------------------------------------------------------------- */
+
+int JSEmitter::registerTemplate(const String *name, const String *code) {
+ if (!State::IsSet(state.globals(HAS_TEMPLATES))) {
+ SetFlag(state.globals(), HAS_TEMPLATES);
+ }
+ return Setattr(templates, name, code);
+}
+
+/* -----------------------------------------------------------------------------
+ * JSEmitter::getTemplate() : Provides a registered code template
+ * ----------------------------------------------------------------------------- */
+
+Template JSEmitter::getTemplate(const String *name) {
+ String *templ = Getattr(templates, name);
+
+ if (!templ) {
+ Printf(stderr, "Could not find template %s\n.", name);
+ SWIG_exit(EXIT_FAILURE);
+ }
+
+ Template t(templ, name);
+ return t;
+}
+
+JSEmitterState & JSEmitter::getState() {
+ return state;
+}
+
+int JSEmitter::initialize(Node * /*n */ ) {
+
+ if (namespaces != NULL) {
+ Delete(namespaces);
+ }
+ namespaces = NewHash();
+ Hash *global_namespace = createNamespaceEntry("exports", 0);
+
+ Setattr(namespaces, "::", global_namespace);
+ current_namespace = global_namespace;
+
+ f_wrappers = NewString("");
+
+ return SWIG_OK;
+}
+
+/* ---------------------------------------------------------------------
+ * skipIgnoredArgs()
+ * --------------------------------------------------------------------- */
+
+Parm *JSEmitter::skipIgnoredArgs(Parm *p) {
+ while (checkAttribute(p, "tmap:in:numinputs", "0")) {
+ p = Getattr(p, "tmap:in:next");
+ }
+ return p;
+}
+
+/* -----------------------------------------------------------------------------
+ * JSEmitter::getBaseClass() : the node of the base class or NULL
+ *
+ * Note: the first base class is provided. Multiple inheritance is not
+ * supported.
+ * ----------------------------------------------------------------------------- */
+
+Node *JSEmitter::getBaseClass(Node *n) {
+ // retrieve the first base class that is not %ignored
+ List *baselist = Getattr(n, "bases");
+ if (baselist) {
+ Iterator base = First(baselist);
+ while (base.item && GetFlag(base.item, "feature:ignore")) {
+ base = Next(base);
+ }
+ return base.item;
+ }
+ return NULL;
+}
+
+ /* -----------------------------------------------------------------------------
+ * JSEmitter::emitWrapperFunction() : dispatches emitter functions.
+ *
+ * This allows to have small sized, dedicated emitting functions.
+ * All state dependent branching is done here.
+ * ----------------------------------------------------------------------------- */
+
+int JSEmitter::emitWrapperFunction(Node *n) {
+ int ret = SWIG_OK;
+
+ String *kind = Getattr(n, "kind");
+
+ if (kind) {
+
+ if (Equal(kind, "function")
+ // HACK: sneaky.ctest revealed that typedef'd (global) functions must be
+ // detected via the 'view' attribute.
+ || (Equal(kind, "variable") && Equal(Getattr(n, "view"), "globalfunctionHandler"))
+ ) {
+ bool is_member = GetFlag(n, "ismember") | GetFlag(n, "feature:extend");
+ bool is_static = GetFlag(state.function(), IS_STATIC);
+ ret = emitFunction(n, is_member, is_static);
+ } else if (Cmp(kind, "variable") == 0) {
+ bool is_static = GetFlag(state.variable(), IS_STATIC);
+ // HACK: smartpointeraccessed static variables are not treated as statics
+ if (GetFlag(n, "allocate:smartpointeraccess")) {
+ is_static = false;
+ }
+
+ bool is_member = GetFlag(n, "ismember");
+ bool is_setter = GetFlag(n, "memberset") || GetFlag(n, "varset");
+ bool is_getter = GetFlag(n, "memberget") || GetFlag(n, "varget");
+ if (is_setter) {
+ ret = emitSetter(n, is_member, is_static);
+ } else if (is_getter) {
+ ret = emitGetter(n, is_member, is_static);
+ } else {
+ Swig_print_node(n);
+ }
+
+ } else {
+ Printf(stderr, "Warning: unsupported wrapper function type\n");
+ Swig_print_node(n);
+ ret = SWIG_ERROR;
+ }
+ } else {
+ String *view = Getattr(n, "view");
+
+ if (Cmp(view, "constructorHandler") == 0) {
+ ret = emitCtor(n);
+ } else if (Cmp(view, "destructorHandler") == 0) {
+ ret = emitDtor(n);
+ } else {
+ Printf(stderr, "Warning: unsupported wrapper function type");
+ Swig_print_node(n);
+ ret = SWIG_ERROR;
+ }
+ }
+
+ return ret;
+}
+
+int JSEmitter::enterClass(Node *n) {
+ state.clazz(RESET);
+ state.clazz(NAME, Getattr(n, "sym:name"));
+ state.clazz("nspace", current_namespace);
+
+ // Creating a mangled name using the current namespace and the symbol name
+ String *mangled_name = NewString("");
+ Printf(mangled_name, "%s_%s", Getattr(current_namespace, NAME_MANGLED), Getattr(n, "sym:name"));
+ state.clazz(NAME_MANGLED, SwigType_manglestr(mangled_name));
+ Delete(mangled_name);
+
+ state.clazz(TYPE, NewString(Getattr(n, "classtype")));
+
+ String *type = SwigType_manglestr(Getattr(n, "classtypeobj"));
+ String *classtype_mangled = NewString("");
+ Printf(classtype_mangled, "p%s", type);
+ state.clazz(TYPE_MANGLED, classtype_mangled);
+ Delete(type);
+
+ String *ctor_wrapper = NewString("_wrap_new_veto_");
+ Append(ctor_wrapper, state.clazz(NAME));
+ state.clazz(CTOR, ctor_wrapper);
+ state.clazz(CTOR_DISPATCHERS, NewString(""));
+ state.clazz(DTOR, NewString("0"));
+
+ // HACK: assume that a class is abstract
+ // this is resolved by emitCtor (which is only called for non abstract classes)
+ SetFlag(state.clazz(), IS_ABSTRACT);
+
+ return SWIG_OK;
+}
+
+int JSEmitter::enterFunction(Node *n) {
+ state.function(RESET);
+ state.function(NAME, Getattr(n, "sym:name"));
+ if (Equal(Getattr(n, "storage"), "static")) {
+ SetFlag(state.function(), IS_STATIC);
+ }
+ return SWIG_OK;
+}
+
+int JSEmitter::enterVariable(Node *n) {
+ // reset the state information for variables.
+ state.variable(RESET);
+
+ // Retrieve a pure symbol name. Using 'sym:name' as a basis, as it considers %renamings.
+ if (Equal(Getattr(n, "view"), "memberconstantHandler")) {
+ // Note: this is kind of hacky/experimental
+ // For constants/enums 'sym:name' contains e.g., 'Foo_Hello' instead of 'Hello'
+ state.variable(NAME, Getattr(n, "memberconstantHandler:sym:name"));
+ } else {
+ state.variable(NAME, Swig_scopename_last(Getattr(n, "sym:name")));
+ }
+
+ if (Equal(Getattr(n, "storage"), "static")) {
+ SetFlag(state.variable(), IS_STATIC);
+ }
+
+ if (!Language::instance()->is_assignable(n)) {
+ SetFlag(state.variable(), IS_IMMUTABLE);
+ }
+ // FIXME: test "arrays_global" does not compile with that as it is not allowed to assign to char[]
+ if (Equal(Getattr(n, "type"), "a().char")) {
+ SetFlag(state.variable(), IS_IMMUTABLE);
+ }
+
+ return SWIG_OK;
+}
+
+int JSEmitter::emitCtor(Node *n) {
+
+ Wrapper *wrapper = NewWrapper();
+
+ bool is_overloaded = GetFlag(n, "sym:overloaded");
+
+ Template t_ctor(getTemplate("js_ctor"));
+
+ String *wrap_name = Swig_name_wrapper(Getattr(n, "sym:name"));
+ if (is_overloaded) {
+ t_ctor = getTemplate("js_overloaded_ctor");
+ Append(wrap_name, Getattr(n, "sym:overname"));
+ }
+ Setattr(n, "wrap:name", wrap_name);
+ // note: we can remove the is_abstract flag now, as this
+ // is called for non-abstract classes only.
+ Setattr(state.clazz(), IS_ABSTRACT, 0);
+
+ ParmList *params = Getattr(n, "parms");
+ emit_parameter_variables(params, wrapper);
+ emit_attach_parmmaps(params, wrapper);
+ // HACK: in test-case `ignore_parameter` emit_attach_parmmaps generated an extra line of applied typemaps.
+ // Deleting wrapper->code here, to reset, and as it seemed to have no side effect elsewhere
+ Delete(wrapper->code);
+ wrapper->code = NewString("");
+
+ Printf(wrapper->locals, "%sresult;", SwigType_str(Getattr(n, "type"), 0));
+
+ marshalInputArgs(n, params, wrapper, Ctor, true, false);
+ String *action = emit_action(n);
+ Printv(wrapper->code, action, "\n", 0);
+
+ emitCleanupCode(n, wrapper, params);
+
+ t_ctor.replace("$jswrapper", wrap_name)
+ .replace("$jsmangledtype", state.clazz(TYPE_MANGLED))
+ .replace("$jslocals", wrapper->locals)
+ .replace("$jscode", wrapper->code)
+ .replace("$jsargcount", Getattr(n, ARGCOUNT))
+ .pretty_print(f_wrappers);
+
+ Template t_ctor_case(getTemplate("js_ctor_dispatch_case"));
+ t_ctor_case.replace("$jswrapper", wrap_name)
+ .replace("$jsargcount", Getattr(n, ARGCOUNT));
+ Append(state.clazz(CTOR_DISPATCHERS), t_ctor_case.str());
+
+ DelWrapper(wrapper);
+
+ // create a dispatching ctor
+ if (is_overloaded) {
+ if (!Getattr(n, "sym:nextSibling")) {
+ String *wrap_name = Swig_name_wrapper(Getattr(n, "sym:name"));
+ Template t_mainctor(getTemplate("js_ctor_dispatcher"));
+ t_mainctor.replace("$jswrapper", wrap_name)
+ .replace("$jsmangledname", state.clazz(NAME_MANGLED))
+ .replace("$jsdispatchcases", state.clazz(CTOR_DISPATCHERS))
+ .pretty_print(f_wrappers);
+ state.clazz(CTOR, wrap_name);
+ }
+ } else {
+ state.clazz(CTOR, wrap_name);
+ }
+
+ return SWIG_OK;
+}
+
+int JSEmitter::emitDtor(Node *n) {
+
+ String *wrap_name = Swig_name_wrapper(Getattr(n, "sym:name"));
+
+ SwigType *type = state.clazz(TYPE);
+ String *p_classtype = SwigType_add_pointer(state.clazz(TYPE));
+ String *ctype = SwigType_lstr(p_classtype, "");
+ String *free = NewString("");
+
+ // (Taken from JSCore implementation.)
+ /* The if (Extend) block was taken from the Ruby implementation.
+ * The problem is that in the case of an %extend to create a destructor for a struct to coordinate automatic memory cleanup with the Javascript collector,
+ * the SWIG function was not being generated. More specifically:
+ struct MyData {
+ %extend {
+ ~MyData() {
+ FreeData($self);
+ }
+ }
+ };
+ %newobject CreateData;
+ struct MyData* CreateData(void);
+ %delobject FreeData;
+ void FreeData(struct MyData* the_data);
+
+ where the use case is something like:
+ var my_data = example.CreateData();
+ my_data = null;
+
+ This function was not being generated:
+ SWIGINTERN void delete_MyData(struct MyData *self){
+ FreeData(self);
+ }
+
+ I don't understand fully why it wasn't being generated. It just seems to happen in the Lua generator.
+ There is a comment about staticmemberfunctionHandler having an inconsistency and I tracked down dome of the SWIGINTERN void delete_*
+ code to that function in the Language base class.
+ The Ruby implementation seems to have an explicit check for if(Extend) and explicitly generates the code, so that's what I'm doing here.
+ The Ruby implementation does other stuff which I omit.
+ */
+ if (Extend) {
+ String *wrap = Getattr(n, "wrap:code");
+ if (wrap) {
+ Printv(f_wrappers, wrap, NIL);
+ }
+ }
+ // HACK: this is only for the v8 emitter. maybe set an attribute wrap:action of node
+ // TODO: generate dtors more similar to other wrappers
+ // EW: I think this is wrong. delete should only be used when new was used to create. If malloc was used, free needs to be used.
+ if (SwigType_isarray(type)) {
+ Printf(free, "delete [] (%s)", ctype);
+ } else {
+ Printf(free, "delete (%s)", ctype);
+ }
+
+ String *destructor_action = Getattr(n, "wrap:action");
+ // Adapted from the JSCore implementation.
+ /* The next challenge is to generate the correct finalize function for JavaScriptCore to call.
+ Originally, it would use this fragment from javascriptcode.swg
+ %fragment ("JS_destructordefn", "templates")
+ %{
+ void _wrap_${classname_mangled}_finalize(JSObjectRef thisObject)
+ {
+ SWIG_PRV_DATA* t = (SWIG_PRV_DATA*)JSObjectGetPrivate(thisObject);
+ if(t && t->swigCMemOwn) free ((${type}*)t->swigCObject);
+ if(t) free(t);
+ }
+ %}
+
+ But for the above example case of %extend to define a destructor on a struct, we need to override the system to not call
+ free ((${type}*)t->swigCObject);
+ and substitute it with what the user has provided.
+ To solve this, I created a variation fragment called JS_destructoroverridedefn:
+ SWIG_PRV_DATA* t = (SWIG_PRV_DATA*)JSObjectGetPrivate(thisObject);
+ if(t && t->swigCMemOwn) {
+ ${type}* arg1 = (${type}*)t->swigCObject;
+ ${destructor_action}
+ }
+ if(t) free(t);
+
+ Based on what I saw in the Lua and Ruby modules, I use Getattr(n, "wrap:action")
+ to decide if the user has a preferred destructor action.
+ Based on that, I decide which fragment to use.
+ And in the case of the custom action, I substitute that action in.
+ I noticed that destructor_action has the form
+ delete_MyData(arg1);
+ The explicit arg1 is a little funny, so I structured the fragment to create a temporary variable called arg1 to make the generation easier.
+ This might suggest this solution misunderstands a more complex case.
+
+ Also, there is a problem where destructor_action is always true for me, even when not requesting %extend as above.
+ So this code doesn't actually quite work as I expect. The end result is that the code still works because
+ destructor_action calls free like the original template. The one caveat is the string in destructor_action casts to char* which is wierd.
+ I think there is a deeper underlying SWIG issue because I don't think it should be char*. However, it doesn't really matter for free.
+
+ Maybe the fix for the destructor_action always true problem is that this is supposed to be embedded in the if(Extend) block above.
+ But I don't fully understand the conditions of any of these things, and since it works for the moment, I don't want to break more stuff.
+ */
+ if (destructor_action) {
+ Template t_dtor = getTemplate("js_dtoroverride");
+ state.clazz(DTOR, wrap_name);
+ t_dtor.replace("${classname_mangled}", state.clazz(NAME_MANGLED))
+ .replace("$jswrapper", wrap_name)
+ .replace("$jsfree", free)
+ .replace("$jstype", ctype);
+
+ t_dtor.replace("${destructor_action}", destructor_action);
+ Wrapper_pretty_print(t_dtor.str(), f_wrappers);
+ } else {
+ Template t_dtor = getTemplate("js_dtor");
+ state.clazz(DTOR, wrap_name);
+ t_dtor.replace("$jsmangledname", state.clazz(NAME_MANGLED))
+ .replace("$jswrapper", wrap_name)
+ .replace("$jsfree", free)
+ .replace("$jstype", ctype)
+ .pretty_print(f_wrappers);
+ }
+
+ Delete(p_classtype);
+ Delete(ctype);
+ Delete(free);
+
+ return SWIG_OK;
+}
+
+int JSEmitter::emitGetter(Node *n, bool is_member, bool is_static) {
+ Wrapper *wrapper = NewWrapper();
+ Template t_getter(getTemplate("js_getter"));
+
+ // prepare wrapper name
+ String *wrap_name = Swig_name_wrapper(Getattr(n, "sym:name"));
+ Setattr(n, "wrap:name", wrap_name);
+ state.variable(GETTER, wrap_name);
+
+ // prepare local variables
+ ParmList *params = Getattr(n, "parms");
+ emit_parameter_variables(params, wrapper);
+ emit_attach_parmmaps(params, wrapper);
+
+ // prepare code part
+ String *action = emit_action(n);
+ marshalInputArgs(n, params, wrapper, Getter, is_member, is_static);
+ marshalOutput(n, params, wrapper, action);
+
+ emitCleanupCode(n, wrapper, params);
+
+ t_getter.replace("$jswrapper", wrap_name)
+ .replace("$jslocals", wrapper->locals)
+ .replace("$jscode", wrapper->code)
+ .pretty_print(f_wrappers);
+
+ DelWrapper(wrapper);
+
+ return SWIG_OK;
+}
+
+int JSEmitter::emitSetter(Node *n, bool is_member, bool is_static) {
+
+ // skip variables that are immutable
+ if (State::IsSet(state.variable(IS_IMMUTABLE))) {
+ return SWIG_OK;
+ }
+
+ Wrapper *wrapper = NewWrapper();
+
+ Template t_setter(getTemplate("js_setter"));
+
+ // prepare wrapper name
+ String *wrap_name = Swig_name_wrapper(Getattr(n, "sym:name"));
+ Setattr(n, "wrap:name", wrap_name);
+ state.variable(SETTER, wrap_name);
+
+ // prepare local variables
+ ParmList *params = Getattr(n, "parms");
+ emit_parameter_variables(params, wrapper);
+ emit_attach_parmmaps(params, wrapper);
+
+ // prepare code part
+ String *action = emit_action(n);
+ marshalInputArgs(n, params, wrapper, Setter, is_member, is_static);
+ Append(wrapper->code, action);
+
+ emitCleanupCode(n, wrapper, params);
+
+ t_setter.replace("$jswrapper", wrap_name)
+ .replace("$jslocals", wrapper->locals)
+ .replace("$jscode", wrapper->code)
+ .pretty_print(f_wrappers);
+
+ DelWrapper(wrapper);
+
+ return SWIG_OK;
+}
+
+/* -----------------------------------------------------------------------------
+ * JSEmitter::emitConstant() : triggers code generation for constants
+ * ----------------------------------------------------------------------------- */
+
+int JSEmitter::emitConstant(Node *n) {
+ // HACK: somehow it happened under OSX that before everything started
+ // a lot of SWIG internal constants were emitted
+ // This didn't happen on other platforms yet...
+ // we ignore those premature definitions
+ if (!State::IsSet(state.globals(HAS_TEMPLATES))) {
+ return SWIG_ERROR;
+ }
+
+ Wrapper *wrapper = NewWrapper();
+ SwigType *type = Getattr(n, "type");
+ String *name = Getattr(n, "name");
+ String *iname = Getattr(n, "sym:name");
+ String *wname = Swig_name_wrapper(name);
+ String *rawval = Getattr(n, "rawval");
+ String *value = rawval ? rawval : Getattr(n, "value");
+
+ // HACK: forcing usage of cppvalue for v8 (which turned out to fix typdef_struct.i, et. al)
+ if (State::IsSet(state.globals(FORCE_CPP)) && Getattr(n, "cppvalue") != NULL) {
+ value = Getattr(n, "cppvalue");
+ }
+
+ Template t_getter(getTemplate("js_getter"));
+
+ // call the variable methods as a constants are
+ // registred in same way
+ enterVariable(n);
+ state.variable(GETTER, wname);
+ // TODO: why do we need this?
+ Setattr(n, "wrap:name", wname);
+
+ // special treatment of member pointers
+ if (SwigType_type(type) == T_MPOINTER) {
+ // TODO: this could go into a code-template
+ String *mpointer_wname = NewString("");
+ Printf(mpointer_wname, "_wrapConstant_%s", iname);
+ Setattr(n, "memberpointer:constant:wrap:name", mpointer_wname);
+ String *str = SwigType_str(type, mpointer_wname);
+ Printf(f_wrappers, "static %s = %s;\n", str, value);
+ Delete(str);
+ value = mpointer_wname;
+ }
+
+ marshalOutput(n, 0, wrapper, NewString(""), value, false);
+
+ t_getter.replace("$jswrapper", wname)
+ .replace("$jslocals", wrapper->locals)
+ .replace("$jscode", wrapper->code)
+ .pretty_print(f_wrappers);
+
+ exitVariable(n);
+
+ DelWrapper(wrapper);
+
+ return SWIG_OK;
+}
+
+int JSEmitter::emitFunction(Node *n, bool is_member, bool is_static) {
+ Wrapper *wrapper = NewWrapper();
+ Template t_function(getTemplate("js_function"));
+
+ bool is_overloaded = GetFlag(n, "sym:overloaded");
+
+ // prepare the function wrapper name
+ String *iname = Getattr(n, "sym:name");
+ String *wrap_name = Swig_name_wrapper(iname);
+ if (is_overloaded) {
+ t_function = getTemplate("js_overloaded_function");
+ Append(wrap_name, Getattr(n, "sym:overname"));
+ }
+ Setattr(n, "wrap:name", wrap_name);
+ state.function(WRAPPER_NAME, wrap_name);
+
+ // prepare local variables
+ ParmList *params = Getattr(n, "parms");
+ emit_parameter_variables(params, wrapper);
+ emit_attach_parmmaps(params, wrapper);
+
+ // HACK: in test-case `ignore_parameter` emit_attach_parmmaps generates an extra line of applied typemap.
+ // Deleting wrapper->code here fixes the problem, and seems to have no side effect elsewhere
+ Delete(wrapper->code);
+ wrapper->code = NewString("");
+
+ marshalInputArgs(n, params, wrapper, Function, is_member, is_static);
+ String *action = emit_action(n);
+ marshalOutput(n, params, wrapper, action);
+ emitCleanupCode(n, wrapper, params);
+ Replaceall(wrapper->code, "$symname", iname);
+
+ t_function.replace("$jswrapper", wrap_name)
+ .replace("$jslocals", wrapper->locals)
+ .replace("$jscode", wrapper->code)
+ .replace("$jsargcount", Getattr(n, ARGCOUNT))
+ .pretty_print(f_wrappers);
+
+
+ DelWrapper(wrapper);
+
+ return SWIG_OK;
+}
+
+int JSEmitter::emitFunctionDispatcher(Node *n, bool /*is_member */ ) {
+ Wrapper *wrapper = NewWrapper();
+
+ // Generate call list, go to first node
+ Node *sibl = n;
+
+ while (Getattr(sibl, "sym:previousSibling"))
+ sibl = Getattr(sibl, "sym:previousSibling"); // go all the way up
+
+ do {
+ String *siblname = Getattr(sibl, "wrap:name");
+
+ if (siblname) {
+ // handle function overloading
+ Template t_dispatch_case = getTemplate("js_function_dispatch_case");
+ t_dispatch_case.replace("$jswrapper", siblname)
+ .replace("$jsargcount", Getattr(sibl, ARGCOUNT));
+
+ Append(wrapper->code, t_dispatch_case.str());
+ }
+
+ } while ((sibl = Getattr(sibl, "sym:nextSibling")));
+
+ Template t_function(getTemplate("js_function_dispatcher"));
+
+ // Note: this dispatcher function gets called after the last overloaded function has been created.
+ // At this time, n.wrap:name contains the name of the last wrapper function.
+ // To get a valid function name for the dispatcher function we take the last wrapper name and
+ // substract the extension "sym:overname",
+ String *wrap_name = NewString(Getattr(n, "wrap:name"));
+ String *overname = Getattr(n, "sym:overname");
+ int l1 = Len(wrap_name);
+ int l2 = Len(overname);
+ Delslice(wrap_name, l1 - l2, l1);
+
+ Setattr(n, "wrap:name", wrap_name);
+ state.function(WRAPPER_NAME, wrap_name);
+
+ t_function.replace("$jslocals", wrapper->locals)
+ .replace("$jscode", wrapper->code);
+
+ // call this here, to replace all variables
+ t_function.replace("$jswrapper", wrap_name)
+ .replace("$jsname", state.function(NAME))
+ .pretty_print(f_wrappers);
+
+ // Delete the state variable
+ DelWrapper(wrapper);
+
+ return SWIG_OK;
+}
+
+String *JSEmitter::emitInputTypemap(Node *n, Parm *p, Wrapper *wrapper, String *arg) {
+ // Get input typemap for current param
+ String *tm = Getattr(p, "tmap:in");
+ SwigType *type = Getattr(p, "type");
+
+ if (tm != NULL) {
+ Replaceall(tm, "$input", arg);
+ Setattr(p, "emit:input", arg);
+ // do replacements for built-in variables
+ if (Getattr(p, "wrap:disown") || (Getattr(p, "tmap:in:disown"))) {
+ Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
+ } else {
+ Replaceall(tm, "$disown", "0");
+ }
+ Replaceall(tm, "$symname", Getattr(n, "sym:name"));
+ Printf(wrapper->code, "%s\n", tm);
+ } else {
+ Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(type, 0));
+ }
+
+ return tm;
+}
+
+void JSEmitter::marshalOutput(Node *n, ParmList *params, Wrapper *wrapper, String *actioncode, const String *cresult, bool emitReturnVariable) {
+ SwigType *type = Getattr(n, "type");
+ String *tm;
+ Parm *p;
+
+ // adds a declaration for the result variable
+ if (emitReturnVariable)
+ emit_return_variable(n, type, wrapper);
+ // if not given, use default result identifier ('result') for output typemap
+ if (cresult == 0)
+ cresult = defaultResultName;
+
+ tm = Swig_typemap_lookup_out("out", n, cresult, wrapper, actioncode);
+ bool should_own = GetFlag(n, "feature:new");
+
+ if (tm) {
+ Replaceall(tm, "$objecttype", Swig_scopename_last(SwigType_str(SwigType_strip_qualifiers(type), 0)));
+
+ if (should_own) {
+ Replaceall(tm, "$owner", "SWIG_POINTER_OWN");
+ } else {
+ Replaceall(tm, "$owner", "0");
+ }
+ Append(wrapper->code, tm);
+
+ if (Len(tm) > 0) {
+ Printf(wrapper->code, "\n");
+ }
+ } else {
+ Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(type, 0), Getattr(n, "name"));
+ }
+
+ if (params) {
+ for (p = params; p;) {
+ if ((tm = Getattr(p, "tmap:argout"))) {
+ Replaceall(tm, "$input", Getattr(p, "emit:input"));
+ Printv(wrapper->code, tm, "\n", NIL);
+ p = Getattr(p, "tmap:argout:next");
+ } else {
+ p = nextSibling(p);
+ }
+ }
+ }
+
+ Replaceall(wrapper->code, "$result", "jsresult");
+}
+
+void JSEmitter::emitCleanupCode(Node *n, Wrapper *wrapper, ParmList *params) {
+ Parm *p;
+ String *tm;
+
+ for (p = params; p;) {
+ if ((tm = Getattr(p, "tmap:freearg"))) {
+ //addThrows(n, "tmap:freearg", p);
+ Replaceall(tm, "$input", Getattr(p, "emit:input"));
+ Printv(wrapper->code, tm, "\n", NIL);
+ p = Getattr(p, "tmap:freearg:next");
+ } else {
+ p = nextSibling(p);
+ }
+ }
+
+ if (GetFlag(n, "feature:new")) {
+ tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0);
+ if (tm != NIL) {
+ //addThrows(throws_hash, "newfree", n);
+ Printv(wrapper->code, tm, "\n", NIL);
+ }
+ }
+
+}
+
+int JSEmitter::switchNamespace(Node *n) {
+ // HACK: somehow this gets called for member functions.
+ // We can safely ignore them, as members are not associated to a namespace (only their class)
+ if (GetFlag(n, "ismember")) {
+ return SWIG_OK;
+ }
+
+ String *nspace = Getattr(n, "sym:nspace");
+
+ // if nspace is deactivated, everything goes into the global scope
+ if (!GetFlag(n, "feature:nspace")) {
+ current_namespace = Getattr(namespaces, "::");
+ return SWIG_OK;
+ }
+
+ if (nspace == NULL) {
+ // It seems that only classes have 'sym:nspace' set.
+ // We try to get the namespace from the qualified name (i.e., everything before the last '::')
+ nspace = Swig_scopename_prefix(Getattr(n, "name"));
+ }
+
+ // If there is not even a scopename prefix then it must be global scope
+ if (nspace == NULL) {
+ current_namespace = Getattr(namespaces, "::");
+ return SWIG_OK;
+ }
+
+ String *scope = NewString(nspace);
+ // replace "." with "::" that we can use Swig_scopename_last
+ Replaceall(scope, ".", "::");
+
+ // if the scope is not yet registered
+ // create (parent) namespaces recursively
+ if (!Getattr(namespaces, scope)) {
+ createNamespace(scope);
+ }
+ current_namespace = Getattr(namespaces, scope);
+
+ return SWIG_OK;
+}
+
+int JSEmitter::createNamespace(String *scope) {
+
+ String *parent_scope = Swig_scopename_prefix(scope);
+ Hash *parent_namespace;
+ if (parent_scope == 0) {
+ parent_namespace = Getattr(namespaces, "::");
+ } else if (!Getattr(namespaces, parent_scope)) {
+ createNamespace(parent_scope);
+ parent_namespace = Getattr(namespaces, parent_scope);
+ } else {
+ parent_namespace = Getattr(namespaces, parent_scope);
+ }
+ assert(parent_namespace != 0);
+
+ Hash *new_namespace = createNamespaceEntry(Char(scope), Char(Getattr(parent_namespace, "name")));
+ Setattr(namespaces, scope, new_namespace);
+
+ Delete(parent_scope);
+ return SWIG_OK;
+}
+
+Hash *JSEmitter::createNamespaceEntry(const char *_name, const char *parent) {
+ Hash *entry = NewHash();
+ String *name = NewString(_name);
+ Setattr(entry, NAME, Swig_scopename_last(name));
+ Setattr(entry, NAME_MANGLED, Swig_name_mangle(name));
+ Setattr(entry, PARENT, NewString(parent));
+
+ Delete(name);
+ return entry;
+}
+
+/**********************************************************************
+ * JavascriptCore: JSEmitter implementation for JavascriptCore engine
+ **********************************************************************/
+
+class JSCEmitter:public JSEmitter {
+
+public:
+ JSCEmitter();
+ virtual ~ JSCEmitter();
+ virtual int initialize(Node *n);
+ virtual int dump(Node *n);
+ virtual int close();
+
+protected:
+ virtual int enterVariable(Node *n);
+ virtual int exitVariable(Node *n);
+ virtual int enterFunction(Node *n);
+ virtual int exitFunction(Node *n);
+ virtual int enterClass(Node *n);
+ virtual int exitClass(Node *n);
+ virtual void marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, MarshallingMode mode, bool is_member, bool is_static);
+ virtual Hash *createNamespaceEntry(const char *name, const char *parent);
+ virtual int emitNamespaces();
+
+private:
+
+ String *NULL_STR;
+ String *VETO_SET;
+
+ // output file and major code parts
+ File *f_wrap_cpp;
+ File *f_runtime;
+ File *f_header;
+ File *f_init;
+
+};
+
+JSCEmitter::JSCEmitter()
+: JSEmitter(JSEmitter::JavascriptCore), NULL_STR(NewString("NULL")), VETO_SET(NewString("JS_veto_set_variable")), f_wrap_cpp(NULL), f_runtime(NULL), f_header(NULL), f_init(NULL) {
+}
+
+JSCEmitter::~JSCEmitter() {
+ Delete(NULL_STR);
+ Delete(VETO_SET);
+}
+
+
+/* ---------------------------------------------------------------------
+ * marshalInputArgs()
+ *
+ * Process all of the arguments passed into the argv array
+ * and convert them into C/C++ function arguments using the
+ * supplied typemaps.
+ * --------------------------------------------------------------------- */
+
+void JSCEmitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, MarshallingMode mode, bool is_member, bool is_static) {
+ Parm *p;
+ String *tm;
+
+ // determine an offset index, as members have an extra 'this' argument
+ // except: static members and ctors.
+ int startIdx = 0;
+ if (is_member && !is_static && mode != Ctor) {
+ startIdx = 1;
+ }
+ // store number of arguments for argument checks
+ int num_args = emit_num_arguments(parms) - startIdx;
+ String *argcount = NewString("");
+ Printf(argcount, "%d", num_args);
+ Setattr(n, ARGCOUNT, argcount);
+
+ // process arguments
+ int i = 0;
+ for (p = parms; p; i++) {
+ String *arg = NewString("");
+ String *type = Getattr(p, "type");
+
+ // ignore varargs
+ if (SwigType_isvarargs(type))
+ break;
+
+ switch (mode) {
+ case Getter:
+ case Function:
+ if (is_member && !is_static && i == 0) {
+ Printv(arg, "thisObject", 0);
+ } else {
+ Printf(arg, "argv[%d]", i - startIdx);
+ }
+ break;
+ case Setter:
+ if (is_member && !is_static && i == 0) {
+ Printv(arg, "thisObject", 0);
+ } else {
+ Printv(arg, "value", 0);
+ }
+ break;
+ case Ctor:
+ Printf(arg, "argv[%d]", i);
+ break;
+ default:
+ throw "Illegal state.";
+ }
+ tm = emitInputTypemap(n, p, wrapper, arg);
+ Delete(arg);
+ if (tm) {
+ p = Getattr(p, "tmap:in:next");
+ } else {
+ p = nextSibling(p);
+ }
+ }
+}
+
+int JSCEmitter::initialize(Node *n) {
+
+ JSEmitter::initialize(n);
+
+ /* Get the output file name */
+ String *outfile = Getattr(n, "outfile");
+
+ /* Initialize I/O */
+ f_wrap_cpp = NewFile(outfile, "w", SWIG_output_files());
+ if (!f_wrap_cpp) {
+ FileErrorDisplay(outfile);
+ SWIG_exit(EXIT_FAILURE);
+ }
+
+ /* Initialization of members */
+ f_runtime = NewString("");
+ f_init = NewString("");
+ f_header = NewString("");
+
+ state.globals(CREATE_NAMESPACES, NewString(""));
+ state.globals(REGISTER_NAMESPACES, NewString(""));
+ state.globals(INITIALIZER, NewString(""));
+
+ /* Register file targets with the SWIG file handler */
+ Swig_register_filebyname("begin", f_wrap_cpp);
+ Swig_register_filebyname("header", f_header);
+ Swig_register_filebyname("wrapper", f_wrappers);
+ Swig_register_filebyname("runtime", f_runtime);
+ Swig_register_filebyname("init", f_init);
+
+ Swig_banner(f_wrap_cpp);
+
+ return SWIG_OK;
+}
+
+int JSCEmitter::dump(Node *n) {
+ /* Get the module name */
+ String *module = Getattr(n, "name");
+
+ Template initializer_define(getTemplate("js_initializer_define"));
+ initializer_define.replace("$jsname", module).pretty_print(f_header);
+
+ SwigType_emit_type_table(f_runtime, f_wrappers);
+
+ Printv(f_wrap_cpp, f_runtime, "\n", 0);
+ Printv(f_wrap_cpp, f_header, "\n", 0);
+ Printv(f_wrap_cpp, f_wrappers, "\n", 0);
+
+ emitNamespaces();
+
+ // compose the initializer function using a template
+ Template initializer(getTemplate("js_initializer"));
+ initializer.replace("$jsname", module)
+ .replace("$jsregisterclasses", state.globals(INITIALIZER))
+ .replace("$jscreatenamespaces", state.globals(CREATE_NAMESPACES))
+ .replace("$jsregisternamespaces", state.globals(REGISTER_NAMESPACES))
+ .pretty_print(f_init);
+
+ Printv(f_wrap_cpp, f_init, 0);
+
+ return SWIG_OK;
+}
+
+int JSCEmitter::close() {
+ Delete(f_runtime);
+ Delete(f_header);
+ Delete(f_wrappers);
+ Delete(f_init);
+ Delete(namespaces);
+ Delete(f_wrap_cpp);
+ return SWIG_OK;
+}
+
+int JSCEmitter::enterFunction(Node *n) {
+
+ JSEmitter::enterFunction(n);
+
+ return SWIG_OK;
+}
+
+int JSCEmitter::exitFunction(Node *n) {
+ Template t_function = getTemplate("jsc_function_declaration");
+
+ bool is_member = GetFlag(n, "ismember") | GetFlag(n, "feature:extend");
+ bool is_overloaded = GetFlag(n, "sym:overloaded");
+
+ // handle overloaded functions
+ if (is_overloaded) {
+ if (!Getattr(n, "sym:nextSibling")) {
+ //state.function(WRAPPER_NAME, Swig_name_wrapper(Getattr(n, "name")));
+ // create dispatcher
+ emitFunctionDispatcher(n, is_member);
+ } else {
+ //don't register wrappers of overloaded functions in function tables
+ return SWIG_OK;
+ }
+ }
+
+ t_function.replace("$jsname", state.function(NAME))
+ .replace("$jswrapper", state.function(WRAPPER_NAME));
+
+ if (is_member) {
+ if (GetFlag(state.function(), IS_STATIC)) {
+ t_function.pretty_print(state.clazz(STATIC_FUNCTIONS));
+ } else {
+ t_function.pretty_print(state.clazz(MEMBER_FUNCTIONS));
+ }
+ } else {
+ t_function.pretty_print(Getattr(current_namespace, "functions"));
+ }
+
+ return SWIG_OK;
+}
+
+int JSCEmitter::enterVariable(Node *n) {
+ JSEmitter::enterVariable(n);
+ state.variable(GETTER, NULL_STR);
+ state.variable(SETTER, VETO_SET);
+ return SWIG_OK;
+}
+
+int JSCEmitter::exitVariable(Node *n) {
+ Template t_variable(getTemplate("jsc_variable_declaration"));
+ t_variable.replace("$jsname", state.variable(NAME))
+ .replace("$jsgetter", state.variable(GETTER))
+ .replace("$jssetter", state.variable(SETTER));
+
+ if (GetFlag(n, "ismember")) {
+ if (GetFlag(state.variable(), IS_STATIC)
+ || Equal(Getattr(n, "nodeType"), "enumitem")) {
+ t_variable.pretty_print(state.clazz(STATIC_VARIABLES));
+ } else {
+ t_variable.pretty_print(state.clazz(MEMBER_VARIABLES));
+ }
+ } else {
+ t_variable.pretty_print(Getattr(current_namespace, "values"));
+ }
+
+ return SWIG_OK;
+}
+
+int JSCEmitter::enterClass(Node *n) {
+ JSEmitter::enterClass(n);
+ state.clazz(MEMBER_VARIABLES, NewString(""));
+ state.clazz(MEMBER_FUNCTIONS, NewString(""));
+ state.clazz(STATIC_VARIABLES, NewString(""));
+ state.clazz(STATIC_FUNCTIONS, NewString(""));
+
+ Template t_class_decl = getTemplate("jsc_class_declaration");
+ t_class_decl.replace("$jsmangledname", state.clazz(NAME_MANGLED))
+ .pretty_print(f_wrappers);
+
+ return SWIG_OK;
+}
+
+int JSCEmitter::exitClass(Node *n) {
+ Template t_class_tables(getTemplate("jsc_class_tables"));
+ t_class_tables.replace("$jsmangledname", state.clazz(NAME_MANGLED))
+ .replace("$jsclassvariables", state.clazz(MEMBER_VARIABLES))
+ .replace("$jsclassfunctions", state.clazz(MEMBER_FUNCTIONS))
+ .replace("$jsstaticclassfunctions", state.clazz(STATIC_FUNCTIONS))
+ .replace("$jsstaticclassvariables", state.clazz(STATIC_VARIABLES))
+ .pretty_print(f_wrappers);
+
+ /* adds the ctor wrappers at this position */
+ // Note: this is necessary to avoid extra forward declarations.
+ //Append(f_wrappers, state.clazz(CTOR_WRAPPERS));
+
+ // for abstract classes add a vetoing ctor
+ if (GetFlag(state.clazz(), IS_ABSTRACT)) {
+ Template t_veto_ctor(getTemplate("js_veto_ctor"));
+ t_veto_ctor.replace("$jswrapper", state.clazz(CTOR))
+ .replace("$jsname", state.clazz(NAME))
+ .pretty_print(f_wrappers);
+ }
+
+ /* adds a class template statement to initializer function */
+ Template t_classtemplate(getTemplate("jsc_class_definition"));
+
+ /* prepare registration of base class */
+ String *jsclass_inheritance = NewString("");
+ Node *base_class = getBaseClass(n);
+ if (base_class != NULL) {
+ Template t_inherit(getTemplate("jsc_class_inherit"));
+ t_inherit.replace("$jsmangledname", state.clazz(NAME_MANGLED))
+ .replace("$jsbaseclassmangled", SwigType_manglestr(Getattr(base_class, "name")))
+ .pretty_print(jsclass_inheritance);
+ } else {
+ Template t_inherit(getTemplate("jsc_class_noinherit"));
+ t_inherit.replace("$jsmangledname", state.clazz(NAME_MANGLED))
+ .pretty_print(jsclass_inheritance);
+ }
+
+ t_classtemplate.replace("$jsmangledname", state.clazz(NAME_MANGLED))
+ .replace("$jsmangledtype", state.clazz(TYPE_MANGLED))
+ .replace("$jsclass_inheritance", jsclass_inheritance)
+ .replace("$jsctor", state.clazz(CTOR))
+ .replace("$jsdtor", state.clazz(DTOR))
+ .pretty_print(state.globals(INITIALIZER));
+ Delete(jsclass_inheritance);
+
+ /* Note: this makes sure that there is a swig_type added for this class */
+ SwigType_remember_clientdata(state.clazz(TYPE_MANGLED), NewString("0"));
+
+ /* adds a class registration statement to initializer function */
+ Template t_registerclass(getTemplate("jsc_class_registration"));
+ t_registerclass.replace("$jsname", state.clazz(NAME))
+ .replace("$jsmangledname", state.clazz(NAME_MANGLED))
+ .replace("$jsnspace", Getattr(state.clazz("nspace"), NAME_MANGLED))
+ .pretty_print(state.globals(INITIALIZER));
+
+ return SWIG_OK;
+}
+
+Hash *JSCEmitter::createNamespaceEntry(const char *name, const char *parent) {
+ Hash *entry = JSEmitter::createNamespaceEntry(name, parent);
+ Setattr(entry, "functions", NewString(""));
+ Setattr(entry, "values", NewString(""));
+ return entry;
+}
+
+int JSCEmitter::emitNamespaces() {
+ Iterator it;
+ for (it = First(namespaces); it.item; it = Next(it)) {
+ Hash *entry = it.item;
+ String *name = Getattr(entry, NAME);
+ String *name_mangled = Getattr(entry, NAME_MANGLED);
+ String *parent = Getattr(entry, PARENT);
+ String *parent_mangled = Swig_name_mangle(parent);
+ String *functions = Getattr(entry, "functions");
+ String *variables = Getattr(entry, "values");
+
+ // skip the global namespace which is given by the application
+
+ Template namespace_definition(getTemplate("jsc_nspace_declaration"));
+ namespace_definition.replace("$jsglobalvariables", variables)
+ .replace("$jsglobalfunctions", functions)
+ .replace("$jsnspace", name_mangled)
+ .pretty_print(f_wrap_cpp);
+
+ Template t_createNamespace(getTemplate("jsc_nspace_definition"));
+ t_createNamespace.replace("$jsmangledname", name_mangled);
+ Append(state.globals(CREATE_NAMESPACES), t_createNamespace.str());
+
+ // Don't register 'exports' as namespace. It is return to the application.
+ if (!Equal("exports", name)) {
+ Template t_registerNamespace(getTemplate("jsc_nspace_registration"));
+ t_registerNamespace.replace("$jsmangledname", name_mangled)
+ .replace("$jsname", name)
+ .replace("$jsparent", parent_mangled);
+ Append(state.globals(REGISTER_NAMESPACES), t_registerNamespace.str());
+ }
+ }
+
+ return SWIG_OK;
+}
+
+JSEmitter *swig_javascript_create_JSCEmitter() {
+ return new JSCEmitter();
+}
+
+/**********************************************************************
+ * V8: JSEmitter implementation for V8 engine
+ **********************************************************************/
+
+class V8Emitter:public JSEmitter {
+
+public:
+ V8Emitter();
+
+ virtual ~ V8Emitter();
+ virtual int initialize(Node *n);
+ virtual int dump(Node *n);
+ virtual int close();
+ virtual int enterClass(Node *n);
+ virtual int exitClass(Node *n);
+ virtual int enterVariable(Node *n);
+ virtual int exitVariable(Node *n);
+ virtual int exitFunction(Node *n);
+
+protected:
+ virtual void marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, MarshallingMode mode, bool is_member, bool is_static);
+ virtual int emitNamespaces();
+
+protected:
+ /* built-in parts */
+ String *f_runtime;
+ String *f_header;
+ String *f_init;
+ String *f_post_init;
+
+ /* part for class templates */
+ String *f_class_templates;
+
+ /* parts for initilizer */
+ String *f_init_namespaces;
+ String *f_init_class_templates;
+ String *f_init_wrappers;
+ String *f_init_inheritance;
+ String *f_init_class_instances;
+ String *f_init_static_wrappers;
+ String *f_init_register_classes;
+ String *f_init_register_namespaces;
+
+ // the output cpp file
+ File *f_wrap_cpp;
+
+ String *NULL_STR;
+ String *VETO_SET;
+ String *moduleName;
+
+};
+
+V8Emitter::V8Emitter()
+: JSEmitter(JSEmitter::V8), NULL_STR(NewString("0")), VETO_SET(NewString("JS_veto_set_variable")) {
+}
+
+V8Emitter::~V8Emitter() {
+ Delete(NULL_STR);
+ Delete(VETO_SET);
+}
+
+int V8Emitter::initialize(Node *n) {
+ JSEmitter::initialize(n);
+
+ moduleName = Getattr(n, "name");
+
+ // Get the output file name
+ String *outfile = Getattr(n, "outfile");
+ f_wrap_cpp = NewFile(outfile, "w", SWIG_output_files());
+ if (!f_wrap_cpp) {
+ FileErrorDisplay(outfile);
+ SWIG_exit(EXIT_FAILURE);
+ }
+
+ f_runtime = NewString("");
+ f_header = NewString("");
+ f_class_templates = NewString("");
+ f_init = NewString("");
+ f_post_init = NewString("");
+
+ f_init_namespaces = NewString("");
+ f_init_class_templates = NewString("");
+ f_init_wrappers = NewString("");
+ f_init_inheritance = NewString("");
+ f_init_class_instances = NewString("");
+ f_init_static_wrappers = NewString("");
+ f_init_register_classes = NewString("");
+ f_init_register_namespaces = NewString("");
+
+ // note: this is necessary for built-in generation of SWIG runtime code
+ Swig_register_filebyname("begin", f_wrap_cpp);
+ Swig_register_filebyname("runtime", f_runtime);
+ Swig_register_filebyname("header", f_header);
+ Swig_register_filebyname("wrapper", f_wrappers);
+ Swig_register_filebyname("init", f_init);
+ Swig_register_filebyname("post-init", f_post_init);
+
+ state.globals(FORCE_CPP, NewString("1"));
+
+ Swig_banner(f_wrap_cpp);
+
+ return SWIG_OK;
+}
+
+int V8Emitter::dump(Node *n) {
+ /* Get the module name */
+ String *module = Getattr(n, "name");
+
+ Template initializer_define(getTemplate("js_initializer_define"));
+ initializer_define.replace("$jsname", module).pretty_print(f_header);
+
+ SwigType_emit_type_table(f_runtime, f_wrappers);
+
+ Printv(f_wrap_cpp, f_runtime, "\n", 0);
+ Printv(f_wrap_cpp, f_header, "\n", 0);
+ Printv(f_wrap_cpp, f_class_templates, "\n", 0);
+ Printv(f_wrap_cpp, f_wrappers, "\n", 0);
+
+ emitNamespaces();
+
+ // compose the initializer function using a template
+ // filled with sub-parts
+ Template initializer(getTemplate("js_initializer"));
+ initializer.replace("$jsname", moduleName)
+ .replace("$jsv8nspaces", f_init_namespaces)
+ .replace("$jsv8classtemplates", f_init_class_templates)
+ .replace("$jsv8wrappers", f_init_wrappers)
+ .replace("$jsv8inheritance", f_init_inheritance)
+ .replace("$jsv8classinstances", f_init_class_instances)
+ .replace("$jsv8staticwrappers", f_init_static_wrappers)
+ .replace("$jsv8registerclasses", f_init_register_classes)
+ .replace("$jsv8registernspaces", f_init_register_namespaces);
+ Printv(f_init, initializer.str(), 0);
+
+ Printv(f_wrap_cpp, f_init, 0);
+
+ Printv(f_wrap_cpp, f_post_init, 0);
+
+ return SWIG_OK;
+}
+
+int V8Emitter::close() {
+ Delete(f_runtime);
+ Delete(f_header);
+ Delete(f_class_templates);
+ Delete(f_init_namespaces);
+ Delete(f_init_class_templates);
+ Delete(f_init_wrappers);
+ Delete(f_init_inheritance);
+ Delete(f_init_class_instances);
+ Delete(f_init_static_wrappers);
+ Delete(f_init_register_classes);
+ Delete(f_init_register_namespaces);
+ Delete(f_init);
+ Delete(f_post_init);
+ Delete(f_wrap_cpp);
+ return SWIG_OK;
+}
+
+int V8Emitter::enterClass(Node *n) {
+ JSEmitter::enterClass(n);
+
+ // emit declaration of a v8 class template
+ Template t_decl_class(getTemplate("jsv8_declare_class_template"));
+ t_decl_class.replace("$jsmangledname", state.clazz(NAME_MANGLED))
+ .trim()
+ .pretty_print(f_class_templates);
+
+ return SWIG_OK;
+}
+
+int V8Emitter::exitClass(Node *n) {
+ if (GetFlag(state.clazz(), IS_ABSTRACT)) {
+ Template t_veto_ctor(getTemplate("js_veto_ctor"));
+ t_veto_ctor.replace("$jswrapper", state.clazz(CTOR))
+ .replace("$jsname", state.clazz(NAME))
+ .pretty_print(f_wrappers);
+ }
+
+ /* Note: this makes sure that there is a swig_type added for this class */
+ String *clientData = NewString("");
+ Printf(clientData, "&%s_clientData", state.clazz(NAME_MANGLED));
+
+ /* Note: this makes sure that there is a swig_type added for this class */
+ SwigType_remember_clientdata(state.clazz(TYPE_MANGLED), NewString("0"));
+
+ // emit definition of v8 class template
+ Template t_def_class = getTemplate("jsv8_define_class_template");
+ t_def_class.replace("$jsmangledname", state.clazz(NAME_MANGLED))
+ .replace("$jsname", state.clazz(NAME))
+ .replace("$jsmangledtype", state.clazz(TYPE_MANGLED))
+ .replace("$jsdtor", state.clazz(DTOR))
+ .trim()
+ .pretty_print(f_init_class_templates);
+
+ Template t_class_instance = getTemplate("jsv8_create_class_instance");
+ t_class_instance.replace("$jsname", state.clazz(NAME))
+ .replace("$jsmangledname", state.clazz(NAME_MANGLED))
+ .replace("$jsctor", state.clazz(CTOR))
+ .trim()
+ .pretty_print(f_init_class_instances);
+
+ // emit inheritance setup
+ Node *baseClass = getBaseClass(n);
+ if (baseClass) {
+ String *base_name = Getattr(baseClass, "name");
+
+ Template t_inherit = getTemplate("jsv8_inherit");
+
+ String *base_name_mangled = SwigType_manglestr(base_name);
+ t_inherit.replace("$jsmangledname", state.clazz(NAME_MANGLED))
+ .replace("$jsbaseclass", base_name_mangled)
+ .trim()
+ .pretty_print(f_init_inheritance);
+ Delete(base_name_mangled);
+ }
+ // emit registeration of class template
+ Template t_register = getTemplate("jsv8_register_class");
+ t_register.replace("$jsmangledname", state.clazz(NAME_MANGLED))
+ .replace("$jsname", state.clazz(NAME))
+ .replace("$jsparent", Getattr(state.clazz("nspace"), NAME_MANGLED))
+ .trim()
+ .pretty_print(f_init_register_classes);
+
+ return SWIG_OK;
+}
+
+int V8Emitter::enterVariable(Node *n) {
+ JSEmitter::enterVariable(n);
+
+ state.variable(GETTER, NULL_STR);
+ state.variable(SETTER, VETO_SET);
+
+ return SWIG_OK;
+}
+
+int V8Emitter::exitVariable(Node *n) {
+ if (GetFlag(n, "ismember")) {
+ if (GetFlag(state.variable(), IS_STATIC) || Equal(Getattr(n, "nodeType"), "enumitem")) {
+ 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()
+ .pretty_print(f_init_static_wrappers);
+ } else {
+ Template t_register = getTemplate("jsv8_register_member_variable");
+ t_register.replace("$jsmangledname", state.clazz(NAME_MANGLED))
+ .replace("$jsname", state.variable(NAME))
+ .replace("$jsgetter", state.variable(GETTER))
+ .replace("$jssetter", state.variable(SETTER))
+ .trim()
+ .pretty_print(f_init_wrappers);
+ }
+ } else {
+ // Note: a global variable is treated like a static variable
+ // with the parent being a nspace object (instead of class object)
+ Template t_register = getTemplate("jsv8_register_static_variable");
+ t_register.replace("$jsparent", Getattr(current_namespace, NAME_MANGLED))
+ .replace("$jsname", state.variable(NAME))
+ .replace("$jsgetter", state.variable(GETTER))
+ .replace("$jssetter", state.variable(SETTER))
+ .trim()
+ .pretty_print(f_init_wrappers);
+ }
+
+ return SWIG_OK;
+}
+
+int V8Emitter::exitFunction(Node *n) {
+ bool is_member = GetFlag(n, "ismember") | GetFlag(n, "feature:extend");
+
+ // create a dispatcher for overloaded functions
+ bool is_overloaded = GetFlag(n, "sym:overloaded");
+ if (is_overloaded) {
+ if (!Getattr(n, "sym:nextSibling")) {
+ //state.function(WRAPPER_NAME, Swig_name_wrapper(Getattr(n, "name")));
+ emitFunctionDispatcher(n, is_member);
+ } else {
+ //don't register wrappers of overloaded functions in function tables
+ return SWIG_OK;
+ }
+ }
+ // register the function at the specific context
+ if (is_member) {
+ if (GetFlag(state.function(), IS_STATIC)) {
+ Template t_register = getTemplate("jsv8_register_static_function");
+ t_register.replace("$jsparent", state.clazz(NAME_MANGLED))
+ .replace("$jsname", state.function(NAME))
+ .replace("$jswrapper", state.function(WRAPPER_NAME))
+ .trim()
+ .pretty_print(f_init_static_wrappers);
+ } else {
+ Template t_register = getTemplate("jsv8_register_member_function");
+ t_register.replace("$jsmangledname", state.clazz(NAME_MANGLED))
+ .replace("$jsname", state.function(NAME))
+ .replace("$jswrapper", state.function(WRAPPER_NAME))
+ .trim()
+ .pretty_print(f_init_wrappers);
+ }
+ } else {
+ // Note: a global function is treated like a static function
+ // with the parent being a nspace object instead of class object
+ Template t_register = getTemplate("jsv8_register_static_function");
+ t_register.replace("$jsparent", Getattr(current_namespace, NAME_MANGLED))
+ .replace("$jsname", state.function(NAME))
+ .replace("$jswrapper", state.function(WRAPPER_NAME))
+ .trim()
+ .pretty_print(f_init_static_wrappers);
+ }
+
+ return SWIG_OK;
+}
+
+void V8Emitter::marshalInputArgs(Node *n, ParmList *parms, Wrapper *wrapper, MarshallingMode mode, bool is_member, bool is_static) {
+ Parm *p;
+ String *tm;
+
+ int startIdx = 0;
+ if (is_member && !is_static && mode != Ctor) {
+ startIdx = 1;
+ }
+ // store number of arguments for argument checks
+ int num_args = emit_num_arguments(parms) - startIdx;
+ String *argcount = NewString("");
+ Printf(argcount, "%d", num_args);
+ Setattr(n, ARGCOUNT, argcount);
+
+ int i = 0;
+ for (p = parms; p; i++) {
+ String *arg = NewString("");
+ String *type = Getattr(p, "type");
+
+ // ignore varargs
+ if (SwigType_isvarargs(type))
+ break;
+
+ switch (mode) {
+ case Getter:
+ if (is_member && !is_static && i == 0) {
+ Printv(arg, "info.Holder()", 0);
+ } else {
+ Printf(arg, "args[%d]", i - startIdx);
+ }
+ break;
+ case Function:
+ if (is_member && !is_static && i == 0) {
+ Printv(arg, "args.Holder()", 0);
+ } else {
+ Printf(arg, "args[%d]", i - startIdx);
+ }
+ break;
+ case Setter:
+ if (is_member && !is_static && i == 0) {
+ Printv(arg, "info.Holder()", 0);
+ } else {
+ Printv(arg, "value", 0);
+ }
+ break;
+ case Ctor:
+ Printf(arg, "args[%d]", i);
+ break;
+ default:
+ throw "Illegal state.";
+ }
+
+ tm = emitInputTypemap(n, p, wrapper, arg);
+ Delete(arg);
+
+ if (tm) {
+ p = Getattr(p, "tmap:in:next");
+ } else {
+ p = nextSibling(p);
+ }
+ }
+}
+
+int V8Emitter::emitNamespaces() {
+ Iterator it;
+ for (it = First(namespaces); it.item; it = Next(it)) {
+ Hash *entry = it.item;
+ String *name = Getattr(entry, NAME);
+ String *name_mangled = Getattr(entry, NAME_MANGLED);
+ String *parent = Getattr(entry, PARENT);
+ String *parent_mangled = Swig_name_mangle(parent);
+
+ bool do_create = true;
+ bool do_register = true;
+
+ if (Equal(parent, "")) {
+ do_register = false;
+ }
+ // Note: 'exports' is by convention the name of the object where
+ // globals are stored into
+ if (Equal(name, "exports")) {
+ do_create = false;
+ }
+
+ if (do_create) {
+ // create namespace object and register it to the parent scope
+ Template t_create_ns = getTemplate("jsv8_create_namespace");
+ t_create_ns.replace("$jsmangledname", name_mangled)
+ .trim()
+ .pretty_print(f_init_namespaces);
+ }
+
+ if (do_register) {
+ Template t_register_ns = getTemplate("jsv8_register_namespace");
+ t_register_ns.replace("$jsmangledname", name_mangled)
+ .replace("$jsname", name)
+ .replace("$jsparent", parent_mangled)
+ .trim();
+
+ // prepend in order to achieve reversed order of registration statements
+ String *tmp_register_stmt = NewString("");
+ t_register_ns.pretty_print(tmp_register_stmt);
+ Insert(f_init_register_namespaces, 0, tmp_register_stmt);
+ Delete(tmp_register_stmt);
+ }
+ }
+
+ return SWIG_OK;
+}
+
+JSEmitter *swig_javascript_create_V8Emitter() {
+ return new V8Emitter();
+}
+
+/**********************************************************************
+ * Helper implementations
+ **********************************************************************/
+
+JSEmitterState::JSEmitterState()
+: globalHash(NewHash()) {
+ // initialize sub-hashes
+ Setattr(globalHash, "class", NewHash());
+ Setattr(globalHash, "function", NewHash());
+ Setattr(globalHash, "variable", NewHash());
+}
+
+JSEmitterState::~JSEmitterState() {
+ Delete(globalHash);
+}
+
+DOH *JSEmitterState::getState(const char *key, bool new_key) {
+ if (new_key) {
+ Hash *hash = NewHash();
+ Setattr(globalHash, key, hash);
+ }
+ return Getattr(globalHash, key);
+}
+
+DOH *JSEmitterState::globals() {
+ return globalHash;
+}
+
+DOH *JSEmitterState::globals(const char *key, DOH *initial) {
+ if (initial != 0) {
+ Setattr(globalHash, key, initial);
+ }
+ return Getattr(globalHash, key);
+}
+
+DOH *JSEmitterState::clazz(bool new_key) {
+ return getState("class", new_key);
+}
+
+DOH *JSEmitterState::clazz(const char *key, DOH *initial) {
+ DOH *c = clazz();
+ if (initial != 0) {
+ Setattr(c, key, initial);
+ }
+ return Getattr(c, key);
+}
+
+DOH *JSEmitterState::function(bool new_key) {
+ return getState("function", new_key);
+}
+
+DOH *JSEmitterState::function(const char *key, DOH *initial) {
+ DOH *f = function();
+ if (initial != 0) {
+ Setattr(f, key, initial);
+ }
+ return Getattr(f, key);
+}
+
+DOH *JSEmitterState::variable(bool new_key) {
+ return getState("variable", new_key);
+}
+
+DOH *JSEmitterState::variable(const char *key, DOH *initial) {
+ DOH *v = variable();
+ if (initial != 0) {
+ Setattr(v, key, initial);
+ }
+ return Getattr(v, key);
+}
+
+/*static*/
+int JSEmitterState::IsSet(DOH *val) {
+ if (!val) {
+ return 0;
+ } else {
+ const char *cval = Char(val);
+ if (!cval)
+ return 0;
+ return (strcmp(cval, "0") != 0) ? 1 : 0;
+ }
+}
+
+/* -----------------------------------------------------------------------------
+ * Template::Template() : creates a Template class for given template code
+ * ----------------------------------------------------------------------------- */
+
+Template::Template(const String *code_) {
+
+ if (!code_) {
+ Printf(stdout, "Template code was null. Illegal input for template.");
+ SWIG_exit(EXIT_FAILURE);
+ }
+ code = NewString(code_);
+ templateName = NewString("");
+}
+
+Template::Template(const String *code_, const String *templateName_) {
+
+ if (!code_) {
+ Printf(stdout, "Template code was null. Illegal input for template.");
+ SWIG_exit(EXIT_FAILURE);
+ }
+
+ code = NewString(code_);
+ templateName = NewString(templateName_);
+}
+
+
+/* -----------------------------------------------------------------------------
+ * Template::~Template() : cleans up of Template.
+ * ----------------------------------------------------------------------------- */
+
+Template::~Template() {
+ Delete(code);
+ Delete(templateName);
+}
+
+/* -----------------------------------------------------------------------------
+ * String* Template::str() : retrieves the current content of the template.
+ * ----------------------------------------------------------------------------- */
+
+String *Template::str() {
+ if (js_template_enable_debug) {
+ String *pre_code = NewString("");
+ String *post_code = NewString("");
+ String *debug_code = NewString("");
+ Printf(pre_code, "/* begin fragment(\"%s\") */", templateName);
+ Printf(post_code, "/* end fragment(\"%s\") */", templateName);
+ Printf(debug_code, "%s\n%s\n%s\n", pre_code, code, post_code);
+
+ Delete(code);
+ Delete(pre_code);
+ Delete(post_code);
+
+ code = debug_code;
+ }
+ return code;
+}
+
+Template & Template::trim() {
+ const char *str = Char(code);
+ if (str == 0)
+ return *this;
+
+ int length = Len(code);
+ if (length == 0)
+ return *this;
+
+ int idx;
+ for (idx = 0; idx < length; ++idx) {
+ if (str[idx] != ' ' && str[idx] != '\t' && str[idx] != '\r' && str[idx] != '\n')
+ break;
+ }
+ int start_pos = idx;
+
+ for (idx = length - 1; idx >= start_pos; --idx) {
+ if (str[idx] != ' ' && str[idx] != '\t' && str[idx] != '\r' && str[idx] != '\n')
+ break;
+ }
+ int end_pos = idx;
+
+ int new_length = end_pos - start_pos + 1;
+ char *newstr = new char[new_length + 1];
+ memcpy(newstr, str + start_pos, new_length);
+ newstr[new_length] = 0;
+
+ Delete(code);
+ code = NewString(newstr);
+ delete[]newstr;
+
+ return *this;
+}
+
+/* -----------------------------------------------------------------------------
+ * Template& Template::replace(const String* pattern, const String* repl) :
+ *
+ * replaces all occurences of a given pattern with a given replacement.
+ *
+ * - pattern: the pattern to be replaced
+ * - repl: the replacement string
+ * - returns a reference to the Template to allow chaining of methods.
+ * ----------------------------------------------------------------------------- */
+
+Template & Template::replace(const String *pattern, const String *repl) {
+ Replaceall(code, pattern, repl);
+ return *this;
+}
+
+Template & Template::print(DOH *doh) {
+ Printv(doh, str(), 0);
+ return *this;
+}
+
+Template & Template::pretty_print(DOH *doh) {
+ Wrapper_pretty_print(str(), doh);
+ return *this;
+}
+
+Template::Template(const Template & t) {
+ code = NewString(t.code);
+ templateName = NewString(t.templateName);
+}
+
+void Template::operator=(const Template & t) {
+ Delete(code);
+ Delete(templateName);
+ code = NewString(t.code);
+ templateName = NewString(t.templateName);
+}
diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx
index bd22ad37d..46e21fb91 100644
--- a/Source/Modules/lua.cxx
+++ b/Source/Modules/lua.cxx
@@ -86,11 +86,11 @@ extern "C"
you can add new ones here
(though for now I have not bothered)
NEW LANGUAGE NOTE:END ************************************************/
-static const char *usage = (char *) "\
+static const char *usage = "\
Lua Options (available with -lua)\n\
-elua - Generates LTR compatible wrappers for smaller devices running elua\n\
-eluac - LTR compatible wrappers in \"crass compress\" mode for elua\n\
- -elua-emulate - Emulates behaviour of eLua. Usefull only for testing.\n\
+ -elua-emulate - Emulates behaviour of eLua. Useful only for testing.\n\
Incompatible with -elua/-eluac options.\n\
-nomoduleglobal - Do not register the module name as a global variable \n\
but return the module table from calls to require.\n\
@@ -205,7 +205,7 @@ public:
}
/* NEW LANGUAGE NOTE:***********************************************
- This is called to initalise the system & read any command line args
+ This is called to initialise the system & read any command line args
most of this is boilerplate code, except the command line args
which depends upon what args your code supports
NEW LANGUAGE NOTE:END *********************************************** */
@@ -380,7 +380,7 @@ public:
Dump(f_header, f_begin);
Dump(f_wrappers, f_begin);
Dump(f_initbeforefunc, f_begin);
- /* for the Lua code it needs to be properly excaped to be added into the C/C++ code */
+ /* for the Lua code it needs to be properly escaped to be added into the C/C++ code */
escapeCode(s_luacode);
Printf(f_begin, "const char* SWIG_LUACODE=\n \"%s\";\n\n", s_luacode);
Wrapper_pretty_print(f_init, f_begin);
@@ -436,9 +436,9 @@ public:
/* NEW LANGUAGE NOTE:***********************************************
This is it!
you get this one right, and most of your work is done
- but its going to take soem file to get it working right
+ but its going to take some file to get it working right
quite a bit of this is generally boilerplate code
- (or stuff I dont understand)
+ (or stuff I don't understand)
that which matters will have extra added comments
NEW LANGUAGE NOTE:END *********************************************** */
/* ---------------------------------------------------------------------
@@ -534,7 +534,7 @@ public:
}
/* NEW LANGUAGE NOTE:***********************************************
- the wrapper object holds all the wrappering code
+ the wrapper object holds all the wrapper code
we need to add a couple of local variables
NEW LANGUAGE NOTE:END *********************************************** */
Wrapper *f = NewWrapper();
@@ -554,7 +554,7 @@ public:
/* NEW LANGUAGE NOTE:***********************************************
the format of a lua fn is:
static int wrap_XXX(lua_State* L){...}
- this line adds this into the wrappering code
+ this line adds this into the wrapper code
NEW LANGUAGE NOTE:END *********************************************** */
Printv(f->def, "static int ", wname, "(lua_State* L) {", NIL);
@@ -657,7 +657,7 @@ public:
continue;
} else {
/* NEW LANGUAGE NOTE:***********************************************
- // why is this code not called when I dont have a typemap?
+ // why is this code not called when I don't have a typemap?
// instead of giving a warning, no code is generated
NEW LANGUAGE NOTE:END *********************************************** */
Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0));
@@ -792,7 +792,7 @@ public:
Replaceall(f->code, "$result", Swig_cresult_name());
/* Dump the function out */
- /* in Lua we will not emit the destructor as a wrappered function,
+ /* in Lua we will not emit the destructor as a wrapper function,
Lua will automatically call the destructor when the object is free'd
However: you cannot just skip this function as it will not emit
any custom destructor (using %extend), as you need to call emit_action()
@@ -835,7 +835,7 @@ public:
/* NEW LANGUAGE NOTE:***********************************************
This is an extra function used for overloading of functions
it checks the args & then calls the relevant fn
- nost of the real work in again typemaps:
+ most of the real work in again typemaps:
look for %typecheck(SWIG_TYPECHECK_*) in the .swg file
NEW LANGUAGE NOTE:END *********************************************** */
int dispatchFunction(Node *n) {
@@ -1958,6 +1958,10 @@ public:
SetFlag(carrays_hash, "lua:closed");
+ // Do arrays describe class instance part or class static part
+ const int is_instance = GetFlag(carrays_hash, "lua:class_instance");
+
+
String *attr_tab = Getattr(carrays_hash, "attributes");
Printf(attr_tab, " {0,0,0}\n};\n");
Printv(output, attr_tab, NIL);
@@ -1968,7 +1972,17 @@ public:
Printv(const_tab, tab4, "{LNILKEY, LNILVAL}\n", "};\n", NIL);
else
Printf(const_tab, " {0,0,0,0,0,0}\n};\n");
- Printv(output, const_tab, NIL);
+
+ // For the sake of compiling with -Wall -Werror we print constants
+ // only when necessary
+ int need_constants = 0;
+ if ( (elua_ltr || eluac_ltr) && (old_metatable_bindings) )
+ need_constants = 1;
+ else if (!is_instance) // static part need constants tab
+ need_constants = 1;
+
+ if (need_constants)
+ Printv(output, const_tab, NIL);
if (elua_ltr) {
// Put forward declaration of metatable array
@@ -2009,7 +2023,18 @@ public:
Printv(output, set_tab, NIL);
}
- if (!eluac_ltr) {
+ // Heuristic whether we need to print metatable or not.
+ // For the sake of compiling with -Wall -Werror we don't print
+ // metatable for static part.
+ int need_metatable = 0;
+ if (eluac_ltr)
+ need_metatable = 0;
+ else if(!is_instance)
+ need_metatable = 0;
+ else
+ need_metatable = 1;
+
+ if (need_metatable) {
String *metatable_tab = Getattr(carrays_hash, "metatable");
assert(metatable_tab);
if (elua_ltr) {
diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx
index 66e2548dc..833394b9c 100644
--- a/Source/Modules/main.cxx
+++ b/Source/Modules/main.cxx
@@ -160,9 +160,9 @@ static String *SwigLib = 0; // Library directory
static String *SwigLibWinUnix = 0; // Extra library directory on Windows
static int freeze = 0;
static String *lang_config = 0;
-static char *hpp_extension = (char *) "h";
-static char *cpp_extension = (char *) "cxx";
-static char *depends_extension = (char *) "d";
+static const char *hpp_extension = "h";
+static const char *cpp_extension = "cxx";
+static const char *depends_extension = "d";
static String *outdir = 0;
static String *xmlout = 0;
static int outcurrentdir = 0;
@@ -324,7 +324,7 @@ const String *SWIG_output_directory() {
}
void SWIG_config_cppext(const char *ext) {
- cpp_extension = (char *) ext;
+ cpp_extension = ext;
}
List *SWIG_output_files() {
@@ -465,7 +465,7 @@ void SWIG_getoptions(int argc, char *argv[]) {
Swig_mark_arg(i);
} else if (strncmp(argv[i], "-D", 2) == 0) {
String *d = NewString(argv[i] + 2);
- Replace(d, (char *) "=", (char *) " ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
+ Replace(d, "=", " ", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
Preprocessor_define((DOH *) d, 0);
Delete(d);
// Create a symbol
diff --git a/Source/Modules/modula3.cxx b/Source/Modules/modula3.cxx
index 4c56d0664..db5d0981b 100644
--- a/Source/Modules/modula3.cxx
+++ b/Source/Modules/modula3.cxx
@@ -3956,7 +3956,7 @@ extern "C" Language *swig_modula3(void) {
* Static member variables
* ----------------------------------------------------------------------------- */
-const char *MODULA3::usage = (char *) "\
+const char *MODULA3::usage = "\
Modula 3 Options (available with -modula3)\n\
-generateconst <file> - Generate code for computing numeric values of constants\n\
-generaterename <file> - Generate suggestions for %rename\n\
diff --git a/Source/Modules/mzscheme.cxx b/Source/Modules/mzscheme.cxx
index a147dd9c4..ed9641b30 100644
--- a/Source/Modules/mzscheme.cxx
+++ b/Source/Modules/mzscheme.cxx
@@ -15,7 +15,7 @@
#include <ctype.h>
-static const char *usage = (char *) "\
+static const char *usage = "\
Mzscheme Options (available with -mzscheme)\n\
-declaremodule - Create extension that declares a module\n\
-dynamic-load <library>,[library,...] - Do not link with these libraries, dynamic load\n\
@@ -36,7 +36,7 @@ static bool declaremodule = false;
static bool noinit = false;
static String *load_libraries = NULL;
static String *module = 0;
-static char *mzscheme_path = (char *) "mzscheme";
+static const char *mzscheme_path = "mzscheme";
static String *init_func_def = 0;
static File *f_begin = 0;
diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx
index f60c13ed3..f1ec8a8cf 100644
--- a/Source/Modules/ocaml.cxx
+++ b/Source/Modules/ocaml.cxx
@@ -15,7 +15,7 @@
#include <ctype.h>
-static const char *usage = (char *) "\
+static const char *usage = "\
Ocaml Options (available with -ocaml)\n\
-oldvarnames - Old intermediary method names for variable wrappers\n\
-prefix <name> - Set a prefix <name> to be prepended to all names\n\
@@ -29,7 +29,7 @@ static int const_enum = 0;
static int static_member_function = 0;
static int generate_sizeof = 0;
static String *prefix = 0;
-static char *ocaml_path = (char *) "ocaml";
+static const char *ocaml_path = "ocaml";
static bool old_variable_names = false;
static String *classname = 0;
static String *module = 0;
diff --git a/Source/Modules/octave.cxx b/Source/Modules/octave.cxx
index 14118972d..103b59194 100644
--- a/Source/Modules/octave.cxx
+++ b/Source/Modules/octave.cxx
@@ -17,7 +17,7 @@
static String *global_name = 0;
static String *op_prefix = 0;
-static const char *usage = (char *) "\
+static const char *usage = "\
Octave Options (available with -octave)\n\
-globals <name> - Set <name> used to access C global variables [default: 'cvar']\n\
Use '.' to load C global variables into module namespace\n\
diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx
index 28f4a3f3d..ff504d461 100644
--- a/Source/Modules/perl5.cxx
+++ b/Source/Modules/perl5.cxx
@@ -17,7 +17,7 @@ static int treduce = SWIG_cparse_template_reduce(0);
#include <ctype.h>
-static const char *usage = (char *) "\
+static const char *usage = "\
Perl5 Options (available with -perl5)\n\
-compat - Compatibility mode\n\
-const - Wrap constants as constants and not variables (implies -proxy)\n\
diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx
index be92b5657..b07c82d3b 100644
--- a/Source/Modules/php.cxx
+++ b/Source/Modules/php.cxx
@@ -42,7 +42,7 @@
#include <ctype.h>
#include <errno.h>
-static const char *usage = (char *) "\
+static const char *usage = "\
PHP Options (available with -php)\n\
-cppext <ext> - Change C++ file extension to <ext> (default is cpp)\n\
-noproxy - Don't generate proxy classes.\n\
@@ -2054,7 +2054,6 @@ done:
// Write property SET handlers
ki = First(shadow_set_vars);
-
if (ki.key) {
// This class has setters.
Printf(s_phpclasses, "\n\tfunction __set($var,$value) {\n");
@@ -2077,17 +2076,6 @@ done:
Printf(s_phpclasses, "\t\t$this->%s[$var] = $value;\n", SWIG_DATA);
}
Printf(s_phpclasses, "\t}\n");
-
- /* Create __isset for PHP 5.1 and later; PHP 5.0 will just ignore it. */
- Printf(s_phpclasses, "\n\tfunction __isset($var) {\n");
- Printf(s_phpclasses, "\t\tif (function_exists('%s_'.$var.'_set')) return true;\n", shadow_classname);
- Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n");
- if (baseclass) {
- Printf(s_phpclasses, "\t\treturn %s%s::__isset($var);\n", prefix, baseclass);
- } else {
- Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA);
- }
- Printf(s_phpclasses, "\t}\n");
} else {
Printf(s_phpclasses, "\n\tfunction __set($var,$value) {\n");
Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_alter_newobject($this->%s,$value);\n", module, SWIG_PTR);
@@ -2097,18 +2085,10 @@ done:
Printf(s_phpclasses, "\t\t$this->%s[$var] = $value;\n", SWIG_DATA);
}
Printf(s_phpclasses, "\t}\n");
- Printf(s_phpclasses, "\n\tfunction __isset($var) {\n");
- Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n");
- if (baseclass) {
- Printf(s_phpclasses, "\t\treturn %s%s::__isset($var);\n", prefix, baseclass);
- } else {
- Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA);
- }
- Printf(s_phpclasses, "\t}\n");
}
+
// Write property GET handlers
ki = First(shadow_get_vars);
-
if (ki.key) {
// This class has getters.
Printf(s_phpclasses, "\n\tfunction __get($var) {\n");
@@ -2144,6 +2124,19 @@ done:
Printf(s_phpclasses, "\t\treturn $this->%s[$var];\n", SWIG_DATA);
}
Printf(s_phpclasses, "\t}\n");
+
+ /* Create __isset for PHP 5.1 and later; PHP 5.0 will just ignore it. */
+ /* __isset() should return true for read-only properties, so check for
+ * *_get() not *_set(). */
+ Printf(s_phpclasses, "\n\tfunction __isset($var) {\n");
+ Printf(s_phpclasses, "\t\tif (function_exists('%s_'.$var.'_get')) return true;\n", shadow_classname);
+ Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n");
+ if (baseclass) {
+ Printf(s_phpclasses, "\t\treturn %s%s::__isset($var);\n", prefix, baseclass);
+ } else {
+ Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA);
+ }
+ Printf(s_phpclasses, "\t}\n");
} else {
Printf(s_phpclasses, "\n\tfunction __get($var) {\n");
Printf(s_phpclasses, "\t\tif ($var === 'thisown') return swig_%s_get_newobject($this->%s);\n", module, SWIG_PTR);
@@ -2153,6 +2146,14 @@ done:
Printf(s_phpclasses, "\t\treturn $this->%s[$var];\n", SWIG_DATA);
}
Printf(s_phpclasses, "\t}\n");
+ Printf(s_phpclasses, "\n\tfunction __isset($var) {\n");
+ Printf(s_phpclasses, "\t\tif ($var === 'thisown') return true;\n");
+ if (baseclass) {
+ Printf(s_phpclasses, "\t\treturn %s%s::__isset($var);\n", prefix, baseclass);
+ } else {
+ Printf(s_phpclasses, "\t\treturn array_key_exists($var, $this->%s);\n", SWIG_DATA);
+ }
+ Printf(s_phpclasses, "\t}\n");
}
if (!class_has_ctor) {
@@ -2272,8 +2273,8 @@ done:
if (i) {
Insert(args, 0, ", ");
}
- Printf(director_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0%s TSRMLS_CC);\n}\n", Swig_cresult_name(), ctype, sname, args);
- Printf(director_prot_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0%s TSRMLS_CC);\n}\n", Swig_cresult_name(), ctype, sname, args);
+ Printf(director_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0 TSRMLS_CC%s);\n}\n", Swig_cresult_name(), ctype, sname, args);
+ Printf(director_prot_ctor_code, "} else {\n %s = (%s *)new SwigDirector_%s(arg0 TSRMLS_CC%s);\n}\n", Swig_cresult_name(), ctype, sname, args);
Delete(args);
wrapperType = directorconstructor;
@@ -2385,17 +2386,23 @@ done:
parms = p;
if (!Getattr(n, "defaultargs")) {
+ // There should always be a "self" parameter first.
+ assert(ParmList_len(parms) > 0);
+
/* constructor */
{
Wrapper *w = NewWrapper();
String *call;
String *basetype = Getattr(parent, "classtype");
+
+ // We put TSRMLS_DC after the self parameter in order to cope with
+ // any default parameters.
String *target = Swig_method_decl(0, decl, classname, parms, 0, 0);
- if (((const char *)Char(target))[Len(target) - 2] == '(') {
- Insert(target, Len(target) - 1, "TSRMLS_D");
- } else {
- Insert(target, Len(target) - 1, " TSRMLS_DC");
- }
+ const char * p = Char(target);
+ const char * comma = strchr(p, ',');
+ size_t ins = comma ? comma - p : Len(target) - 1;
+ Insert(target, ins, " TSRMLS_DC");
+
call = Swig_csuperclass_call(0, basetype, superparms);
Printf(w->def, "%s::%s: %s, Swig::Director(self TSRMLS_CC) {", classname, target, call);
Append(w->def, "}");
@@ -2407,12 +2414,14 @@ done:
/* constructor header */
{
+ // We put TSRMLS_DC after the self parameter in order to cope with
+ // any default parameters.
String *target = Swig_method_decl(0, decl, classname, parms, 0, 1);
- if (((const char *)Char(target))[Len(target) - 2] == '(') {
- Insert(target, Len(target) - 1, "TSRMLS_D");
- } else {
- Insert(target, Len(target) - 1, " TSRMLS_DC");
- }
+ const char * p = Char(target);
+ const char * comma = strchr(p, ',');
+ size_t ins = comma ? comma - p : Len(target) - 1;
+ Insert(target, ins, " TSRMLS_DC");
+
Printf(f_directors_h, " %s;\n", target);
Delete(target);
}
diff --git a/Source/Modules/pike.cxx b/Source/Modules/pike.cxx
index cdbddc15d..22c5a638b 100644
--- a/Source/Modules/pike.cxx
+++ b/Source/Modules/pike.cxx
@@ -33,7 +33,7 @@
#include <ctype.h> // for isalnum()
-static const char *usage = (char *) "\
+static const char *usage = "\
Pike Options (available with -pike)\n\
[no additional options]\n\
\n";
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
index 13ddbfb61..06c1c4868 100644
--- a/Source/Modules/python.cxx
+++ b/Source/Modules/python.cxx
@@ -107,7 +107,7 @@ enum autodoc_t {
};
-static const char *usage1 = (char *) "\
+static const char *usage1 = "\
Python Options (available with -python)\n\
-aliasobj0 - Alias obj0 when using fastunpack, needed for some old typemaps \n\
-buildnone - Use Py_BuildValue(" ") to obtain Py_None (default in Windows)\n\
@@ -127,7 +127,7 @@ Python Options (available with -python)\n\
-keyword - Use keyword arguments\n\
-modern - Use modern python features only, without compatibility code\n\
-modernargs - Use \"modern\" args mechanism to pack/unpack the function arguments\n";
-static const char *usage2 = (char *) "\
+static const char *usage2 = "\
-newrepr - Use more informative version of __repr__ in proxy classes (default) \n\
-newvwm - New value wrapper mode, use only when everything else fails \n\
-noaliasobj0 - Don't generate an obj0 alias when using fastunpack (default) \n\
@@ -144,7 +144,7 @@ static const char *usage2 = (char *) "\
-noh - Don't generate the output header file\n\
-nomodern - Don't use modern python features which are not backwards compatible \n\
-nomodernargs - Use classic ParseTuple/CallFunction methods to pack/unpack the function arguments (default) \n";
-static const char *usage3 = (char *) "\
+static const char *usage3 = "\
-noolddefs - Don't emit the old method definitions even when using fastproxy (default) \n\
-nooutputtuple - Use a PyList for appending output values (default) \n\
-noproxy - Don't generate proxy classes \n\
diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx
index c3860a161..3befcfbdd 100644
--- a/Source/Modules/r.cxx
+++ b/Source/Modules/r.cxx
@@ -14,7 +14,6 @@
#include "swigmod.h"
static const double DEFAULT_NUMBER = .0000123456712312312323;
-static const int MAX_OVERLOAD_ARGS = 5;
static String* replaceInitialDash(const String *name)
{
@@ -206,7 +205,7 @@ static void writeListByLine(List *l, File *out, bool quote = 0) {
}
-static const char *usage = (char *)"\
+static const char *usage = "\
R Options (available with -r)\n\
-copystruct - Emit R code to copy C structs (on by default)\n\
-cppcast - Enable C++ casting operators (default) \n\
@@ -2161,7 +2160,7 @@ int R::functionWrapper(Node *n) {
/* If we are dealing with a method in an C++ class, then
add the name of the R function and its definition.
XXX need to figure out how to store the Wrapper if possible in the hash/list.
- Would like to be able to do this so that we can potentialy insert
+ Would like to be able to do this so that we can potentially insert
*/
if(processing_member_access_function || processing_class_member_function) {
addAccessor(member_name, sfun, iname);
diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx
index 5ff599d54..6aeaae5a1 100644
--- a/Source/Modules/ruby.cxx
+++ b/Source/Modules/ruby.cxx
@@ -130,7 +130,7 @@ enum autodoc_t {
AUTODOC_NONE
};
-static const char *usage = (char *) "\
+static const char *usage = "\
Ruby Options (available with -ruby)\n\
-autorename - Enable renaming of classes and methods to follow Ruby coding standards\n\
-cppcast - Enable C++ casting operators (default)\n\
@@ -1111,7 +1111,7 @@ public:
/* typedef void *VALUE */
SwigType *value = NewSwigType(T_VOID);
SwigType_add_pointer(value);
- SwigType_typedef(value, (char *) "VALUE");
+ SwigType_typedef(value, "VALUE");
Delete(value);
/* Set module name */
diff --git a/Source/Modules/swigmain.cxx b/Source/Modules/swigmain.cxx
index 7c9cded70..8a0861d17 100644
--- a/Source/Modules/swigmain.cxx
+++ b/Source/Modules/swigmain.cxx
@@ -51,6 +51,7 @@ extern "C" {
Language *swig_r(void);
Language *swig_go(void);
Language *swig_d(void);
+ Language *swig_javascript(void);
}
struct swig_module {
@@ -73,6 +74,7 @@ static swig_module modules[] = {
{"-go", swig_go, "Go"},
{"-guile", swig_guile, "Guile"},
{"-java", swig_java, "Java"},
+ {"-javascript", swig_javascript, "Javascript"},
{"-lua", swig_lua, "Lua"},
{"-modula3", swig_modula3, "Modula 3"},
{"-mzscheme", swig_mzscheme, "Mzscheme"},
diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx
index e61071167..ac356098b 100644
--- a/Source/Modules/tcl8.cxx
+++ b/Source/Modules/tcl8.cxx
@@ -15,7 +15,7 @@
#include "cparse.h"
static int treduce = SWIG_cparse_template_reduce(0);
-static const char *usage = (char *) "\
+static const char *usage = "\
Tcl 8 Options (available with -tcl)\n\
-itcl - Enable ITcl support\n\
-nosafe - Leave out SafeInit module function.\n\
diff --git a/Source/Modules/uffi.cxx b/Source/Modules/uffi.cxx
index b0136a361..d56ed3b1f 100644
--- a/Source/Modules/uffi.cxx
+++ b/Source/Modules/uffi.cxx
@@ -15,7 +15,7 @@
#include "swigmod.h"
-static const char *usage = (char *) "\
+static const char *usage = "\
UFFI Options (available with -uffi)\n\
-identifier-converter <type or funcname> - \n\
Specifies the type of conversion to do on C identifiers\n\
diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c
index ec0acfa77..d15c2e12f 100644
--- a/Source/Swig/cwrap.c
+++ b/Source/Swig/cwrap.c
@@ -467,7 +467,7 @@ static String *Swig_cmethod_call(const_String_or_char_ptr name, ParmList *parms,
return func;
if (!self)
- self = (char *) "(this)->";
+ self = "(this)->";
Append(func, self);
if (SwigType_istemplate(name) && (strncmp(Char(name), "operator ", 9) == 0)) {
diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c
index 12228079e..d8c3f7f3f 100644
--- a/Source/Swig/scanner.c
+++ b/Source/Swig/scanner.c
@@ -45,8 +45,8 @@ typedef struct Locator {
} Locator;
static int follow_locators = 0;
-void Scanner_push_brackets(Scanner*);
-void Scanner_clear_brackets(Scanner*);
+static void brackets_push(Scanner *);
+static void brackets_clear(Scanner *);
/* -----------------------------------------------------------------------------
* NewScanner()
@@ -70,7 +70,7 @@ Scanner *NewScanner(void) {
s->error_line = 0;
s->freeze_line = 0;
s->brackets = NewList();
- Scanner_push_brackets(s);
+ brackets_push(s);
return s;
}
@@ -80,7 +80,7 @@ Scanner *NewScanner(void) {
* Delete a scanner object.
* ----------------------------------------------------------------------------- */
-void DelScanner(Scanner * s) {
+void DelScanner(Scanner *s) {
assert(s);
Delete(s->scanobjs);
Delete(s->brackets);
@@ -98,12 +98,12 @@ void DelScanner(Scanner * s) {
* Clear the contents of a scanner object.
* ----------------------------------------------------------------------------- */
-void Scanner_clear(Scanner * s) {
+void Scanner_clear(Scanner *s) {
assert(s);
Delete(s->str);
Clear(s->text);
Clear(s->scanobjs);
- Scanner_clear_brackets(s);
+ brackets_clear(s);
Delete(s->error);
s->str = 0;
s->error = 0;
@@ -126,7 +126,7 @@ void Scanner_clear(Scanner * s) {
* immediately before returning to the old text.
* ----------------------------------------------------------------------------- */
-void Scanner_push(Scanner * s, String *txt) {
+void Scanner_push(Scanner *s, String *txt) {
assert(s && txt);
Push(s->scanobjs, txt);
if (s->str) {
@@ -145,7 +145,7 @@ void Scanner_push(Scanner * s, String *txt) {
* call to Scanner_token().
* ----------------------------------------------------------------------------- */
-void Scanner_pushtoken(Scanner * s, int nt, const_String_or_char_ptr val) {
+void Scanner_pushtoken(Scanner *s, int nt, const_String_or_char_ptr val) {
assert(s);
assert((nt >= 0) && (nt < SWIG_MAXTOKENS));
s->nexttoken = nt;
@@ -161,7 +161,7 @@ void Scanner_pushtoken(Scanner * s, int nt, const_String_or_char_ptr val) {
* Set the file and line number location of the scanner.
* ----------------------------------------------------------------------------- */
-void Scanner_set_location(Scanner * s, String *file, int line) {
+void Scanner_set_location(Scanner *s, String *file, int line) {
Setline(s->str, line);
Setfile(s->str, file);
s->line = line;
@@ -173,7 +173,7 @@ void Scanner_set_location(Scanner * s, String *file, int line) {
* Get the current file.
* ----------------------------------------------------------------------------- */
-String *Scanner_file(Scanner * s) {
+String *Scanner_file(Scanner *s) {
return Getfile(s->str);
}
@@ -182,7 +182,7 @@ String *Scanner_file(Scanner * s) {
*
* Get the current line number
* ----------------------------------------------------------------------------- */
-int Scanner_line(Scanner * s) {
+int Scanner_line(Scanner *s) {
return s->line;
}
@@ -191,7 +191,7 @@ int Scanner_line(Scanner * s) {
*
* Get the line number on which the current token starts
* ----------------------------------------------------------------------------- */
-int Scanner_start_line(Scanner * s) {
+int Scanner_start_line(Scanner *s) {
return s->start_line;
}
@@ -201,7 +201,7 @@ int Scanner_start_line(Scanner * s) {
* Change the set of additional characters that can be used to start an identifier.
* ----------------------------------------------------------------------------- */
-void Scanner_idstart(Scanner * s, const char *id) {
+void Scanner_idstart(Scanner *s, const char *id) {
free(s->idstart);
s->idstart = Swig_copy_string(id);
}
@@ -211,7 +211,7 @@ void Scanner_idstart(Scanner * s, const char *id) {
*
* Returns the next character from the scanner or 0 if end of the string.
* ----------------------------------------------------------------------------- */
-static char nextchar(Scanner * s) {
+static char nextchar(Scanner *s) {
int nc;
if (!s->str)
return 0;
@@ -253,8 +253,7 @@ String *Scanner_errmsg(Scanner *s) {
return s->error;
}
-int
-Scanner_errline(Scanner *s) {
+int Scanner_errline(Scanner *s) {
return s->error_line;
}
@@ -269,71 +268,99 @@ static void freeze_line(Scanner *s, int val) {
}
/* -----------------------------------------------------------------------------
- * Scanner_brackets()
+ * brackets_count()
*
* Returns the number of brackets at the current depth.
+ * A syntax error with unbalanced ) brackets will result in a NULL pointer return.
* ----------------------------------------------------------------------------- */
-int*
-Scanner_brackets(Scanner *s) {
- return (int*)(**((void***)Getitem(s->brackets, 0))); /* TODO: Use VoidObj*->ptr instead of void** */
+static int *brackets_count(Scanner *s) {
+ int *count;
+ if (Len(s->brackets) > 0)
+ count = (int *)Data(Getitem(s->brackets, 0));
+ else
+ count = 0;
+ return count;
}
/* -----------------------------------------------------------------------------
- * Scanner_clear_brackets()
+ * brackets_clear()
*
* Resets the current depth and clears all brackets.
* Usually called at the end of statements;
* ----------------------------------------------------------------------------- */
-void
-Scanner_clear_brackets(Scanner *s) {
+static void brackets_clear(Scanner *s) {
Clear(s->brackets);
- Scanner_push_brackets(s); /* base bracket count should always be created */
+ brackets_push(s); /* base bracket count should always be created */
}
/* -----------------------------------------------------------------------------
- * Scanner_inc_brackets()
+ * brackets_increment()
*
* Increases the number of brackets at the current depth.
- * Usually called when '<' was found.
+ * Usually called when a single '<' is found.
* ----------------------------------------------------------------------------- */
-void
-Scanner_inc_brackets(Scanner *s) {
- (*Scanner_brackets(s))++;
+static void brackets_increment(Scanner *s) {
+ int *count = brackets_count(s);
+ if (count)
+ (*count)++;
}
/* -----------------------------------------------------------------------------
- * Scanner_dec_brackets()
+ * brackets_decrement()
*
* Decreases the number of brackets at the current depth.
- * Usually called when '>' was found.
+ * Usually called when a single '>' is found.
* ----------------------------------------------------------------------------- */
-void
-Scanner_dec_brackets(Scanner *s) {
- (*Scanner_brackets(s))--;
+static void brackets_decrement(Scanner *s) {
+ int *count = brackets_count(s);
+ if (count)
+ (*count)--;
}
/* -----------------------------------------------------------------------------
- * Scanner_push_brackets()
+ * brackets_reset()
+ *
+ * Sets the number of '<' brackets back to zero. Called at the point where
+ * it is no longer possible to have a matching closing >> pair for a template.
+ * ----------------------------------------------------------------------------- */
+static void brackets_reset(Scanner *s) {
+ int *count = brackets_count(s);
+ if (count)
+ *count = 0;
+}
+
+/* -----------------------------------------------------------------------------
+ * brackets_push()
*
* Increases the depth of brackets.
- * Usually called when '(' was found.
+ * Usually called when '(' is found.
* ----------------------------------------------------------------------------- */
-void
-Scanner_push_brackets(Scanner *s) {
+static void brackets_push(Scanner *s) {
int *newInt = malloc(sizeof(int));
*newInt = 0;
Push(s->brackets, NewVoid(newInt, free));
}
/* -----------------------------------------------------------------------------
- * Scanner_pop_brackets()
+ * brackets_pop()
*
* Decreases the depth of brackets.
- * Usually called when ')' was found.
+ * Usually called when ')' is found.
* ----------------------------------------------------------------------------- */
-void
-Scanner_pop_brackets(Scanner *s) {
- Delitem(s->brackets, 0);
+static void brackets_pop(Scanner *s) {
+ if (Len(s->brackets) > 0) /* protect against unbalanced ')' brackets */
+ Delitem(s->brackets, 0);
+}
+
+/* -----------------------------------------------------------------------------
+ * brackets_allow_shift()
+ *
+ * Return 1 to allow shift (>>), or 0 if (>>) should be split into (> >).
+ * This is for C++11 template syntax for closing templates.
+ * ----------------------------------------------------------------------------- */
+static int brackets_allow_shift(Scanner *s) {
+ int *count = brackets_count(s);
+ return !count || (*count <= 0);
}
/* -----------------------------------------------------------------------------
@@ -341,7 +368,7 @@ Scanner_pop_brackets(Scanner *s) {
*
* Retract n characters
* ----------------------------------------------------------------------------- */
-static void retract(Scanner * s, int n) {
+static void retract(Scanner *s, int n) {
int i, l;
char *str;
@@ -482,7 +509,7 @@ static void get_escape(Scanner *s) {
* Return the raw value of the next token.
* ----------------------------------------------------------------------------- */
-static int look(Scanner * s) {
+static int look(Scanner *s) {
int state = 0;
int c = 0;
String *str_delimiter = 0;
@@ -526,15 +553,15 @@ static int look(Scanner * s) {
/* Look for single character symbols */
else if (c == '(') {
- Scanner_push_brackets(s);
+ brackets_push(s);
return SWIG_TOKEN_LPAREN;
}
else if (c == ')') {
- Scanner_pop_brackets(s);
+ brackets_pop(s);
return SWIG_TOKEN_RPAREN;
}
else if (c == ';') {
- Scanner_clear_brackets(s);
+ brackets_clear(s);
return SWIG_TOKEN_SEMI;
}
else if (c == ',')
@@ -543,8 +570,10 @@ static int look(Scanner * s) {
state = 220;
else if (c == '}')
return SWIG_TOKEN_RBRACE;
- else if (c == '{')
+ else if (c == '{') {
+ brackets_reset(s);
return SWIG_TOKEN_LBRACE;
+ }
else if (c == '=')
state = 33;
else if (c == '+')
@@ -848,28 +877,32 @@ static int look(Scanner * s) {
break;
case 60: /* shift operators */
- Scanner_inc_brackets(s);
- if ((c = nextchar(s)) == 0)
+ if ((c = nextchar(s)) == 0) {
+ brackets_increment(s);
return SWIG_TOKEN_LESSTHAN;
+ }
if (c == '<')
state = 240;
else if (c == '=')
return SWIG_TOKEN_LTEQUAL;
else {
retract(s, 1);
+ brackets_increment(s);
return SWIG_TOKEN_LESSTHAN;
}
break;
case 61:
- Scanner_dec_brackets(s);
- if ((c = nextchar(s)) == 0)
+ if ((c = nextchar(s)) == 0) {
+ brackets_decrement(s);
return SWIG_TOKEN_GREATERTHAN;
- if (c == '>' && ((*Scanner_brackets(s))<0)) /* go to double >> only, if no template < has been used */
+ }
+ if (c == '>' && brackets_allow_shift(s))
state = 250;
else if (c == '=')
return SWIG_TOKEN_GTEQUAL;
else {
retract(s, 1);
+ brackets_decrement(s);
return SWIG_TOKEN_GREATERTHAN;
}
break;
@@ -1311,7 +1344,6 @@ static int look(Scanner * s) {
break;
case 240: /* LSHIFT, LSEQUAL */
- Scanner_inc_brackets(s);
if ((c = nextchar(s)) == 0)
return SWIG_TOKEN_LSHIFT;
else if (c == '=')
@@ -1323,7 +1355,6 @@ static int look(Scanner * s) {
break;
case 250: /* RSHIFT, RSEQUAL */
- Scanner_dec_brackets(s);
if ((c = nextchar(s)) == 0)
return SWIG_TOKEN_RSHIFT;
else if (c == '=')
@@ -1361,7 +1392,7 @@ static int look(Scanner * s) {
* Real entry point to return the next token. Returns 0 if at end of input.
* ----------------------------------------------------------------------------- */
-int Scanner_token(Scanner * s) {
+int Scanner_token(Scanner *s) {
int t;
Delete(s->error);
if (s->nexttoken >= 0) {
@@ -1385,7 +1416,7 @@ int Scanner_token(Scanner * s) {
* Return the lexene associated with the last returned token.
* ----------------------------------------------------------------------------- */
-String *Scanner_text(Scanner * s) {
+String *Scanner_text(Scanner *s) {
return s->text;
}
@@ -1395,7 +1426,7 @@ String *Scanner_text(Scanner * s) {
* Skips to the end of a line
* ----------------------------------------------------------------------------- */
-void Scanner_skip_line(Scanner * s) {
+void Scanner_skip_line(Scanner *s) {
char c;
int done = 0;
Clear(s->text);
@@ -1420,7 +1451,7 @@ void Scanner_skip_line(Scanner * s) {
* (...). Ignores symbols inside comments or strings.
* ----------------------------------------------------------------------------- */
-int Scanner_skip_balanced(Scanner * s, int startchar, int endchar) {
+int Scanner_skip_balanced(Scanner *s, int startchar, int endchar) {
char c;
int num_levels = 1;
int state = 0;
diff --git a/Tools/javascript/Makefile.in b/Tools/javascript/Makefile.in
new file mode 100644
index 000000000..373c5d952
--- /dev/null
+++ b/Tools/javascript/Makefile.in
@@ -0,0 +1,56 @@
+# ----------------------------------------------------------------
+# Compile a custom javascript interpreter
+# ----------------------------------------------------------------
+#
+# Note:
+# There is no common CLI Javascript interpreter.
+# V8 comes with one 'd8' which however does not provide a means
+# to load extensions. Therefore, by default we use nodejs as
+# environment.
+# For testing native v8 and jsc extensions we provide our own
+# interpreter (see 'Tools/javascript').
+#
+# ----------------------------------------------------------------
+CC = @CC@
+# HACK: under OSX a g++ compiled interpreter is seg-faulting when loading module libraries
+# with 'c++' it works... probably some missing flags?
+JSCXX = @JSINTERPRETERCXX@
+CFLAGS = @PLATCFLAGS@
+CXXFLAGS = @BOOST_CPPFLAGS@ @PLATCXXFLAGS@
+LINKFLAGS = @JSINTERPRETERLINKFLAGS@
+
+ROOT_DIR = @ROOT_DIR@
+JSINCLUDES = @JSCOREINC@ @JSV8INC@
+JSDYNAMICLINKING = @JSCOREDYNAMICLINKING@ @JSV8DYNAMICLINKING@
+JSLIBRARYPREFIX = @JSLIBRARYPREFIX@
+JSSO =@JSSO@
+JSLDSHARED = @JSLDSHARED@
+JSCXXSHARED = @JSCXXSHARED@
+JSV8ENABLED = @JSV8ENABLED@
+JSCENABLED = @JSCENABLED@
+
+# These settings are provided by 'configure' (see '/configure.in')
+ifeq (1, $(JSV8ENABLED))
+ JS_INTERPRETER_SRC_V8 = v8_shell.cxx
+ JS_INTERPRETER_ENABLE_V8 = -DENABLE_V8
+endif
+
+ifeq (1, $(JSCENABLED))
+ JS_INTERPRETER_SRC_JSC = jsc_shell.cxx
+ JS_INTERPRETER_ENABLE_JSC = -DENABLE_JSC
+endif
+
+JS_INTERPRETER_DEFINES = $(JS_INTERPRETER_ENABLE_JSC) $(JS_INTERPRETER_ENABLE_V8)
+JS_INTERPRETER_SRC = javascript.cxx js_shell.cxx $(JS_INTERPRETER_SRC_JSC) $(JS_INTERPRETER_SRC_V8)
+
+JS_INTERPRETER_OBJS = $(JS_INTERPRETER_SRC:.cxx=.o)
+
+%.o: %.cxx
+ $(JSCXX) $(JS_INTERPRETER_DEFINES) $(CXXFLAGS) $(JSINCLUDES) -o $@ -c $<
+
+javascript: $(JS_INTERPRETER_OBJS)
+ $(JSCXX) $^ $(CXXFLAGS) -o javascript $(JSDYNAMICLINKING) $(LINKFLAGS)
+
+clean:
+ rm -f *.o
+ rm -f javascript
diff --git a/Tools/javascript/javascript.cxx b/Tools/javascript/javascript.cxx
new file mode 100644
index 000000000..5e7cc0b20
--- /dev/null
+++ b/Tools/javascript/javascript.cxx
@@ -0,0 +1,66 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include "js_shell.h"
+
+void print_usage() {
+ std::cout << "javascript [-i] [-jsc|-v8] [-l module] <js-file>" << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+
+#if defined(JAVASCRIPT_INTERPRETER_STOP)
+ std::cout << "Attach your Debugger and press any key to continue" << std::endl;
+ std::cin.get();
+#endif
+
+ std::string scriptPath = "";
+
+ bool interactive = false;
+ JSShell* shell = 0;
+
+ std::vector<std::string> modulePath;
+ modulePath.push_back(".");
+
+ for (int idx = 1; idx < argc; ++idx) {
+ if(strcmp(argv[idx], "-v8") == 0) {
+ shell = JSShell::Create(JSShell::V8);
+ } else if(strcmp(argv[idx], "-jsc") == 0) {
+ shell = JSShell::Create(JSShell::JSC);
+ } else if(strcmp(argv[idx], "-i") == 0) {
+ interactive = true;
+ } else if(strcmp(argv[idx], "-L") == 0) {
+ modulePath.push_back(argv[++idx]);
+ } else {
+ scriptPath = argv[idx];
+ }
+ }
+
+ if (shell == 0) {
+ shell = JSShell::Create();
+ }
+
+ shell->setModulePath(modulePath);
+
+ bool failed = false;
+
+ if(interactive) {
+ failed = !(shell->RunShell());
+ } else {
+ failed = !(shell->RunScript(scriptPath));
+ }
+
+ if (failed) {
+ delete shell;
+ printf("FAIL: Error during execution of script.\n");
+ return 1;
+ }
+
+ delete shell;
+
+ return 0;
+}
diff --git a/Tools/javascript/js_shell.cxx b/Tools/javascript/js_shell.cxx
new file mode 100644
index 000000000..539b83d65
--- /dev/null
+++ b/Tools/javascript/js_shell.cxx
@@ -0,0 +1,156 @@
+#include "js_shell.h"
+
+#include <iostream>
+#include <fstream>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#ifdef __GNUC__
+#ifdef __APPLE__
+#define LIBRARY_EXT ".bundle"
+#else
+#define LIBRARY_EXT ".so"
+#endif
+#include <dlfcn.h>
+#define LOAD_LIBRARY(name) dlopen(name, RTLD_LAZY)
+#define CLOSE_LIBRARY(handle) dlclose(handle)
+#define LIBRARY_ERROR dlerror
+#define LIBRARYFILE(name) std::string("lib").append(name).append(LIBRARY_EXT)
+#else
+#error "implement dll loading"
+#endif
+
+
+JSShell::~JSShell() {
+
+ for(std::vector<HANDLE>::iterator it = loaded_modules.begin();
+ it != loaded_modules.end(); ++it) {
+ HANDLE handle = *it;
+ CLOSE_LIBRARY(handle);
+ }
+
+}
+
+// TODO: this could be done more intelligent...
+// - can we achieve source file relative loading?
+// - better path resolution
+std::string JSShell::LoadModule(const std::string& name, HANDLE* library) {
+
+ // works only for posix like OSs
+ size_t pathIdx = name.find_last_of("/");
+
+ std::string lib_name;
+ std::string module_name;
+
+ if (pathIdx == std::string::npos) {
+ module_name = name;
+ lib_name = std::string(name).append(LIBRARY_EXT);
+ } else {
+ std::string path = name.substr(0, pathIdx+1);
+ module_name = name.substr(pathIdx+1);
+ lib_name = path.append(module_name).append(LIBRARY_EXT);
+ }
+
+ std::string lib_path;
+ HANDLE handle = 0;
+
+ for (int i = 0; i < module_path.size(); ++i) {
+ lib_path = module_path[i] + "/" + lib_name;
+ if (access( lib_path.c_str(), F_OK ) != -1) {
+ handle = LOAD_LIBRARY(lib_path.c_str());
+ }
+ }
+
+ if(handle == 0) {
+ std::cerr << "Could not find module " << lib_path << ":"
+ << std::endl << LIBRARY_ERROR() << std::endl;
+ return 0;
+ }
+
+ loaded_modules.push_back(handle);
+
+ *library = handle;
+
+ return module_name;
+}
+
+bool JSShell::RunScript(const std::string& scriptPath) {
+ std::string source = ReadFile(scriptPath);
+ if(!InitializeEngine()) return false;
+
+ // Node.js compatibility: make `print` available as `console.log()`
+ ExecuteScript("var console = {}; console.log = print;", "<console>");
+
+ if(!ExecuteScript(source, scriptPath)) {
+ return false;
+ }
+
+ return DisposeEngine();
+}
+
+bool JSShell::RunShell() {
+
+ if(!InitializeEngine()) return false;
+
+ static const int kBufferSize = 1024;
+ while (true) {
+ char buffer[kBufferSize];
+ printf("> ");
+ char* str = fgets(buffer, kBufferSize, stdin);
+ if (str == NULL) break;
+ std::string source(str);
+ ExecuteScript(source, "(shell)");
+ }
+ printf("\n");
+ return true;
+}
+
+std::string JSShell::ReadFile(const std::string& fileName)
+{
+ std::string script;
+
+ std::ifstream file(fileName.c_str());
+ if (file.is_open()) {
+ while ( file.good() ) {
+ std::string line;
+ getline(file, line);
+ script.append(line);
+ script.append("\n");
+ }
+ file.close();
+ } else {
+ std::cout << "Unable to open file " << fileName << "." << std::endl;
+ }
+
+ return script;
+}
+
+#ifdef ENABLE_JSC
+extern JSShell* JSCShell_Create();
+#endif
+#ifdef ENABLE_V8
+extern JSShell* V8Shell_Create();
+#endif
+
+typedef JSShell*(*ShellFactory)();
+
+static ShellFactory js_shell_factories[2] = {
+#ifdef ENABLE_JSC
+JSCShell_Create,
+#else
+0,
+#endif
+#ifdef ENABLE_V8
+V8Shell_Create,
+#else
+0,
+#endif
+};
+
+JSShell *JSShell::Create(Engine engine) {
+ if(js_shell_factories[engine] == 0) {
+ throw "Engine not available.";
+ }
+ return js_shell_factories[engine]();
+}
diff --git a/Tools/javascript/js_shell.h b/Tools/javascript/js_shell.h
new file mode 100644
index 000000000..1e2466b96
--- /dev/null
+++ b/Tools/javascript/js_shell.h
@@ -0,0 +1,53 @@
+#ifndef JS_SHELL_H
+#define JS_SHELL_H
+
+#include <vector>
+#include <string>
+
+typedef void* HANDLE;
+typedef void* MODULE;
+
+class JSShell {
+
+public:
+ enum Engine {
+ JSC = 0,
+ V8
+ };
+
+public:
+
+ JSShell() {}
+
+ virtual ~JSShell() = 0;
+
+ static JSShell* Create(Engine engine = JSC);
+
+ std::string LoadModule(const std::string& name, HANDLE* library);
+
+ virtual bool RunScript(const std::string& scriptPath);
+
+ virtual bool RunShell();
+
+ void setModulePath(const std::vector<std::string>& modulePath) {
+ module_path = modulePath;
+ }
+
+protected:
+
+ virtual bool InitializeEngine() = 0;
+
+ virtual bool ExecuteScript(const std::string& source, const std::string& scriptPath) = 0;
+
+ virtual bool DisposeEngine() = 0;
+
+ static std::string ReadFile(const std::string& fileName);
+
+protected:
+
+ std::vector<HANDLE> loaded_modules;
+ std::vector<std::string> module_path;
+
+};
+
+#endif // JS_SHELL_H
diff --git a/Tools/javascript/jsc_shell.cxx b/Tools/javascript/jsc_shell.cxx
new file mode 100644
index 000000000..292c4042b
--- /dev/null
+++ b/Tools/javascript/jsc_shell.cxx
@@ -0,0 +1,233 @@
+#include <JavaScriptCore/JavaScript.h>
+
+#include "js_shell.h"
+
+#include <iostream>
+#include <stdio.h>
+
+#ifdef __GNUC__
+#include <dlfcn.h>
+#define LOAD_SYMBOL(handle, name) dlsym(handle, name)
+#else
+#error "implement dll loading"
+#endif
+
+class JSCShell: public JSShell {
+
+typedef int (*JSCIntializer)(JSGlobalContextRef context, JSObjectRef *module);
+
+public:
+
+ JSCShell() {};
+
+ virtual ~JSCShell();
+
+protected:
+
+ virtual bool InitializeEngine();
+
+ virtual bool ExecuteScript(const std::string& source, const std::string& scriptPath);
+
+ virtual bool DisposeEngine();
+
+private:
+
+ JSObjectRef Import(const std::string &moduleName);
+
+ static JSValueRef Print(JSContextRef context, JSObjectRef object, JSObjectRef globalobj, size_t argc, const JSValueRef args[], JSValueRef* ex);
+
+ static JSValueRef Require(JSContextRef context, JSObjectRef object, JSObjectRef globalobj, size_t argc, const JSValueRef args[], JSValueRef* ex);
+
+ static bool RegisterFunction(JSGlobalContextRef context, JSObjectRef object, const char* functionName, JSObjectCallAsFunctionCallback cbFunction);
+
+ static void PrintError(JSContextRef, JSValueRef);
+
+private:
+
+ JSGlobalContextRef context;
+};
+
+JSCShell::~JSCShell() {
+ if(context != 0) {
+ JSGlobalContextRelease(context);
+ context = 0;
+ }
+}
+
+bool JSCShell::InitializeEngine() {
+ if(context != 0) {
+ JSGlobalContextRelease(context);
+ context = 0;
+ }
+ // TODO: check for initialization errors
+ context = JSGlobalContextCreate(NULL);
+ if(context == 0) return false;
+ JSObjectRef globalObject = JSContextGetGlobalObject(context);
+
+ // store this for later use
+ JSClassDefinition __shell_classdef__ = JSClassDefinition();
+
+ JSClassRef __shell_class__ = JSClassCreate(&__shell_classdef__);
+ JSObjectRef __shell__ = JSObjectMake(context, __shell_class__, 0);
+ bool success = JSObjectSetPrivate(__shell__, (void*) (long) this);
+ if (!success) {
+ std::cerr << "Could not register the shell in the Javascript context" << std::endl;
+ return false;
+ }
+ JSStringRef shellKey = JSStringCreateWithUTF8CString("__shell__");
+ JSObjectSetProperty(context, globalObject, shellKey, __shell__, kJSPropertyAttributeReadOnly, NULL);
+ JSStringRelease(shellKey);
+
+ JSCShell::RegisterFunction(context, globalObject, "print", JSCShell::Print);
+ JSCShell::RegisterFunction(context, globalObject, "require", JSCShell::Require);
+
+ return true;
+}
+
+bool JSCShell::ExecuteScript(const std::string& source, const std::string& scriptPath) {
+ JSStringRef jsScript;
+ JSStringRef sourceURL;
+ JSValueRef ex;
+ jsScript = JSStringCreateWithUTF8CString(source.c_str());
+ sourceURL = JSStringCreateWithUTF8CString(scriptPath.c_str());
+ JSValueRef jsResult = JSEvaluateScript(context, jsScript, 0, sourceURL, 0, &ex);
+ JSStringRelease(jsScript);
+ if (jsResult == NULL && ex != NULL) {
+ JSCShell::PrintError(context, ex);
+ return false;
+ }
+ return true;
+}
+
+bool JSCShell::DisposeEngine() {
+ JSGlobalContextRelease(context);
+ context = 0;
+ return true;
+}
+
+JSValueRef JSCShell::Print(JSContextRef context, JSObjectRef object,
+ JSObjectRef globalobj, size_t argc,
+ const JSValueRef args[], JSValueRef* ex) {
+ if (argc > 0)
+ {
+ JSStringRef string = JSValueToStringCopy(context, args[0], NULL);
+ size_t numChars = JSStringGetMaximumUTF8CStringSize(string);
+ char *stringUTF8 = new char[numChars];
+ JSStringGetUTF8CString(string, stringUTF8, numChars);
+ printf("%s\n", stringUTF8);
+
+ delete[] stringUTF8;
+ }
+
+ return JSValueMakeUndefined(context);
+}
+
+// Attention: this feature should not create too high expectations.
+// It is only capable of loading things relative to the execution directory
+// and not relative to the parent script.
+JSValueRef JSCShell::Require(JSContextRef context, JSObjectRef object,
+ JSObjectRef globalObj, size_t argc,
+ const JSValueRef args[], JSValueRef* ex) {
+ JSObjectRef module;
+
+ JSStringRef shellKey = JSStringCreateWithUTF8CString("__shell__");
+ JSValueRef shellAsVal = JSObjectGetProperty(context, globalObj, shellKey, NULL);
+ JSStringRelease(shellKey);
+ JSObjectRef shell = JSValueToObject(context, shellAsVal, 0);
+ JSCShell *_this = (JSCShell*) (long) JSObjectGetPrivate(shell);
+
+ if (argc > 0)
+ {
+ JSStringRef string = JSValueToStringCopy(context, args[0], NULL);
+ size_t numChars = JSStringGetMaximumUTF8CStringSize(string);
+ char *stringUTF8 = new char[numChars];
+ JSStringGetUTF8CString(string, stringUTF8, numChars);
+
+ std::string modulePath(stringUTF8);
+ module = _this->Import(modulePath);
+
+ delete[] stringUTF8;
+ }
+
+ if (module) {
+ return module;
+ } else {
+ printf("Ooops.\n");
+ return JSValueMakeUndefined(context);
+ }
+}
+
+JSObjectRef JSCShell::Import(const std::string& module_path) {
+
+ HANDLE library;
+ std::string module_name = LoadModule(module_path, &library);
+
+ if (library == 0) {
+ printf("Could not load module.");
+ return 0;
+ }
+
+ std::string symname = std::string(module_name).append("_initialize");
+
+ JSCIntializer init_function = reinterpret_cast<JSCIntializer>((long) LOAD_SYMBOL(library, symname.c_str()));
+ if(init_function == 0) {
+ printf("Could not find module's initializer function.");
+ return 0;
+ }
+
+ JSObjectRef module;
+ init_function(context, &module);
+
+ return module;
+}
+
+bool JSCShell::RegisterFunction(JSGlobalContextRef context, JSObjectRef object,
+ const char* functionName, JSObjectCallAsFunctionCallback callback) {
+ JSStringRef js_functionName = JSStringCreateWithUTF8CString(functionName);
+ JSObjectSetProperty(context, object, js_functionName,
+ JSObjectMakeFunctionWithCallback(context, js_functionName, callback),
+ kJSPropertyAttributeNone, NULL);
+ JSStringRelease(js_functionName);
+ return true;
+}
+
+void JSCShell::PrintError(JSContextRef ctx, JSValueRef err) {
+ char *buffer;
+ size_t length;
+
+ JSStringRef string = JSValueToStringCopy(ctx, err, 0);
+ length = JSStringGetLength(string);
+ buffer = new char[length+1];
+ JSStringGetUTF8CString(string, buffer, length+1);
+ std::string errMsg(buffer);
+ JSStringRelease(string);
+ delete[] buffer;
+
+ JSObjectRef errObj = JSValueToObject(ctx, err, 0);
+
+ if(errObj == 0) {
+ std::cerr << errMsg << std::endl;
+ return;
+ }
+
+ JSStringRef sourceURLKey = JSStringCreateWithUTF8CString("sourceURL");
+ JSStringRef sourceURLStr = JSValueToStringCopy(ctx, JSObjectGetProperty(ctx, errObj, sourceURLKey, 0), 0);
+ length = JSStringGetLength(sourceURLStr);
+ buffer = new char[length+1];
+ JSStringGetUTF8CString(sourceURLStr, buffer, length+1);
+ std::string sourceURL(buffer);
+ delete[] buffer;
+ JSStringRelease(sourceURLStr);
+ JSStringRelease(sourceURLKey);
+
+ JSStringRef lineKey = JSStringCreateWithUTF8CString("line");
+ JSValueRef jsLine = JSObjectGetProperty(ctx, errObj, lineKey, 0);
+ int line = (int) JSValueToNumber(ctx, jsLine, 0);
+ JSStringRelease(lineKey);
+
+ std::cerr << sourceURL << ":" << line << ":" << errMsg << std::endl;
+}
+
+JSShell* JSCShell_Create() {
+ return new JSCShell();
+}
diff --git a/Tools/javascript/v8_shell.cxx b/Tools/javascript/v8_shell.cxx
new file mode 100755
index 000000000..4c6334f2f
--- /dev/null
+++ b/Tools/javascript/v8_shell.cxx
@@ -0,0 +1,313 @@
+#include <assert.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <v8.h>
+#include <vector>
+
+#include "js_shell.h"
+
+typedef int (*V8ExtensionInitializer) (v8::Handle<v8::Object> module);
+
+class V8Shell: public JSShell {
+
+public:
+ V8Shell();
+
+ virtual ~V8Shell();
+
+ virtual bool RunScript(const std::string& scriptPath);
+
+ virtual bool RunShell();
+
+
+protected:
+
+ virtual bool InitializeEngine();
+
+ virtual bool ExecuteScript(const std::string& source, const std::string& scriptPath);
+
+ virtual bool DisposeEngine();
+
+private:
+
+ v8::Handle<v8::Value> Import(const std::string& moduleName);
+
+ v8::Persistent<v8::Context> CreateShellContext();
+
+ void ReportException(v8::TryCatch* handler);
+
+ static v8::Handle<v8::Value> Print(const v8::Arguments& args);
+
+ static v8::Handle<v8::Value> Require(const v8::Arguments& args);
+
+ static v8::Handle<v8::Value> Quit(const v8::Arguments& args);
+
+ static v8::Handle<v8::Value> Version(const v8::Arguments& args);
+
+ static const char* ToCString(const v8::String::Utf8Value& value);
+
+ virtual bool _ExecuteScript(const std::string& source, const std::string& scriptPath);
+
+protected:
+
+ v8::Persistent<v8::Context> context;
+};
+
+#ifdef __GNUC__
+#include <dlfcn.h>
+#define LOAD_SYMBOL(handle, name) dlsym(handle, name)
+#else
+#error "implement dll loading"
+#endif
+
+V8Shell::V8Shell(){}
+
+V8Shell::~V8Shell() {}
+
+bool V8Shell::RunScript(const std::string& scriptPath) {
+
+ if (!context.IsEmpty()) {
+ context.Dispose();
+ }
+
+ std::string source = ReadFile(scriptPath);
+
+ context = CreateShellContext();
+ if (context.IsEmpty()) {
+ printf("Could not create context.\n");
+ return false;
+ }
+ context->Enter();
+
+ bool success = _ExecuteScript(source, scriptPath);
+
+ context->Exit();
+ context.Dispose();
+ v8::V8::Dispose();
+
+ return true;
+}
+
+bool V8Shell::_ExecuteScript(const std::string& source, const std::string& scriptPath) {
+ v8::HandleScope scope;
+
+ // Store a pointer to this shell for later use
+ v8::Handle<v8::Object> global = context->Global();
+ v8::Local<v8::External> __shell__ = v8::External::New((void*) (long) this);
+ global->SetHiddenValue(v8::String::New("__shell__"), __shell__);
+
+ // Node.js compatibility: make `print` available as `console.log()`
+ ExecuteScript("var console = {}; console.log = print;", "<console>");
+
+ if(!ExecuteScript(source, scriptPath)) {
+ return false;
+ }
+
+ return true;
+}
+
+bool V8Shell::RunShell() {
+
+ if (!context.IsEmpty()) {
+ context.Dispose();
+ }
+
+ context = CreateShellContext();
+ if (context.IsEmpty()) {
+ printf("Could not create context.\n");
+ return false;
+ }
+
+ context->Enter();
+
+ v8::Context::Scope context_scope(context);
+
+ ExecuteScript("var console = {}; console.log = print;", "<console>");
+
+ static const int kBufferSize = 1024;
+ while (true) {
+ char buffer[kBufferSize];
+ printf("> ");
+ char* str = fgets(buffer, kBufferSize, stdin);
+ if (str == NULL) break;
+ std::string source(str);
+ ExecuteScript(source, "(shell)");
+ }
+ printf("\n");
+
+ context->Exit();
+ context.Dispose();
+ v8::V8::Dispose();
+
+ return true;
+}
+
+
+bool V8Shell::InitializeEngine() {
+ return true;
+}
+
+bool V8Shell::ExecuteScript(const std::string& source, const std::string& name) {
+ v8::HandleScope handle_scope;
+ v8::TryCatch try_catch;
+ v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(source.c_str()), v8::String::New(name.c_str()));
+
+ // Stop if script is empty
+ if (script.IsEmpty()) {
+ // Print errors that happened during compilation.
+ ReportException(&try_catch);
+ return false;
+ }
+
+ v8::Handle<v8::Value> result = script->Run();
+
+ // Print errors that happened during execution.
+ if (try_catch.HasCaught()) {
+ ReportException(&try_catch);
+ return false;
+ } else {
+ return true;
+ }
+}
+
+bool V8Shell::DisposeEngine() {
+ return true;
+}
+
+v8::Persistent<v8::Context> V8Shell::CreateShellContext() {
+ v8::HandleScope scope;
+
+ // Create a template for the global object.
+ v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
+
+ // Bind global functions
+ global->Set(v8::String::New("print"), v8::FunctionTemplate::New(V8Shell::Print));
+ global->Set(v8::String::New("quit"), v8::FunctionTemplate::New(V8Shell::Quit));
+ global->Set(v8::String::New("require"), v8::FunctionTemplate::New(V8Shell::Require));
+ global->Set(v8::String::New("version"), v8::FunctionTemplate::New(V8Shell::Version));
+
+ v8::Persistent<v8::Context> _context = v8::Context::New(NULL, global);
+
+ return _context;
+}
+
+v8::Handle<v8::Value> V8Shell::Import(const std::string& module_path)
+{
+ v8::HandleScope scope;
+
+ HANDLE library;
+ std::string module_name = LoadModule(module_path, &library);
+
+ std::string symname = std::string(module_name).append("_initialize");
+
+ V8ExtensionInitializer init_function = reinterpret_cast<V8ExtensionInitializer>((long) LOAD_SYMBOL(library, symname.c_str()));
+
+ if(init_function == 0) {
+ printf("Could not find initializer function.");
+ return v8::Undefined();
+ }
+
+ v8::Local<v8::Object> module = v8::Object::New();
+ init_function(module);
+ return scope.Close(module);
+}
+
+v8::Handle<v8::Value> V8Shell::Print(const v8::Arguments& args) {
+ bool first = true;
+ for (int i = 0; i < args.Length(); i++) {
+ v8::HandleScope handle_scope;
+ if (first) {
+ first = false;
+ } else {
+ printf(" ");
+ }
+ v8::String::Utf8Value str(args[i]);
+ const char* cstr = V8Shell::ToCString(str);
+ printf("%s", cstr);
+ }
+ printf("\n");
+ fflush(stdout);
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> V8Shell::Require(const v8::Arguments& args) {
+ v8::HandleScope scope;
+
+ if (args.Length() != 1) {
+ printf("Illegal arguments for `require`");
+ };
+
+ v8::String::Utf8Value str(args[0]);
+ const char* cstr = V8Shell::ToCString(str);
+ std::string moduleName(cstr);
+
+ v8::Local<v8::Object> global = v8::Context::GetCurrent()->Global();
+ v8::Local<v8::Value> hidden = global->GetHiddenValue(v8::String::New("__shell__"));
+ v8::Local<v8::External> __shell__ = v8::Local<v8::External>::Cast(hidden);
+ V8Shell* _this = (V8Shell*) (long) __shell__->Value();
+
+ v8::Handle<v8::Value> module = _this->Import(moduleName);
+
+ return scope.Close(module);
+}
+
+v8::Handle<v8::Value> V8Shell::Quit(const v8::Arguments& args) {
+ int exit_code = args[0]->Int32Value();
+ fflush(stdout);
+ fflush(stderr);
+ exit(exit_code);
+ return v8::Undefined();
+}
+
+v8::Handle<v8::Value> V8Shell::Version(const v8::Arguments& args) {
+ return v8::String::New(v8::V8::GetVersion());
+}
+
+void V8Shell::ReportException(v8::TryCatch* try_catch) {
+ v8::HandleScope handle_scope;
+ v8::String::Utf8Value exception(try_catch->Exception());
+ const char* exception_string = V8Shell::ToCString(exception);
+ v8::Handle<v8::Message> message = try_catch->Message();
+ if (message.IsEmpty()) {
+ // V8 didn't provide any extra information about this error; just
+ // print the exception.
+ printf("%s\n", exception_string);
+ } else {
+ // Print (filename):(line number): (message).
+ v8::String::Utf8Value filename(message->GetScriptResourceName());
+ const char* filename_string = V8Shell::ToCString(filename);
+ int linenum = message->GetLineNumber();
+ printf("%s:%i: %s\n", filename_string, linenum, exception_string);
+ // Print line of source code.
+ v8::String::Utf8Value sourceline(message->GetSourceLine());
+ const char* sourceline_string = V8Shell::ToCString(sourceline);
+ printf("%s\n", sourceline_string);
+ // Print wavy underline (GetUnderline is deprecated).
+ int start = message->GetStartColumn();
+ for (int i = 0; i < start; i++) {
+ printf(" ");
+ }
+ int end = message->GetEndColumn();
+ for (int i = start; i < end; i++) {
+ printf("^");
+ }
+ printf("\n");
+ v8::String::Utf8Value stack_trace(try_catch->StackTrace());
+ if (stack_trace.length() > 0) {
+ const char* stack_trace_string = V8Shell::ToCString(stack_trace);
+ printf("%s\n", stack_trace_string);
+ }
+ }
+}
+
+// Extracts a C string from a V8 Utf8Value.
+const char* V8Shell::ToCString(const v8::String::Utf8Value& value) {
+ return *value ? *value : "<string conversion failed>";
+}
+
+JSShell* V8Shell_Create() {
+ return new V8Shell();
+}
diff --git a/configure.ac b/configure.ac
index fbf74774a..091749f53 100644
--- a/configure.ac
+++ b/configure.ac
@@ -130,13 +130,13 @@ AC_CHECK_PROGS(YODL2HTML, yodl2html)
if test -n "$YODL2MAN"; then
AC_MSG_CHECKING([yodl2man version >= 2.02])
- yodl_version=`$YODL2MAN --version 2>&1 | grep 'yodl version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.*[0-9]*\).*/\1/g'`
+ [yodl_version=`$YODL2MAN --version 2>&1 | grep 'yodl version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.*[0-9]*\).*/\1/g'`]
AX_COMPARE_VERSION([$yodl_version],[ge],[2.02], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no - $yodl_version found])])
fi
if test -n "$YODL2HTML"; then
AC_MSG_CHECKING([yodl2html version >= 2.02])
- yodl_version=`$YODL2HTML --version 2>&1 | grep 'yodl version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`
+ [yodl_version=`$YODL2HTML --version 2>&1 | grep 'yodl version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`]
AX_COMPARE_VERSION([$yodl_version],[ge],[2.02], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no - $yodl_version found])])
fi
@@ -1088,6 +1088,231 @@ AC_SUBST(JAVACXXSHARED)
AC_SUBST(JAVACFLAGS)
#----------------------------------------------------------------
+# Look for Javascript
+#----------------------------------------------------------------
+AC_ARG_WITH(javascript, AS_HELP_STRING([--without-javascript], [Disable Javascript]), [with_javascript="$withval"], [with_javascript=yes])
+
+# First, check for "--without-javascript" or "--with-javascript=no".
+if test x"${with_javascript}" = xno -o x"${with_alllang}" = xno ; then
+ AC_MSG_NOTICE([Disabling Javascript])
+ JAVASCRIPT=
+else
+ JAVASCRIPT=1
+
+ #----------------------------------------------------------------
+ # General Javascript settings shared by JSC and V8
+ #----------------------------------------------------------------
+
+ case $host in
+ *-*-cygwin* | *-*-mingw*)
+ JSLIBRARYPREFIX=""
+ ;;
+ *)
+ JSLIBRARYPREFIX="lib"
+ ;;
+ esac
+
+ case $host in
+ *-*-darwin*)
+ JSSO=".dylib"
+ JSLDSHARED='$(CC) -dynamiclib'
+ JSCXXSHARED='$(CXX) -dynamiclib'
+ # HACK: didn't manage to get dynamic module loading working with a g++ compiled interpreter
+ JSINTERPRETERCXX='c++'
+ JSINTERPRETERLINKFLAGS='-g -Wl,-search_paths_first -Wl,-headerpad_max_install_names'
+ ;;
+ *)
+ JSSO=$SO
+ JSLDSHARED='$(LDSHARED)'
+ JSCXXSHARED='$(CXXSHARED)'
+ JSINTERPRETERCXX='$(CXX)'
+ JSINTERPRETERLINKFLAGS='-ldl'
+ ;;
+ esac
+
+ #----------------------------------------------------------------
+ # Look for Node.js which is the default Javascript engine
+ #----------------------------------------------------------------
+
+ AC_CHECK_PROGS(NODEJS, node)
+
+ if test -n "$NODEJS"; then
+ # node-gyp is needed to run the test-suite/examples
+ AC_CHECK_PROGS(NODEGYP, node-gyp)
+ if test -z "$NODEGYP"; then
+ NODEJS=
+ fi
+ fi
+
+ #----------------------------------------------------------------
+ # Look for JavascriptCore (Webkit) settings (JSCOREINCDIR, JSCOREDYNAMICLINKING)
+ #----------------------------------------------------------------
+
+ # check for include files
+ AC_MSG_CHECKING(for JavaScriptCore/JavaScript.h)
+ AC_ARG_WITH(jscoreinc, [ --with-jscinc=path Set location of Javascript include directory], [JSCOREINCDIR="$withval"], [JSCOREINCDIR=])
+
+ JSCOREVERSION=
+
+ if test -z "$JSCOREINCDIR"; then
+ JSCOREINCDIR="/usr/include/ /usr/local/include/"
+
+ # Add in default directory for JavaScriptCore headers for Linux and MacOSX
+ case $host in
+ *-*-linux*)
+ JSCOREINCDIR="/usr/include/webkit-1.0/ /usr/include/webkitgtk-1.0/ /usr/local/include/webkit-1.0/JavaScriptCore/ $JSCOREINCDIR"
+ ;;
+ *-*-darwin*)
+ JSCOREINCDIR="/System/Library/Frameworks/JavaScriptCore.framework/Headers/ $JSCOREINCDIR"
+ ;;
+ *)
+ ;;
+ esac
+ fi
+
+ for d in $JSCOREINCDIR ; do
+ if test -r "$d/JavaScriptCore/JavaScript.h" || test -r "$d/JavaScript.h" ; then
+ AC_MSG_RESULT($d)
+ JSCOREINCDIR=$d
+ JSCOREINC=-I\"$d\"
+ break
+ fi
+ done
+
+ if test "$JSCOREINC" = "" ; then
+ AC_MSG_RESULT(not found)
+ fi
+
+ # check for JavaScriptCore/Webkit libraries
+ AC_ARG_WITH(jscorelib,[ --with-jsclib =path Set location of the JavaScriptCore/Webkit library directory],[JSCORELIB="-L$withval"], [JSCORELIB=])
+ AC_MSG_CHECKING(for JavaScriptCore/Webkit library)
+
+ # look for the library when not provided
+ if test -z "$JSCORELIB"; then
+ case $host in
+ *-*-linux*)
+ dirs="/usr/lib/ /usr/local/lib/"
+ for i in $dirs ; do
+ if test -r $i/libjavascriptcoregtk-1.0.so; then
+ AC_MSG_RESULT($i)
+ JSCORELIB="-L$i -ljavascriptcoregtk-1.0"
+ JSCOREVERSION=`pkg-config --modversion javascriptcoregtk-1.0`
+ break
+ fi
+ done
+
+ if test -z "$JSCORELIB"; then
+ AC_MSG_RESULT(not found)
+ JSCENABLED=0
+ else
+ JSCOREDYNAMICLINKING="$JSCORELIB"
+ JSCENABLED=1
+ fi
+ ;;
+ *-*-darwin*)
+ JSCOREDYNAMICLINKING="-framework JavaScriptCore"
+ JSCENABLED=1
+ ;;
+ *)
+ ;;
+ esac
+ fi
+
+ #----------------------------------------------------------------
+ # Look for V8 settings (JSV8INCDIR, JSV8DYNAMICLINKING)
+ #----------------------------------------------------------------
+
+ # check for include files
+ AC_MSG_CHECKING(for V8 Javascript v8.h)
+ AC_ARG_WITH(jsv8inc, [ --with-v8inc=path Set location of Javascript v8 include directory], [JSV8INCDIR="$withval"])
+
+ # if not include dir is specified we try to find
+ if test -z "$JSV8INCDIR"; then
+ # Add in default directory for JavaScriptCore headers for Linux and MacOSX
+ case $host in
+ *-*-linux*)
+ JSV8INCDIR="/usr/include /usr/local/include/ $JSV8INCDIR"
+ ;;
+ *-*-darwin*)
+ JSV8INCDIR="$JSV8INCDIR"
+ ;;
+ *)
+ ;;
+ esac
+ fi
+
+ for d in $JSV8INCDIR ; do
+ if test -r "$d/v8.h" ; then
+ JSV8INCDIR=$d
+ JSV8INC=-I\"$d\"
+ break
+ fi
+ done
+
+ if test "$JSV8INC" = "" ; then
+ AC_MSG_RESULT(not found)
+ else
+ AC_MSG_RESULT($JSV8INCDIR)
+ fi
+
+ # check for V8 library
+ AC_MSG_CHECKING(for V8 Javascript library)
+ AC_ARG_WITH(jsv8lib,[ --with-v8lib=path Set location of V8 Javascript library directory],[JSV8LIBDIR="$withval"], [JSV8LIB=])
+
+ v8libdirs="$JSV8LIBDIR /usr/lib/ /usr/local/lib/"
+ for d in $v8libdirs ; do
+ if test -r $d/libv8.so; then
+ JSV8LIBDIR=$d
+ JSV8LIB="-L$d -lv8"
+ break
+ fi
+ done
+
+ if test "$JSV8LIB" = "" ; then
+ AC_MSG_RESULT(not found)
+ JSV8ENABLED=0
+ else
+ AC_MSG_RESULT($JSV8LIBDIR)
+ JSV8ENABLED=1
+ fi
+
+
+ # linking options
+ case $host in
+ *-*-darwin*)
+ JSV8DYNAMICLINKING="" # TODO: add osx configuration
+ ;;
+ *-*-linux*)
+ JSV8DYNAMICLINKING="$JSV8LIB"
+ ;;
+ *)
+ JSV8DYNAMICLINKING=""
+ ;;
+ esac
+
+fi
+
+AC_SUBST(JSLIBRARYPREFIX)
+AC_SUBST(JSSO)
+AC_SUBST(JSLDSHARED)
+AC_SUBST(JSCXXSHARED)
+
+AC_SUBST(JSINTERPRETERCXX)
+AC_SUBST(JSINTERPRETERLINKFLAGS)
+
+AC_SUBST(JSCOREINC)
+AC_SUBST(JSCOREDYNAMICLINKING)
+AC_SUBST(JSCOREVERSION)
+AC_SUBST(JSV8INC)
+AC_SUBST(JSV8DYNAMICLINKING)
+
+AC_SUBST(JSCENABLED)
+AC_SUBST(JSV8ENABLED)
+
+AC_SUBST(NODEJS)
+AC_SUBST(NODEGYP)
+
+#----------------------------------------------------------------
# Look for gcj
#----------------------------------------------------------------
@@ -2238,6 +2463,11 @@ if test -z "$JAVA" || test -z "$JAVAC" || test -z "$JAVAINC" ; then
fi
AC_SUBST(SKIP_JAVA)
+SKIP_JAVASCRIPT=
+if test -z "$JAVASCRIPT" || ( test -z "$NODEJS" && test -z "$JSCENABLED" && test -z "$JSV8ENABLED" ) ; then
+ SKIP_JAVASCRIPT="1"
+fi
+AC_SUBST(SKIP_JAVASCRIPT)
SKIP_GUILE=
if test -z "$GUILE" || test -z "$GUILE_LIBS" ; then
@@ -2412,7 +2642,6 @@ AC_DEFINE_UNQUOTED(SWIG_LIB_WIN_UNIX, ["$SWIG_LIB_WIN_UNIX"], [Directory for SWI
AC_CONFIG_FILES([
Makefile
swig.spec
- Source/Makefile
Examples/Makefile
Examples/xml/Makefile
Examples/test-suite/errors/Makefile
@@ -2421,6 +2650,7 @@ AC_CONFIG_FILES([
Examples/test-suite/d/Makefile
Examples/test-suite/guile/Makefile
Examples/test-suite/java/Makefile
+ Examples/test-suite/javascript/Makefile
Examples/test-suite/mzscheme/Makefile
Examples/test-suite/ocaml/Makefile
Examples/test-suite/octave/Makefile
@@ -2437,6 +2667,8 @@ AC_CONFIG_FILES([
Examples/test-suite/uffi/Makefile
Examples/test-suite/r/Makefile
Examples/test-suite/go/Makefile
+ Source/Makefile
+ Tools/javascript/Makefile
])
AC_CONFIG_FILES([preinst-swig], [chmod +x preinst-swig])
AC_CONFIG_FILES([CCache/ccache_swig_config.h])