summaryrefslogtreecommitdiff
path: root/Lib
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 /Lib
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
Diffstat (limited to 'Lib')
-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
59 files changed, 4702 insertions, 32 deletions
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