summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Buchtala <oliver.buchtala@googlemail.com>2013-09-27 02:46:11 +0200
committerOliver Buchtala <oliver.buchtala@googlemail.com>2013-09-27 03:25:28 +0200
commit48af60d82904f1eef37b9beac03f8412947e883e (patch)
treef971856d71e61616cabc45a0527374350b10e5ee
parentecf9f96079067386a5f8bc83fadd4ac9e03f551c (diff)
downloadswig-48af60d82904f1eef37b9beac03f8412947e883e.tar.gz
Javascript examples.
-rw-r--r--Examples/javascript/check.list13
-rwxr-xr-xExamples/javascript/class/Makefile21
-rw-r--r--Examples/javascript/class/binding.gyp8
-rwxr-xr-xExamples/javascript/class/example.cxx28
-rwxr-xr-xExamples/javascript/class/example.h34
-rwxr-xr-xExamples/javascript/class/example.i10
-rwxr-xr-xExamples/javascript/class/runme.js46
-rwxr-xr-xExamples/javascript/constant/Makefile21
-rw-r--r--Examples/javascript/constant/binding.gyp8
-rw-r--r--Examples/javascript/constant/example.h8
-rwxr-xr-xExamples/javascript/constant/example.i24
-rwxr-xr-xExamples/javascript/constant/runme.js14
-rwxr-xr-xExamples/javascript/enum/Makefile21
-rw-r--r--Examples/javascript/enum/binding.gyp8
-rwxr-xr-xExamples/javascript/enum/example.cxx37
-rwxr-xr-xExamples/javascript/enum/example.h13
-rwxr-xr-xExamples/javascript/enum/example.i11
-rwxr-xr-xExamples/javascript/enum/runme.js34
-rwxr-xr-xExamples/javascript/exception/Makefile21
-rw-r--r--Examples/javascript/exception/binding.gyp8
-rw-r--r--Examples/javascript/exception/example.cxx1
-rw-r--r--Examples/javascript/exception/example.h53
-rw-r--r--Examples/javascript/exception/example.i12
-rw-r--r--Examples/javascript/exception/runme.js64
-rwxr-xr-xExamples/javascript/functor/Makefile21
-rw-r--r--Examples/javascript/functor/binding.gyp8
-rw-r--r--Examples/javascript/functor/example.cxx0
-rw-r--r--Examples/javascript/functor/example.i25
-rw-r--r--Examples/javascript/functor/runme.js15
-rwxr-xr-xExamples/javascript/namespace/Makefile21
-rw-r--r--Examples/javascript/namespace/binding.gyp8
-rw-r--r--Examples/javascript/namespace/example.cxx36
-rw-r--r--Examples/javascript/namespace/example.h20
-rw-r--r--Examples/javascript/namespace/example.i10
-rw-r--r--Examples/javascript/namespace/runme.js10
-rwxr-xr-xExamples/javascript/operator/Makefile21
-rw-r--r--Examples/javascript/operator/binding.gyp8
-rw-r--r--Examples/javascript/operator/example.h36
-rw-r--r--Examples/javascript/operator/example.i34
-rw-r--r--Examples/javascript/operator/runme.js25
-rwxr-xr-xExamples/javascript/overload/Makefile21
-rw-r--r--Examples/javascript/overload/binding.gyp8
-rw-r--r--Examples/javascript/overload/example.h28
-rw-r--r--Examples/javascript/overload/example.i16
-rw-r--r--Examples/javascript/overload/runme.js9
-rw-r--r--Examples/javascript/overload/swig_gdb.log0
-rwxr-xr-xExamples/javascript/pointer/Makefile21
-rw-r--r--Examples/javascript/pointer/binding.gyp8
-rwxr-xr-xExamples/javascript/pointer/example.cxx16
-rwxr-xr-xExamples/javascript/pointer/example.i30
-rwxr-xr-xExamples/javascript/pointer/runme.js35
-rw-r--r--Examples/javascript/pointer/typemaps.i0
-rwxr-xr-xExamples/javascript/reference/Makefile21
-rw-r--r--Examples/javascript/reference/binding.gyp8
-rwxr-xr-xExamples/javascript/reference/example.cxx46
-rwxr-xr-xExamples/javascript/reference/example.h26
-rwxr-xr-xExamples/javascript/reference/example.i42
-rwxr-xr-xExamples/javascript/reference/runme.js67
-rw-r--r--Examples/javascript/reference/swig_gdb.log22
-rwxr-xr-xExamples/javascript/simple/Makefile21
-rw-r--r--Examples/javascript/simple/binding.gyp8
-rw-r--r--Examples/javascript/simple/example.cxx18
-rw-r--r--Examples/javascript/simple/example.i7
-rwxr-xr-xExamples/javascript/simple/runme.js26
-rwxr-xr-xExamples/javascript/template/Makefile21
-rw-r--r--Examples/javascript/template/binding.gyp8
-rw-r--r--Examples/javascript/template/example.h32
-rw-r--r--Examples/javascript/template/example.i17
-rw-r--r--Examples/javascript/template/runme.js30
-rwxr-xr-xExamples/javascript/variables/Makefile21
-rw-r--r--Examples/javascript/variables/binding.gyp8
-rwxr-xr-xExamples/javascript/variables/example.cxx96
-rwxr-xr-xExamples/javascript/variables/example.h6
-rwxr-xr-xExamples/javascript/variables/example.i49
-rwxr-xr-xExamples/javascript/variables/runme.js68
-rw-r--r--Examples/javascript/variables/swig_gdb.log9
76 files changed, 1685 insertions, 0 deletions
diff --git a/Examples/javascript/check.list b/Examples/javascript/check.list
new file mode 100644
index 000000000..146f1800f
--- /dev/null
+++ b/Examples/javascript/check.list
@@ -0,0 +1,13 @@
+class
+constant
+enum
+exception
+functor
+namespace
+operator
+overload
+pointer
+reference
+simple
+template
+variables
diff --git a/Examples/javascript/class/Makefile b/Examples/javascript/class/Makefile
new file mode 100755
index 000000000..99a9e9e86
--- /dev/null
+++ b/Examples/javascript/class/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+JS_SCRIPT = runme.js
+TARGET = example
+INTERFACE = example.i
+
+wrapper::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
+
+build:: wrapper
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile javascript_clean
+
+check:: build
+ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
+ TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run
diff --git a/Examples/javascript/class/binding.gyp b/Examples/javascript/class/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/class/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/class/example.cxx b/Examples/javascript/class/example.cxx
new file mode 100755
index 000000000..e23fa6f73
--- /dev/null
+++ b/Examples/javascript/class/example.cxx
@@ -0,0 +1,28 @@
+/* File : example.c */
+#include <iostream>
+#include "example.h"
+#define M_PI 3.14159265358979323846
+
+/* Move the shape to a new location */
+void Shape::move(double dx, double dy) {
+ x += dx;
+ y += dy;
+}
+
+int Shape::nshapes = 0;
+
+double Circle::area(void) {
+ return M_PI*radius*radius;
+}
+
+double Circle::perimeter(void) {
+ return 2*M_PI*radius;
+}
+
+double Square::area(void) {
+ return width*width;
+}
+
+double Square::perimeter(void) {
+ return 4*width;
+}
diff --git a/Examples/javascript/class/example.h b/Examples/javascript/class/example.h
new file mode 100755
index 000000000..64b7684fa
--- /dev/null
+++ b/Examples/javascript/class/example.h
@@ -0,0 +1,34 @@
+/* File : example.h */
+
+class Shape {
+public:
+ Shape() {
+ nshapes++;
+ }
+ virtual ~Shape() {
+ nshapes--;
+ };
+ double x, y;
+ void move(double dx, double dy);
+ virtual double area(void) = 0;
+ virtual double perimeter(void) = 0;
+ static int nshapes;
+};
+
+class Circle : public Shape {
+private:
+ double radius;
+public:
+ Circle(double r) : radius(r) { };
+ virtual double area(void);
+ virtual double perimeter(void);
+};
+
+class Square : public Shape {
+private:
+ double width;
+public:
+ Square(double w) : width(w) { };
+ virtual double area(void);
+ virtual double perimeter(void);
+};
diff --git a/Examples/javascript/class/example.i b/Examples/javascript/class/example.i
new file mode 100755
index 000000000..75700b305
--- /dev/null
+++ b/Examples/javascript/class/example.i
@@ -0,0 +1,10 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Let's just grab the original header file here */
+%include "example.h"
+
diff --git a/Examples/javascript/class/runme.js b/Examples/javascript/class/runme.js
new file mode 100755
index 000000000..5bb62ecd4
--- /dev/null
+++ b/Examples/javascript/class/runme.js
@@ -0,0 +1,46 @@
+var example = require("./build/Release/example");
+
+// ----- Object creation -----
+
+console.log("Creating some objects:");
+c = new example.Circle(10);
+console.log("Created circle " + c);
+s = new example.Square(10);
+console.log("Created square " + s);
+
+// ----- Access a static member -----
+console.log("\nA total of " + example.Shape.nshapes + " shapes were created"); // access static member as properties of the class object
+
+// ----- Member data access -----
+// Set the location of the object.
+// Note: methods in the base class Shape are used since
+// x and y are defined there.
+
+c.x = 20;
+c.y = 30;
+s.x = -10;
+s.y = 5;
+
+console.log("\nHere is their new position:");
+console.log("Circle = (" + c.x + "," + c.y + ")");
+console.log("Square = (" + s.x + "," + s.y + ")");
+
+// ----- Call some methods -----
+console.log("\nHere are some properties of the shapes:");
+console.log("Circle:");
+console.log("area = " + c.area() + "");
+console.log("perimeter = " + c.perimeter() + "");
+console.log("\n");
+console.log("Square:");
+console.log("area = " + s.area() + "");
+console.log("perimeter = " + s.perimeter() + "");
+
+// ----- Delete everything -----
+console.log("\nGuess I'll clean up now");
+// Note: this invokes the virtual destructor
+delete c;
+delete s;
+
+console.log(example.Shape.nshapes + " shapes remain");
+
+console.log("Goodbye");
diff --git a/Examples/javascript/constant/Makefile b/Examples/javascript/constant/Makefile
new file mode 100755
index 000000000..99a9e9e86
--- /dev/null
+++ b/Examples/javascript/constant/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+JS_SCRIPT = runme.js
+TARGET = example
+INTERFACE = example.i
+
+wrapper::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
+
+build:: wrapper
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile javascript_clean
+
+check:: build
+ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
+ TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run
diff --git a/Examples/javascript/constant/binding.gyp b/Examples/javascript/constant/binding.gyp
new file mode 100644
index 000000000..69af46b22
--- /dev/null
+++ b/Examples/javascript/constant/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/constant/example.h b/Examples/javascript/constant/example.h
new file mode 100644
index 000000000..2c88ebd1e
--- /dev/null
+++ b/Examples/javascript/constant/example.h
@@ -0,0 +1,8 @@
+#define ICONST 42
+#define FCONST 2.1828
+#define CCONST 'x'
+#define CCONST2 '\n'
+#define SCONST "Hello World"
+#define SCONST2 "\"Hello World\""
+#define EXTERN extern
+#define FOO (ICONST + BAR)
diff --git a/Examples/javascript/constant/example.i b/Examples/javascript/constant/example.i
new file mode 100755
index 000000000..a6d28e7c9
--- /dev/null
+++ b/Examples/javascript/constant/example.i
@@ -0,0 +1,24 @@
+/* File : example.i */
+%module example
+
+/* A few preprocessor macros */
+
+#define ICONST 42
+#define FCONST 2.1828
+#define CCONST 'x'
+#define CCONST2 '\n'
+#define SCONST "Hello World"
+#define SCONST2 "\"Hello World\""
+
+/* This should work just fine */
+#define EXPR ICONST + 3*(FCONST)
+
+/* This shouldn't do anything */
+#define EXTERN extern
+
+/* Neither should this (BAR isn't defined) */
+#define FOO (ICONST + BAR)
+
+/* The following directives also produce constants */
+%constant int iconst = 37;
+%constant double fconst = 3.14;
diff --git a/Examples/javascript/constant/runme.js b/Examples/javascript/constant/runme.js
new file mode 100755
index 000000000..b11c08c98
--- /dev/null
+++ b/Examples/javascript/constant/runme.js
@@ -0,0 +1,14 @@
+var example = require("./build/Release/example");
+
+console.log("ICONST = " + example.ICONST + " (should be 42)\n");
+console.log("FCONST = " + example.FCONST + " (should be 2.1828)\n");
+console.log("CCONST = " + example.CCONST + " (should be 'x')\n");
+console.log("CCONST2 = " + example.CCONST2 + " (this should be on a new line)\n");
+console.log("SCONST = " + example.SCONST + " (should be 'Hello World')\n");
+console.log("SCONST2 = " + example.SCONST2 + " (should be '\"Hello World\"')\n");
+console.log("EXPR = " + example.EXPR + " (should be 48.5484)\n");
+console.log("iconst = " + example.iconst + " (should be 37)\n");
+console.log("fconst = " + example.fconst + " (should be 3.14)\n");
+
+console.log("EXTERN = " + example.EXTERN + " (should be undefined)\n");
+console.log("FOO = " + example.FOO + " (should be undefined)\n");
diff --git a/Examples/javascript/enum/Makefile b/Examples/javascript/enum/Makefile
new file mode 100755
index 000000000..99a9e9e86
--- /dev/null
+++ b/Examples/javascript/enum/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+JS_SCRIPT = runme.js
+TARGET = example
+INTERFACE = example.i
+
+wrapper::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
+
+build:: wrapper
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile javascript_clean
+
+check:: build
+ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
+ TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run
diff --git a/Examples/javascript/enum/binding.gyp b/Examples/javascript/enum/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/enum/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/enum/example.cxx b/Examples/javascript/enum/example.cxx
new file mode 100755
index 000000000..6785e57ac
--- /dev/null
+++ b/Examples/javascript/enum/example.cxx
@@ -0,0 +1,37 @@
+/* File : example.c */
+
+#include "example.h"
+#include <stdio.h>
+
+void Foo::enum_test(speed s) {
+ if (s == IMPULSE) {
+ printf("IMPULSE speed\n");
+ } else if (s == WARP) {
+ printf("WARP speed\n");
+ } else if (s == LUDICROUS) {
+ printf("LUDICROUS speed\n");
+ } else {
+ printf("Unknown speed\n");
+ }
+}
+
+void enum_test(color c, Foo::speed s) {
+ if (c == RED) {
+ printf("color = RED, ");
+ } else if (c == BLUE) {
+ printf("color = BLUE, ");
+ } else if (c == GREEN) {
+ printf("color = GREEN, ");
+ } else {
+ printf("color = Unknown color!, ");
+ }
+ if (s == Foo::IMPULSE) {
+ printf("speed = IMPULSE speed\n");
+ } else if (s == Foo::WARP) {
+ printf("speed = WARP speed\n");
+ } else if (s == Foo::LUDICROUS) {
+ printf("speed = LUDICROUS speed\n");
+ } else {
+ printf("speed = Unknown speed!\n");
+ }
+}
diff --git a/Examples/javascript/enum/example.h b/Examples/javascript/enum/example.h
new file mode 100755
index 000000000..9119cd9fc
--- /dev/null
+++ b/Examples/javascript/enum/example.h
@@ -0,0 +1,13 @@
+/* File : example.h */
+
+enum color { RED, BLUE, GREEN };
+
+class Foo {
+ public:
+ Foo() { }
+ enum speed { IMPULSE=10, WARP=20, LUDICROUS=30 };
+ void enum_test(speed s);
+};
+
+void enum_test(color c, Foo::speed s);
+
diff --git a/Examples/javascript/enum/example.i b/Examples/javascript/enum/example.i
new file mode 100755
index 000000000..23ee8a822
--- /dev/null
+++ b/Examples/javascript/enum/example.i
@@ -0,0 +1,11 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Let's just grab the original header file here */
+
+%include "example.h"
+
diff --git a/Examples/javascript/enum/runme.js b/Examples/javascript/enum/runme.js
new file mode 100755
index 000000000..9d3accd1d
--- /dev/null
+++ b/Examples/javascript/enum/runme.js
@@ -0,0 +1,34 @@
+var example = require("./build/Release/example");
+
+// ----- Object creation -----
+
+// Print out the value of some enums
+console.log("*** color ***");
+console.log(" RED =" + example.RED);
+console.log(" BLUE =" + example.BLUE);
+console.log(" GREEN =" + example.GREEN);
+
+console.log("\n*** Foo::speed ***");
+console.log(" Foo_IMPULSE =" + example.Foo.IMPULSE);
+console.log(" Foo_WARP =" + example.Foo.WARP);
+console.log(" Foo_LUDICROUS =" + example.Foo.LUDICROUS);
+
+console.log("\nTesting use of enums with functions\n");
+
+example.enum_test(example.RED, example.Foo.IMPULSE);
+example.enum_test(example.BLUE, example.Foo.WARP);
+example.enum_test(example.GREEN, example.Foo.LUDICROUS);
+example.enum_test(1234,5678);
+
+console.log("\nTesting use of enum with class method");
+f = new example.Foo();
+
+f.enum_test(example.Foo.IMPULSE);
+f.enum_test(example.Foo.WARP);
+f.enum_test(example.Foo.LUDICROUS);
+
+// enum value BLUE of enum color is accessed as property of cconst
+console.log("example.BLUE= " + example.BLUE);
+
+// enum value LUDICROUS of enum Foo::speed is accessed as as property of cconst
+console.log("example.speed.LUDICROUS= " + example.Foo.LUDICROUS);
diff --git a/Examples/javascript/exception/Makefile b/Examples/javascript/exception/Makefile
new file mode 100755
index 000000000..99a9e9e86
--- /dev/null
+++ b/Examples/javascript/exception/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+JS_SCRIPT = runme.js
+TARGET = example
+INTERFACE = example.i
+
+wrapper::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
+
+build:: wrapper
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile javascript_clean
+
+check:: build
+ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
+ TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run
diff --git a/Examples/javascript/exception/binding.gyp b/Examples/javascript/exception/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/exception/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/exception/example.cxx b/Examples/javascript/exception/example.cxx
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/Examples/javascript/exception/example.cxx
@@ -0,0 +1 @@
+
diff --git a/Examples/javascript/exception/example.h b/Examples/javascript/exception/example.h
new file mode 100644
index 000000000..7cf917d01
--- /dev/null
+++ b/Examples/javascript/exception/example.h
@@ -0,0 +1,53 @@
+/* File : example.h */
+
+#include <string.h>
+#ifndef SWIG
+struct A {
+};
+#endif
+
+class Exc {
+public:
+ Exc(int c, const char *m) {
+ code = c;
+ strncpy(msg,m,256);
+ }
+ int code;
+ char msg[256];
+};
+
+#if defined(_MSC_VER)
+ #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
+#endif
+
+class Test {
+public:
+ int simple() throw(int) {
+ throw(37);
+ return 1;
+ }
+ int message() throw(const char *) {
+ throw("I died.");
+ return 1;
+ }
+ int hosed() throw(Exc) {
+ throw(Exc(42,"Hosed"));
+ return 1;
+ }
+ int unknown() throw(A*) {
+ static A a;
+ throw &a;
+ return 1;
+ }
+ int multi(int x) throw(int, const char *, Exc) {
+ if (x == 1) throw(37);
+ if (x == 2) throw("Bleah!");
+ if (x == 3) throw(Exc(42,"No-go-diggy-die"));
+ return 1;
+ }
+};
+
+#if defined(_MSC_VER)
+ #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
+#endif
+
diff --git a/Examples/javascript/exception/example.i b/Examples/javascript/exception/example.i
new file mode 100644
index 000000000..08672c3a8
--- /dev/null
+++ b/Examples/javascript/exception/example.i
@@ -0,0 +1,12 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+%include "std_string.i"
+
+/* Let's just grab the original header file here */
+%include "example.h"
+
diff --git a/Examples/javascript/exception/runme.js b/Examples/javascript/exception/runme.js
new file mode 100644
index 000000000..f7041f028
--- /dev/null
+++ b/Examples/javascript/exception/runme.js
@@ -0,0 +1,64 @@
+var example = require("./build/Release/example");
+
+console.log("Trying to catch some exceptions.");
+t = new example.Test();
+try{
+ t.unknown();
+ throw -1;
+} catch(error)
+{
+ if(error == -1) {
+ console.log("t.unknown() didn't throw");
+ } else {
+ console.log("successfully catched throw in Test::unknown().");
+ }
+}
+
+try{
+ t.simple();
+ throw -1;
+}
+catch(error){
+ if(error == -1) {
+ console.log("t.simple() did not throw");
+ } else {
+ console.log("successfully catched throw in Test::simple().");
+ }
+}
+
+try{
+ t.message();
+ throw -1;
+} catch(error){
+ if(error == -1) {
+ console.log("t.message() did not throw");
+ } else {
+ console.log("successfully catched throw in Test::message().");
+ }
+}
+
+try{
+ t.hosed();
+ throw -1;
+}
+catch(error){
+ if(error == -1) {
+ console.log("t.hosed() did not throw");
+ } else {
+ console.log("successfully catched throw in Test::hosed().");
+ }
+}
+
+for (var i=1; i<4; i++) {
+ try{
+ t.multi(i);
+ throw -1;
+ }
+ catch(error){
+ if(error == -1) {
+ console.log("t.multi(" + i + ") did not throw");
+ } else {
+ console.log("successfully catched throw in Test::multi().");
+ }
+ }
+}
diff --git a/Examples/javascript/functor/Makefile b/Examples/javascript/functor/Makefile
new file mode 100755
index 000000000..99a9e9e86
--- /dev/null
+++ b/Examples/javascript/functor/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+JS_SCRIPT = runme.js
+TARGET = example
+INTERFACE = example.i
+
+wrapper::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
+
+build:: wrapper
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile javascript_clean
+
+check:: build
+ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
+ TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run
diff --git a/Examples/javascript/functor/binding.gyp b/Examples/javascript/functor/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/functor/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/functor/example.cxx b/Examples/javascript/functor/example.cxx
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/Examples/javascript/functor/example.cxx
diff --git a/Examples/javascript/functor/example.i b/Examples/javascript/functor/example.i
new file mode 100644
index 000000000..0450c2124
--- /dev/null
+++ b/Examples/javascript/functor/example.i
@@ -0,0 +1,25 @@
+/* File : example.i */
+%module example
+
+
+%inline %{
+// From B. Strousjoup, "The C++ Programming Language, Third Edition", p. 514
+template<class T> class Sum {
+ T res;
+public:
+ Sum(T i = 0) : res(i) { }
+ void operator() (T x) { res += x; }
+ T result() const { return res; }
+};
+
+%}
+
+%rename(call) *::operator(); // the fn call operator
+
+// Instantiate a few versions
+%template(intSum) Sum<int>;
+%template(doubleSum) Sum<double>;
+
+
+
+
diff --git a/Examples/javascript/functor/runme.js b/Examples/javascript/functor/runme.js
new file mode 100644
index 000000000..f7be78286
--- /dev/null
+++ b/Examples/javascript/functor/runme.js
@@ -0,0 +1,15 @@
+var example = require("./build/Release/example");
+
+a = new example.intSum(0);
+b = new example.doubleSum(100.0);
+
+// Use the objects. They should be callable just like a normal
+// javascript function.
+
+for (i=1;i<=100;i++)
+ a.call(i); // Note: function call
+ b.call(Math.sqrt(i)); // Note: function call
+
+console.log(a.result());
+console.log(b.result());
+
diff --git a/Examples/javascript/namespace/Makefile b/Examples/javascript/namespace/Makefile
new file mode 100755
index 000000000..99a9e9e86
--- /dev/null
+++ b/Examples/javascript/namespace/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+JS_SCRIPT = runme.js
+TARGET = example
+INTERFACE = example.i
+
+wrapper::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
+
+build:: wrapper
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile javascript_clean
+
+check:: build
+ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
+ TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run
diff --git a/Examples/javascript/namespace/binding.gyp b/Examples/javascript/namespace/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/namespace/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/namespace/example.cxx b/Examples/javascript/namespace/example.cxx
new file mode 100644
index 000000000..5beeb09fe
--- /dev/null
+++ b/Examples/javascript/namespace/example.cxx
@@ -0,0 +1,36 @@
+/* File : example.c */
+
+#include <iostream>
+#include "example.h"
+
+#define M_PI 3.14159
+
+
+/* A global variable */
+namespace nspace
+{
+double Foo = 3.0;
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x > 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+
+Circle::Circle(): radius(1.0) {}
+
+Circle::Circle(double r): radius(r) {
+ std::cout << "created Circle with r=" << radius << std::endl;
+}
+
+double Circle::area() {
+ std::cout << "Circle::area called, r=" << radius << std::endl;
+ return M_PI*radius*radius;
+}
+}
diff --git a/Examples/javascript/namespace/example.h b/Examples/javascript/namespace/example.h
new file mode 100644
index 000000000..7f76c2f07
--- /dev/null
+++ b/Examples/javascript/namespace/example.h
@@ -0,0 +1,20 @@
+
+namespace nspace {
+
+extern int gcd(int x, int y);
+extern double Foo;
+
+class Circle
+{
+public:
+ Circle();
+
+ Circle(double r);
+
+ double area();
+
+ double radius;
+
+};
+
+}
diff --git a/Examples/javascript/namespace/example.i b/Examples/javascript/namespace/example.i
new file mode 100644
index 000000000..e14b10b44
--- /dev/null
+++ b/Examples/javascript/namespace/example.i
@@ -0,0 +1,10 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+%feature("nspace", 1);
+
+%include "example.h"
diff --git a/Examples/javascript/namespace/runme.js b/Examples/javascript/namespace/runme.js
new file mode 100644
index 000000000..9a9d6744d
--- /dev/null
+++ b/Examples/javascript/namespace/runme.js
@@ -0,0 +1,10 @@
+var example = require("./build/Release/example");
+
+console.log("Global variable Foo=" + example.nspace.Foo);
+example.nspace.Foo = 5;
+console.log("Variable Foo changed to " + example.nspace.Foo);
+console.log("GCD of number 6,18 is " + example.nspace.gcd(6,18));
+
+console.log("Creating some objects:");
+c = new example.nspace.Circle(10);
+console.log("area = " + c.area());
diff --git a/Examples/javascript/operator/Makefile b/Examples/javascript/operator/Makefile
new file mode 100755
index 000000000..99a9e9e86
--- /dev/null
+++ b/Examples/javascript/operator/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+JS_SCRIPT = runme.js
+TARGET = example
+INTERFACE = example.i
+
+wrapper::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
+
+build:: wrapper
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile javascript_clean
+
+check:: build
+ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
+ TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run
diff --git a/Examples/javascript/operator/binding.gyp b/Examples/javascript/operator/binding.gyp
new file mode 100644
index 000000000..69af46b22
--- /dev/null
+++ b/Examples/javascript/operator/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/operator/example.h b/Examples/javascript/operator/example.h
new file mode 100644
index 000000000..4da6a2307
--- /dev/null
+++ b/Examples/javascript/operator/example.h
@@ -0,0 +1,36 @@
+/* File : example.h */
+#include <math.h>
+
+class Complex {
+private:
+ double rpart, ipart;
+public:
+ Complex(double r = 0, double i = 0) : rpart(r), ipart(i) { }
+ Complex(const Complex &c) : rpart(c.rpart), ipart(c.ipart) { }
+ Complex &operator=(const Complex &c) {
+ rpart = c.rpart;
+ ipart = c.ipart;
+ return *this;
+ }
+ Complex operator+(const Complex &c) const {
+ return Complex(rpart+c.rpart, ipart+c.ipart);
+ }
+ Complex operator-(const Complex &c) const {
+ return Complex(rpart-c.rpart, ipart-c.ipart);
+ }
+ Complex operator*(const Complex &c) const {
+ return Complex(rpart*c.rpart - ipart*c.ipart,
+ rpart*c.ipart + c.rpart*ipart);
+ }
+ Complex operator-() const {
+ return Complex(-rpart, -ipart);
+ }
+
+ double re() const { return rpart; }
+ double im() const { return ipart; }
+};
+
+
+
+
+
diff --git a/Examples/javascript/operator/example.i b/Examples/javascript/operator/example.i
new file mode 100644
index 000000000..7a1bd45e1
--- /dev/null
+++ b/Examples/javascript/operator/example.i
@@ -0,0 +1,34 @@
+/* File : example.i */
+%module example
+#pragma SWIG nowarn=SWIGWARN_IGNORE_OPERATOR_EQ
+%{
+#include "example.h"
+%}
+
+/* This header file is a little tough to handle because it has overloaded
+ operators and constructors. We're going to try and deal with that here */
+
+/* This turns the copy constructor in a function ComplexCopy() that can
+ be called */
+
+%rename(assign) Complex::operator=;
+%rename(plus) Complex::operator+;
+%rename(minus) Complex::operator-(const Complex &) const;
+%rename(uminus) Complex::operator-() const;
+%rename(times) Complex::operator*;
+
+/* Now grab the original header file */
+%include "example.h"
+
+/* An output method that turns a complex into a short string */
+%extend Complex {
+ char *toString() {
+ static char temp[512];
+ sprintf(temp,"(%g,%g)", $self->re(), $self->im());
+ return temp;
+ }
+ static Complex* copy(const Complex& c) {
+ return new Complex(c);
+ }
+};
+
diff --git a/Examples/javascript/operator/runme.js b/Examples/javascript/operator/runme.js
new file mode 100644
index 000000000..9dba4b7f9
--- /dev/null
+++ b/Examples/javascript/operator/runme.js
@@ -0,0 +1,25 @@
+var example = require("./build/Release/example");
+
+a = new example.Complex(2,3);
+b = new example.Complex(-5,10);
+
+console.log ("a =" + a);
+console.log ("b =" + b);
+
+c = a.plus(b);
+
+console.log("c =" + c);
+console.log("a*b =" + a.times(b));
+console.log("a-c =" + a.minus(c));
+
+e = example.Complex.copy(a.minus(c));
+console.log("e =" + e);
+
+// Big expression
+f = a.plus(b).times(c.plus(b.times(e))).plus(a.uminus());
+console.log("f =" + f);
+
+
+
+
+
diff --git a/Examples/javascript/overload/Makefile b/Examples/javascript/overload/Makefile
new file mode 100755
index 000000000..99a9e9e86
--- /dev/null
+++ b/Examples/javascript/overload/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+JS_SCRIPT = runme.js
+TARGET = example
+INTERFACE = example.i
+
+wrapper::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
+
+build:: wrapper
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile javascript_clean
+
+check:: build
+ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
+ TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run
diff --git a/Examples/javascript/overload/binding.gyp b/Examples/javascript/overload/binding.gyp
new file mode 100644
index 000000000..69af46b22
--- /dev/null
+++ b/Examples/javascript/overload/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/overload/example.h b/Examples/javascript/overload/example.h
new file mode 100644
index 000000000..2f112f1e1
--- /dev/null
+++ b/Examples/javascript/overload/example.h
@@ -0,0 +1,28 @@
+#include <iostream>
+
+void f() {
+ std::cout << "Called f()." << std::endl;
+}
+
+void f(int val) {
+ std::cout << "Called f(int)." << std::endl;
+}
+void f(int val1, int val2) {
+ std::cout << "Called f(int, int)." << std::endl;
+}
+
+void f(const char* s) {
+ std::cout << "Called f(const char*)." << std::endl;
+}
+
+void f(bool val) {
+ std::cout << "Called f(bool)." << std::endl;
+}
+
+void f(long val) {
+ std::cout << "Called f(long)." << std::endl;
+}
+
+void f(double val) {
+ std::cout << "Called f(double)." << std::endl;
+}
diff --git a/Examples/javascript/overload/example.i b/Examples/javascript/overload/example.i
new file mode 100644
index 000000000..b86689f8a
--- /dev/null
+++ b/Examples/javascript/overload/example.i
@@ -0,0 +1,16 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/*
+ Note: overloading is implemented in a sloppy way currently
+ i.e., only the number of arguments is taken into conideration
+ for dispatching.
+ To solve the problem one has to rename such conflicting methods.
+*/
+%rename(f_double) f(double val);
+
+%include "example.h"
diff --git a/Examples/javascript/overload/runme.js b/Examples/javascript/overload/runme.js
new file mode 100644
index 000000000..5ff5d01be
--- /dev/null
+++ b/Examples/javascript/overload/runme.js
@@ -0,0 +1,9 @@
+var example = require("./build/Release/example");
+
+example.f();
+example.f(1);
+example.f(1, 2);
+example.f("bla");
+example.f(false);
+example.f(11111111111);
+example.f_double(1.0);
diff --git a/Examples/javascript/overload/swig_gdb.log b/Examples/javascript/overload/swig_gdb.log
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/Examples/javascript/overload/swig_gdb.log
diff --git a/Examples/javascript/pointer/Makefile b/Examples/javascript/pointer/Makefile
new file mode 100755
index 000000000..99a9e9e86
--- /dev/null
+++ b/Examples/javascript/pointer/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+JS_SCRIPT = runme.js
+TARGET = example
+INTERFACE = example.i
+
+wrapper::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
+
+build:: wrapper
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile javascript_clean
+
+check:: build
+ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
+ TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run
diff --git a/Examples/javascript/pointer/binding.gyp b/Examples/javascript/pointer/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/pointer/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/pointer/example.cxx b/Examples/javascript/pointer/example.cxx
new file mode 100755
index 000000000..8762329fe
--- /dev/null
+++ b/Examples/javascript/pointer/example.cxx
@@ -0,0 +1,16 @@
+/* File : example.c */
+
+void add(int *x, int *y, int *result) {
+ *result = *x + *y;
+}
+
+void subtract(int *x, int *y, int *result) {
+ *result = *x - *y;
+}
+
+int divide(int n, int d, int *r) {
+ int q;
+ q = n/d;
+ *r = n - q*d;
+ return q;
+}
diff --git a/Examples/javascript/pointer/example.i b/Examples/javascript/pointer/example.i
new file mode 100755
index 000000000..38c67d7d2
--- /dev/null
+++ b/Examples/javascript/pointer/example.i
@@ -0,0 +1,30 @@
+/* File : example.i */
+%module example
+
+%{
+extern void add(int *, int *, int *);
+extern void subtract(int *, int *, int *);
+extern int divide(int, int, int *);
+%}
+
+/* This example illustrates a couple of different techniques
+ for manipulating C pointers */
+
+/* First we'll use the pointer library */
+extern void add(int *x, int *y, int *result);
+%include cpointer.i
+%pointer_functions(int, intp);
+
+/* Next we'll use some typemaps */
+
+%include typemaps.i
+extern void subtract(int *INPUT, int *INPUT, int *OUTPUT);
+
+/* Next we'll use typemaps and the %apply directive */
+
+%apply int *OUTPUT { int *r };
+extern int divide(int n, int d, int *r);
+
+
+
+
diff --git a/Examples/javascript/pointer/runme.js b/Examples/javascript/pointer/runme.js
new file mode 100755
index 000000000..00778dfbc
--- /dev/null
+++ b/Examples/javascript/pointer/runme.js
@@ -0,0 +1,35 @@
+var example = require("./build/Release/example");
+
+// First create some objects using the pointer library.
+console.log("Testing the pointer library\n");
+a = example.new_intp();
+b = example.new_intp();
+c = example.new_intp();
+
+example.intp_assign(a,37);
+example.intp_assign(b,42);
+
+console.log(" a = " + example.intp_value(a) + "\n");
+console.log(" b = " + example.intp_value(b) + "\n");
+console.log(" c = " + example.intp_value(c) + "\n");
+
+//// Call the add() function with some pointers
+example.add(a, b, c);
+
+//
+//// Now get the result
+r = example.intp_value(c);
+console.log(" 37 + 42 = " + r + "\n");
+
+// Clean up the pointers
+example.delete_intp(a);
+example.delete_intp(b);
+example.delete_intp(c);
+
+//// Now try the typemap library
+//// This should be much easier. Now how it is no longer
+//// necessary to manufacture pointers.
+//"OUTPUT" Mapping is not supported
+//console.log("Trying the typemap library");
+//r = example.subtract(37,42);
+//console.log("37 - 42 =" + r);
diff --git a/Examples/javascript/pointer/typemaps.i b/Examples/javascript/pointer/typemaps.i
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/Examples/javascript/pointer/typemaps.i
diff --git a/Examples/javascript/reference/Makefile b/Examples/javascript/reference/Makefile
new file mode 100755
index 000000000..99a9e9e86
--- /dev/null
+++ b/Examples/javascript/reference/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+JS_SCRIPT = runme.js
+TARGET = example
+INTERFACE = example.i
+
+wrapper::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
+
+build:: wrapper
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile javascript_clean
+
+check:: build
+ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
+ TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run
diff --git a/Examples/javascript/reference/binding.gyp b/Examples/javascript/reference/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/reference/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/reference/example.cxx b/Examples/javascript/reference/example.cxx
new file mode 100755
index 000000000..8a513bf49
--- /dev/null
+++ b/Examples/javascript/reference/example.cxx
@@ -0,0 +1,46 @@
+/* File : example.cxx */
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+#include "example.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+Vector operator+(const Vector &a, const Vector &b) {
+ Vector r;
+ r.x = a.x + b.x;
+ r.y = a.y + b.y;
+ r.z = a.z + b.z;
+ return r;
+}
+
+char *Vector::print() {
+ static char temp[512];
+ sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z);
+ return temp;
+}
+
+VectorArray::VectorArray(int size) {
+ items = new Vector[size];
+ maxsize = size;
+}
+
+VectorArray::~VectorArray() {
+ delete [] items;
+}
+
+Vector &VectorArray::operator[](int index) {
+ if ((index < 0) || (index >= maxsize)) {
+ printf("Panic! Array index out of bounds.\n");
+ exit(1);
+ }
+ return items[index];
+}
+
+int VectorArray::size() {
+ return maxsize;
+}
+
diff --git a/Examples/javascript/reference/example.h b/Examples/javascript/reference/example.h
new file mode 100755
index 000000000..4915adb1b
--- /dev/null
+++ b/Examples/javascript/reference/example.h
@@ -0,0 +1,26 @@
+/* File : example.h */
+
+class Vector {
+private:
+ double x,y,z;
+public:
+ Vector() : x(0), y(0), z(0) { };
+ Vector(double x, double y, double z) : x(x), y(y), z(z) { };
+ friend Vector operator+(const Vector &a, const Vector &b);
+ char *print();
+};
+
+class VectorArray {
+private:
+ Vector *items;
+ int maxsize;
+public:
+ VectorArray(int maxsize);
+ ~VectorArray();
+ Vector &operator[](int);
+ int size();
+};
+
+
+
+
diff --git a/Examples/javascript/reference/example.i b/Examples/javascript/reference/example.i
new file mode 100755
index 000000000..1cf19c82c
--- /dev/null
+++ b/Examples/javascript/reference/example.i
@@ -0,0 +1,42 @@
+/* File : example.i */
+
+/* This file has a few "typical" uses of C++ references. */
+
+%module example
+
+%{
+#include "example.h"
+%}
+
+class Vector {
+public:
+ Vector(double x, double y, double z);
+ ~Vector();
+ char *print();
+};
+
+/* This helper function calls an overloaded operator */
+%inline %{
+Vector addv(Vector &a, Vector &b) {
+ return a+b;
+}
+%}
+
+/* Wrapper around an array of vectors class */
+
+class VectorArray {
+public:
+ VectorArray(int maxsize);
+ ~VectorArray();
+ int size();
+
+ /* This wrapper provides an alternative to the [] operator */
+ %extend {
+ Vector &get(int index) {
+ return (*$self)[index];
+ }
+ void set(int index, Vector &a) {
+ (*$self)[index] = a;
+ }
+ }
+};
diff --git a/Examples/javascript/reference/runme.js b/Examples/javascript/reference/runme.js
new file mode 100755
index 000000000..ee5737076
--- /dev/null
+++ b/Examples/javascript/reference/runme.js
@@ -0,0 +1,67 @@
+// This file illustrates the manipulation of C++ references in Javascript.
+var example = require("./build/Release/example");
+
+// ----- Object creation -----
+
+console.log("Creating some objects:\n");
+a = new example.Vector(3,4,5);
+b = new example.Vector(10,11,12);
+
+console.log(" created" + a.print());
+console.log(" created" + b.print());
+
+// ----- Call an overloaded operator -----
+
+// This calls the wrapper we placed around operator+(const Vector &a, const Vector &)
+// It returns a new allocated object.
+
+console.log("Adding a+b\n");
+c = example.addv(a, b);
+console.log("a+b = " + c.print());
+
+
+// TODO: Note: Unless we free the result, a memory leak will occur
+//delete_Vector(c);
+
+// ----- Create a vector array -----
+
+// Note: Using the high-level interface here
+console.log("Creating an array of vectors\n");
+va = new example.VectorArray(10);
+console.log("va = " + va + "\n");
+
+// ----- Set some values in the array -----
+
+// These operators copy the value of a and b to the vector array
+va.set(0,a);
+va.set(1,b);
+
+// This will work, but it will cause a memory leak!
+va.set(2,example.addv(a,b));
+
+// The non-leaky way to do it
+//c = addv(a,b);
+//va.set(3,c);
+//delete_Vector(c);
+
+// Get some values from the array
+
+console.log("Getting some array values\n");
+for (i = 0; i < 5; i++) {
+ temp = va.get(i);
+ console.log(i,temp.print());
+}
+
+// Watch under resource meter to check on this
+console.log("Making sure we don't leak memory.\n");
+for (i = 0; i < 1000000; i++) {
+ c = va.get(i % 10);
+}
+//---------TODO---------
+//----- Clean up -----
+//console.log("Cleaning up\n");
+
+//example.delete_VectorArray(va);
+//example.delete_Vector(a);
+//example.delete_Vector(b);
+
diff --git a/Examples/javascript/reference/swig_gdb.log b/Examples/javascript/reference/swig_gdb.log
new file mode 100644
index 000000000..57bca0306
--- /dev/null
+++ b/Examples/javascript/reference/swig_gdb.log
@@ -0,0 +1,22 @@
+Loaded swig printers
+SwigStringPrinter: Could not convert const char* to string
+SwigListIterator: Construction failed.
+ Cannot access memory at address 0x7d894828ec834853.
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not convert const char* to string
+SwigListIterator: Construction failed.
+ Cannot access memory at address 0x7d894828ec834853.
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not dereference struct String*
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not dereference struct String*
+SwigStringPrinter: Could not dereference struct String*
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not dereference struct String*
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not dereference struct String*
+SwigStringPrinter: Could not dereference struct String*
diff --git a/Examples/javascript/simple/Makefile b/Examples/javascript/simple/Makefile
new file mode 100755
index 000000000..99a9e9e86
--- /dev/null
+++ b/Examples/javascript/simple/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+JS_SCRIPT = runme.js
+TARGET = example
+INTERFACE = example.i
+
+wrapper::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
+
+build:: wrapper
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile javascript_clean
+
+check:: build
+ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
+ TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run
diff --git a/Examples/javascript/simple/binding.gyp b/Examples/javascript/simple/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/simple/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/simple/example.cxx b/Examples/javascript/simple/example.cxx
new file mode 100644
index 000000000..1c2af789c
--- /dev/null
+++ b/Examples/javascript/simple/example.cxx
@@ -0,0 +1,18 @@
+/* File : example.c */
+
+/* A global variable */
+double Foo = 3.0;
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x > 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+
+
diff --git a/Examples/javascript/simple/example.i b/Examples/javascript/simple/example.i
new file mode 100644
index 000000000..24093b9bf
--- /dev/null
+++ b/Examples/javascript/simple/example.i
@@ -0,0 +1,7 @@
+/* File : example.i */
+%module example
+
+%inline %{
+extern int gcd(int x, int y);
+extern double Foo;
+%}
diff --git a/Examples/javascript/simple/runme.js b/Examples/javascript/simple/runme.js
new file mode 100755
index 000000000..d970dcb7c
--- /dev/null
+++ b/Examples/javascript/simple/runme.js
@@ -0,0 +1,26 @@
+var example = require("./build/Release/example");
+
+/* Call our gcd() function */
+
+x = 42;
+y = 105;
+g = example.gcd(x,y);
+console.log("GCD of x and y is=" + g);
+
+/* Manipulate the Foo global variable */
+
+/* Output its current value */
+console.log("Global variable Foo=" + example.Foo);
+
+/* Change its value */
+example.Foo = 3.1415926;
+
+/* See if the change took effect */
+console.log("Variable Foo changed to=" + example.Foo);
+
+
+
+
+
+
+
diff --git a/Examples/javascript/template/Makefile b/Examples/javascript/template/Makefile
new file mode 100755
index 000000000..99a9e9e86
--- /dev/null
+++ b/Examples/javascript/template/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+JS_SCRIPT = runme.js
+TARGET = example
+INTERFACE = example.i
+
+wrapper::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
+
+build:: wrapper
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile javascript_clean
+
+check:: build
+ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
+ TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run
diff --git a/Examples/javascript/template/binding.gyp b/Examples/javascript/template/binding.gyp
new file mode 100644
index 000000000..69af46b22
--- /dev/null
+++ b/Examples/javascript/template/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/template/example.h b/Examples/javascript/template/example.h
new file mode 100644
index 000000000..7401df650
--- /dev/null
+++ b/Examples/javascript/template/example.h
@@ -0,0 +1,32 @@
+/* File : example.h */
+
+// Some template definitions
+
+template<class T> T max(T a, T b) { return a>b ? a : b; }
+
+template<class T> class vector {
+ T *v;
+ int sz;
+ public:
+ vector(int _sz) {
+ v = new T[_sz];
+ sz = _sz;
+ }
+ T &get(int index) {
+ return v[index];
+ }
+ void set(int index, T &val) {
+ v[index] = val;
+ }
+#ifdef SWIG
+ %extend {
+ T getitem(int index) {
+ return $self->get(index);
+ }
+ void setitem(int index, T val) {
+ $self->set(index,val);
+ }
+ }
+#endif
+};
+
diff --git a/Examples/javascript/template/example.i b/Examples/javascript/template/example.i
new file mode 100644
index 000000000..8f94c4da1
--- /dev/null
+++ b/Examples/javascript/template/example.i
@@ -0,0 +1,17 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Let's just grab the original header file here */
+%include "example.h"
+
+/* Now instantiate some specific template declarations */
+
+%template(maxint) max<int>;
+%template(maxdouble) max<double>;
+%template(vecint) vector<int>;
+%template(vecdouble) vector<double>;
+
diff --git a/Examples/javascript/template/runme.js b/Examples/javascript/template/runme.js
new file mode 100644
index 000000000..551475c72
--- /dev/null
+++ b/Examples/javascript/template/runme.js
@@ -0,0 +1,30 @@
+var example = require("./build/Release/example");
+
+//Call some templated functions
+console.log(example.maxint(3,7));
+console.log(example.maxdouble(3.14,2.18));
+
+// Create some class
+
+iv = new example.vecint(100);
+dv = new example.vecdouble(1000);
+
+for(i=0;i<=100;i++)
+ iv.setitem(i,2*i);
+
+for(i=0;i<=1000;i++)
+ dv.setitem(i, 1.0/(i+1));
+
+sum = 0;
+for(i=0;i<=100;i++)
+ sum = sum + iv.getitem(i);
+
+console.log(sum);
+
+sum = 0.0;
+for(i=0;i<=1000;i++)
+ sum = sum + dv.getitem(i);
+console.log(sum);
+
+delete iv;
+delete dv;
diff --git a/Examples/javascript/variables/Makefile b/Examples/javascript/variables/Makefile
new file mode 100755
index 000000000..99a9e9e86
--- /dev/null
+++ b/Examples/javascript/variables/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+JS_SCRIPT = runme.js
+TARGET = example
+INTERFACE = example.i
+
+wrapper::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
+
+build:: wrapper
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile javascript_clean
+
+check:: build
+ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
+ TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run
diff --git a/Examples/javascript/variables/binding.gyp b/Examples/javascript/variables/binding.gyp
new file mode 100644
index 000000000..54eebfaa0
--- /dev/null
+++ b/Examples/javascript/variables/binding.gyp
@@ -0,0 +1,8 @@
+{
+ "targets": [
+ {
+ "target_name": "example",
+ "sources": [ "example.cxx", "example_wrap.cxx" ]
+ }
+ ]
+}
diff --git a/Examples/javascript/variables/example.cxx b/Examples/javascript/variables/example.cxx
new file mode 100755
index 000000000..3ad4c2323
--- /dev/null
+++ b/Examples/javascript/variables/example.cxx
@@ -0,0 +1,96 @@
+/* File : example.c */
+
+/* I'm a file containing some C global variables */
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "example.h"
+
+int ivar = 0;
+short svar = 0;
+long lvar = 0;
+unsigned int uivar = 0;
+unsigned short usvar = 0;
+unsigned long ulvar = 0;
+signed char scvar = 0;
+unsigned char ucvar = 0;
+char cvar = 0;
+float fvar = 0;
+double dvar = 0;
+char *strvar = 0;
+#ifdef __cplusplus // Note: for v8 this must be linkable with g++, without extern cstrvar is mangled
+extern const char cstrvar[] = "Goodbye";
+#else
+const char cstrvar[] = "Goodbye";
+#endif
+const
+int *iptrvar = 0;
+char name[256] = "Dave";
+char path[256] = "/home/beazley";
+
+
+/* Global variables involving a structure */
+Point *ptptr = 0;
+Point pt = { 10, 20 };
+
+/* A variable that we will make read-only in the interface */
+int status = 1;
+
+/* A debugging function to print out their values */
+
+void print_vars() {
+ printf("ivar = %d\n", ivar);
+ printf("svar = %d\n", svar);
+ printf("lvar = %ld\n", lvar);
+ printf("uivar = %u\n", uivar);
+ printf("usvar = %u\n", usvar);
+ printf("ulvar = %lu\n", ulvar);
+ printf("scvar = %d\n", scvar);
+ printf("ucvar = %u\n", ucvar);
+ printf("fvar = %g\n", fvar);
+ printf("dvar = %g\n", dvar);
+ printf("cvar = %c\n", cvar);
+ printf("strvar = %s\n", strvar ? strvar : "(null)");
+ printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)");
+ printf("iptrvar = %p\n", iptrvar);
+ printf("name = %s\n", name);
+ printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0);
+ printf("pt = (%d, %d)\n", pt.x, pt.y);
+ printf("status = %d\n", status);
+}
+
+/* A function to create an integer (to test iptrvar) */
+
+int *new_int(int value) {
+ int *ip = (int *) malloc(sizeof(int));
+ *ip = value;
+ return ip;
+}
+
+/* A function to create a point */
+
+Point *new_Point(int x, int y) {
+ Point *p = (Point *) malloc(sizeof(Point));
+ p->x = x;
+ p->y = y;
+ return p;
+}
+
+char * Point_print(Point *p) {
+ static char buffer[256];
+ if (p) {
+ sprintf(buffer,"(%d,%d)", p->x,p->y);
+ } else {
+ sprintf(buffer,"null");
+ }
+ return buffer;
+}
+
+void pt_print() {
+ printf("(%d, %d)\n", pt.x, pt.y);
+}
diff --git a/Examples/javascript/variables/example.h b/Examples/javascript/variables/example.h
new file mode 100755
index 000000000..0f7e89594
--- /dev/null
+++ b/Examples/javascript/variables/example.h
@@ -0,0 +1,6 @@
+/* File: example.h */
+
+typedef struct {
+ int x,y;
+} Point;
+
diff --git a/Examples/javascript/variables/example.i b/Examples/javascript/variables/example.i
new file mode 100755
index 000000000..591b871ed
--- /dev/null
+++ b/Examples/javascript/variables/example.i
@@ -0,0 +1,49 @@
+/* File : example.i */
+%module example
+%{
+#include "example.h"
+%}
+
+/* Some global variable declarations */
+%inline %{
+extern int ivar;
+extern short svar;
+extern long lvar;
+extern unsigned int uivar;
+extern unsigned short usvar;
+extern unsigned long ulvar;
+extern signed char scvar;
+extern unsigned char ucvar;
+extern char cvar;
+extern float fvar;
+extern double dvar;
+extern char *strvar;
+extern const char cstrvar[];
+extern int *iptrvar;
+extern char name[256];
+
+extern Point *ptptr;
+extern Point pt;
+%}
+
+
+/* Some read-only variables */
+
+%immutable;
+
+%inline %{
+extern int status;
+extern char path[256];
+%}
+
+%mutable;
+
+/* Some helper functions to make it easier to test */
+%inline %{
+extern void print_vars();
+extern int *new_int(int value);
+extern Point *new_Point(int x, int y);
+extern char *Point_print(Point *p);
+extern void pt_print();
+%}
+
diff --git a/Examples/javascript/variables/runme.js b/Examples/javascript/variables/runme.js
new file mode 100755
index 000000000..22d208480
--- /dev/null
+++ b/Examples/javascript/variables/runme.js
@@ -0,0 +1,68 @@
+var example = require("./build/Release/example");
+
+// Try to set the values of some global variables
+example.ivar = 42;
+example.svar = -31000;
+example.lvar = 65537;
+example.uivar = 123456;
+example.usvar = 61000;
+example.ulvar = 654321;
+example.scvar = -13;
+example.ucvar = 251;
+example.cvar = "S";
+example.fvar = 3.14159;
+example.dvar = 2.1828;
+example.strvar = "Hello World";
+example.iptrvar= example.new_int(37);
+example.ptptr = example.new_Point(37,42);
+example.name = "Bill";
+
+// Now console.log out the values of the variables
+console.log("Variables (values console.loged from Python)" + "\n");
+console.log("ivar = " + example.ivar + "\n");
+console.log("svar = " + example.svar + "\n");
+console.log("lvar = " + example.lvar + "\n");
+console.log("uivar = " + example.uivar + "\n");
+console.log("usvar = " + example.usvar + "\n");
+console.log("ulvar = " + example.ulvar + "\n");
+console.log("scvar = " + example.scvar + "\n");
+console.log("ucvar = " + example.ucvar + "\n");
+console.log("fvar = " + example.fvar + "\n");
+console.log("dvar = " + example.dvar + "\n");
+console.log("cvar = " + example.cvar + "\n");
+console.log("strvar = " + example.strvar+ "\n");
+console.log("cstrvar = " + example.cstrvar+ "\n");
+console.log("iptrvar = " + example.iptrvar+ "\n");
+console.log("name = " + example.name + "\n");
+console.log("ptptr = " + example.ptptr + ": " + example.Point_print(example.ptptr) + "\n");
+console.log("pt = " + example.pt + ": " + example.Point_print(example.pt) + "\n");
+
+
+console.log("\nVariables (values console.loged from C)");
+
+example.print_vars();
+
+console.log("\nNow I'm going to try and modify some read only variables");
+
+console.log("Tring to set 'path'");
+try{
+ example.path = "Whoa!";
+ console.log("Hey, what's going on?!?! This shouldn't work");
+}
+catch(e){
+ console.log("Good.");
+}
+
+console.log("Trying to set 'status'");
+try{
+ example.status = 0;
+ console.log("Hey, what's going on?!?! This shouldn't work");
+} catch(e){
+ console.log("Good.");
+}
+
+console.log("\nI'm going to try and update a structure variable.\n");
+example.pt = example.ptptr;
+console.log("The new value is: ");
+example.pt_print();
+console.log("You should see the value: " + example.Point_print(example.ptptr));
diff --git a/Examples/javascript/variables/swig_gdb.log b/Examples/javascript/variables/swig_gdb.log
new file mode 100644
index 000000000..2fe437110
--- /dev/null
+++ b/Examples/javascript/variables/swig_gdb.log
@@ -0,0 +1,9 @@
+Loaded swig printers
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not convert const char* to string
+SwigStringPrinter: Could not convert const char* to string