Convert javascript examples to nodejs.

This commit is contained in:
Oliver Buchtala 2013-09-03 06:26:54 +02:00
commit 5da54ca435
48 changed files with 312 additions and 223 deletions

View file

@ -1,4 +1,3 @@
// file: runme.js
var example = require("./build/Release/example"); var example = require("./build/Release/example");
// ----- Object creation ----- // ----- Object creation -----

View file

@ -1,21 +1,21 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
CXXSRCS = CXXSRCS = example.cxx
JS_SCRIPT = runme.js JS_SCRIPT = runme.js
TARGET = example TARGET = example
INTERFACE = example.i INTERFACE = example.i
all:: wrapper::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript 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:: clean::
$(MAKE) -f $(TOP)/Makefile javascript_clean $(MAKE) -f $(TOP)/Makefile javascript_clean
javascript_exe:: check:: build
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' javascript_exe
check:: all
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run

View file

@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "example",
"sources": [ "example_wrap.cxx" ]
}
]
}

View file

@ -1,14 +1,14 @@
// file: runme.js var example = require("./build/Release/example");
print("ICONST = " + example.ICONST + " (should be 42)\n"); console.log("ICONST = " + example.ICONST + " (should be 42)\n");
print("FCONST = " + example.FCONST + " (should be 2.1828)\n"); console.log("FCONST = " + example.FCONST + " (should be 2.1828)\n");
print("CCONST = " + example.CCONST + " (should be 'x')\n"); console.log("CCONST = " + example.CCONST + " (should be 'x')\n");
print("CCONST2 = " + example.CCONST2 + " (this should be on a new line)\n"); console.log("CCONST2 = " + example.CCONST2 + " (this should be on a new line)\n");
print("SCONST = " + example.SCONST + " (should be 'Hello World')\n"); console.log("SCONST = " + example.SCONST + " (should be 'Hello World')\n");
print("SCONST2 = " + example.SCONST2 + " (should be '\"Hello World\"')\n"); console.log("SCONST2 = " + example.SCONST2 + " (should be '\"Hello World\"')\n");
print("EXPR = " + example.EXPR + " (should be 48.5484)\n"); console.log("EXPR = " + example.EXPR + " (should be 48.5484)\n");
print("iconst = " + example.iconst + " (should be 37)\n"); console.log("iconst = " + example.iconst + " (should be 37)\n");
print("fconst = " + example.fconst + " (should be 3.14)\n"); console.log("fconst = " + example.fconst + " (should be 3.14)\n");
print("EXTERN = " + example.EXTERN + " (should be undefined)\n"); console.log("EXTERN = " + example.EXTERN + " (should be undefined)\n");
print("FOO = " + example.FOO + " (should be undefined)\n"); console.log("FOO = " + example.FOO + " (should be undefined)\n");

View file

@ -1,21 +1,21 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cpp CXXSRCS = example.cxx
JS_SCRIPT = runme.js JS_SCRIPT = runme.js
TARGET = example TARGET = example
INTERFACE = example.i INTERFACE = example.i
all:: wrapper::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_cpp 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:: clean::
$(MAKE) -f $(TOP)/Makefile javascript_clean $(MAKE) -f $(TOP)/Makefile javascript_clean
javascript_exe:: check:: build
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' javascript_exe
check:: all
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run

View file

@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "example",
"sources": [ "example.cxx", "example_wrap.cxx" ]
}
]
}

View file

@ -1,26 +1,26 @@
// file: runme.py var example = require("./build/Release/example");
// ----- Object creation ----- // ----- Object creation -----
// Print out the value of some enums // Print out the value of some enums
print("*** color ***"); console.log("*** color ***");
print(" RED =" + example.RED); console.log(" RED =" + example.RED);
print(" BLUE =" + example.BLUE); console.log(" BLUE =" + example.BLUE);
print(" GREEN =" + example.GREEN); console.log(" GREEN =" + example.GREEN);
print("\n*** Foo::speed ***"); console.log("\n*** Foo::speed ***");
print(" Foo_IMPULSE =" + example.Foo.IMPULSE); console.log(" Foo_IMPULSE =" + example.Foo.IMPULSE);
print(" Foo_WARP =" + example.Foo.WARP); console.log(" Foo_WARP =" + example.Foo.WARP);
print(" Foo_LUDICROUS =" + example.Foo.LUDICROUS); console.log(" Foo_LUDICROUS =" + example.Foo.LUDICROUS);
print("\nTesting use of enums with functions\n"); console.log("\nTesting use of enums with functions\n");
example.enum_test(example.RED, example.Foo.IMPULSE); example.enum_test(example.RED, example.Foo.IMPULSE);
example.enum_test(example.BLUE, example.Foo.WARP); example.enum_test(example.BLUE, example.Foo.WARP);
example.enum_test(example.GREEN, example.Foo.LUDICROUS); example.enum_test(example.GREEN, example.Foo.LUDICROUS);
example.enum_test(1234,5678); example.enum_test(1234,5678);
print("\nTesting use of enum with class method"); console.log("\nTesting use of enum with class method");
f = new example.Foo(); f = new example.Foo();
f.enum_test(example.Foo.IMPULSE); f.enum_test(example.Foo.IMPULSE);
@ -28,7 +28,7 @@ f.enum_test(example.Foo.WARP);
f.enum_test(example.Foo.LUDICROUS); f.enum_test(example.Foo.LUDICROUS);
// enum value BLUE of enum color is accessed as property of cconst // enum value BLUE of enum color is accessed as property of cconst
print("example.BLUE= " + example.BLUE); console.log("example.BLUE= " + example.BLUE);
// enum value LUDICROUS of enum Foo::speed is accessed as as property of cconst // enum value LUDICROUS of enum Foo::speed is accessed as as property of cconst
print("example.speed.LUDICROUS= " + example.Foo.LUDICROUS); console.log("example.speed.LUDICROUS= " + example.Foo.LUDICROUS);

View file

@ -1,21 +1,21 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cpp CXXSRCS = example.cxx
JS_SCRIPT = runme.js JS_SCRIPT = runme.js
TARGET = example TARGET = example
INTERFACE = example.i INTERFACE = example.i
all:: wrapper::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_cpp 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:: clean::
$(MAKE) -f $(TOP)/Makefile javascript_clean $(MAKE) -f $(TOP)/Makefile javascript_clean
javascript_exe:: check:: build
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' javascript_exe
check:: all
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run

View file

@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "example",
"sources": [ "example.cxx", "example_wrap.cxx" ]
}
]
}

View file

@ -1,7 +1,6 @@
//file: runme.js var example = require("./build/Release/example");
// Throw a lot of exceptions
print("Trying to catch some exceptions."); console.log("Trying to catch some exceptions.");
t = new example.Test(); t = new example.Test();
try{ try{
t.unknown(); t.unknown();
@ -9,9 +8,9 @@ try{
} catch(error) } catch(error)
{ {
if(error == -1) { if(error == -1) {
print("t.unknown() didn't throw"); console.log("t.unknown() didn't throw");
} else { } else {
print("successfully catched throw in Test::unknown()."); console.log("successfully catched throw in Test::unknown().");
} }
} }
@ -21,9 +20,9 @@ try{
} }
catch(error){ catch(error){
if(error == -1) { if(error == -1) {
print("t.simple() did not throw"); console.log("t.simple() did not throw");
} else { } else {
print("successfully catched throw in Test::simple()."); console.log("successfully catched throw in Test::simple().");
} }
} }
@ -32,9 +31,9 @@ try{
throw -1; throw -1;
} catch(error){ } catch(error){
if(error == -1) { if(error == -1) {
print("t.message() did not throw"); console.log("t.message() did not throw");
} else { } else {
print("successfully catched throw in Test::message()."); console.log("successfully catched throw in Test::message().");
} }
} }
@ -44,9 +43,9 @@ try{
} }
catch(error){ catch(error){
if(error == -1) { if(error == -1) {
print("t.hosed() did not throw"); console.log("t.hosed() did not throw");
} else { } else {
print("successfully catched throw in Test::hosed()."); console.log("successfully catched throw in Test::hosed().");
} }
} }
@ -57,9 +56,9 @@ for (var i=1; i<4; i++) {
} }
catch(error){ catch(error){
if(error == -1) { if(error == -1) {
print("t.multi(" + i + ") did not throw"); console.log("t.multi(" + i + ") did not throw");
} else { } else {
print("successfully catched throw in Test::multi()."); console.log("successfully catched throw in Test::multi().");
} }
} }
} }

View file

@ -1,21 +1,21 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cpp CXXSRCS = example.cxx
JS_SCRIPT = runme.js JS_SCRIPT = runme.js
TARGET = example TARGET = example
INTERFACE = example.i INTERFACE = example.i
all:: wrapper::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_cpp 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:: clean::
$(MAKE) -f $(TOP)/Makefile javascript_clean $(MAKE) -f $(TOP)/Makefile javascript_clean
javascript_exe:: check:: build
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' javascript_exe
check:: all
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run

View file

@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "example",
"sources": [ "example.cxx", "example_wrap.cxx" ]
}
]
}

View file

@ -1,5 +1,4 @@
// Operator overloading example var example = require("./build/Release/example");
a = new example.intSum(0); a = new example.intSum(0);
b = new example.doubleSum(100.0); b = new example.doubleSum(100.0);
@ -11,6 +10,6 @@ for (i=1;i<=100;i++)
a.call(i); // Note: function call a.call(i); // Note: function call
b.call(Math.sqrt(i)); // Note: function call b.call(Math.sqrt(i)); // Note: function call
print(a.result()); console.log(a.result());
print(b.result()); console.log(b.result());

View file

@ -1,21 +1,21 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cpp CXXSRCS = example.cxx
JS_SCRIPT = runme.js JS_SCRIPT = runme.js
TARGET = example TARGET = example
INTERFACE = example.i INTERFACE = example.i
all:: wrapper::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_cpp 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:: clean::
$(MAKE) -f $(TOP)/Makefile javascript_clean $(MAKE) -f $(TOP)/Makefile javascript_clean
javascript_exe:: check:: build
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' javascript_exe
check:: all
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run

View file

@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "example",
"sources": [ "example.cxx", "example_wrap.cxx" ]
}
]
}

View file

@ -1,11 +1,10 @@
print("Global variable Foo=" + example.nspace.Foo); var example = require("./build/Release/example");
example.nspace.Foo = 5;
print("Variable Foo changed to " + example.nspace.Foo);
print("GCD of number 6,18 is " + example.nspace.gcd(6,18));
print("Creating some objects:"); 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); c = new example.nspace.Circle(10);
print("area = " + c.area()); console.log("area = " + c.area());

View file

@ -1,21 +1,21 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cpp CXXSRCS = example.cxx
JS_SCRIPT = runme.js JS_SCRIPT = runme.js
TARGET = example TARGET = example
INTERFACE = example.i INTERFACE = example.i
all:: wrapper::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_cpp 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:: clean::
$(MAKE) -f $(TOP)/Makefile javascript_clean $(MAKE) -f $(TOP)/Makefile javascript_clean
javascript_exe:: check:: build
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' javascript_exe
check:: all
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run

View file

@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "example",
"sources": [ "example_wrap.cxx" ]
}
]
}

View file

@ -1,23 +1,23 @@
// Operator overloading example var example = require("./build/Release/example");
a = new example.Complex(2,3); a = new example.Complex(2,3);
b = new example.Complex(-5,10); b = new example.Complex(-5,10);
print ("a =" + a); console.log ("a =" + a);
print ("b =" + b); console.log ("b =" + b);
c = a.plus(b); c = a.plus(b);
print("c =" + c); console.log("c =" + c);
print("a*b =" + a.times(b)); console.log("a*b =" + a.times(b));
print("a-c =" + a.minus(c)); console.log("a-c =" + a.minus(c));
e = example.Complex.copy(a.minus(c)); e = example.Complex.copy(a.minus(c));
print("e =" + e); console.log("e =" + e);
// Big expression // Big expression
f = a.plus(b).times(c.plus(b.times(e))).plus(a.uminus()); f = a.plus(b).times(c.plus(b.times(e))).plus(a.uminus());
print("f =" + f); console.log("f =" + f);

View file

@ -1,21 +1,21 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cpp CXXSRCS = example.cxx
JS_SCRIPT = runme.js JS_SCRIPT = runme.js
TARGET = example TARGET = example
INTERFACE = example.i INTERFACE = example.i
all:: wrapper::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_cpp 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:: clean::
$(MAKE) -f $(TOP)/Makefile javascript_clean $(MAKE) -f $(TOP)/Makefile javascript_clean
javascript_exe:: check:: build
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' javascript_exe
check:: all
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run

View file

@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "example",
"sources": [ "example_wrap.cxx" ]
}
]
}

View file

@ -1,3 +1,5 @@
var example = require("./build/Release/example");
example.f(); example.f();
example.f(1); example.f(1);
example.f(1, 2); example.f(1, 2);

View file

@ -1,21 +1,21 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cpp CXXSRCS = example.cxx
JS_SCRIPT = runme.js JS_SCRIPT = runme.js
TARGET = example TARGET = example
INTERFACE = example.i INTERFACE = example.i
all:: wrapper::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_cpp 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:: clean::
$(MAKE) -f $(TOP)/Makefile javascript_clean $(MAKE) -f $(TOP)/Makefile javascript_clean
javascript_exe:: check:: build
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' javascript_exe
check:: all
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run

View file

@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "example",
"sources": [ "example.cxx", "example_wrap.cxx" ]
}
]
}

View file

@ -1,7 +1,7 @@
// file: runme.js var example = require("./build/Release/example");
// First create some objects using the pointer library. // First create some objects using the pointer library.
print("Testing the pointer library\n"); console.log("Testing the pointer library\n");
a = example.new_intp(); a = example.new_intp();
b = example.new_intp(); b = example.new_intp();
c = example.new_intp(); c = example.new_intp();
@ -9,9 +9,9 @@ c = example.new_intp();
example.intp_assign(a,37); example.intp_assign(a,37);
example.intp_assign(b,42); example.intp_assign(b,42);
print(" a = " + example.intp_value(a) + "\n"); console.log(" a = " + example.intp_value(a) + "\n");
print(" b = " + example.intp_value(b) + "\n"); console.log(" b = " + example.intp_value(b) + "\n");
print(" c = " + example.intp_value(c) + "\n"); console.log(" c = " + example.intp_value(c) + "\n");
//// Call the add() function with some pointers //// Call the add() function with some pointers
example.add(a, b, c); example.add(a, b, c);
@ -19,7 +19,7 @@ example.add(a, b, c);
// //
//// Now get the result //// Now get the result
r = example.intp_value(c); r = example.intp_value(c);
print(" 37 + 42 = " + r + "\n"); console.log(" 37 + 42 = " + r + "\n");
// Clean up the pointers // Clean up the pointers
example.delete_intp(a); example.delete_intp(a);
@ -30,9 +30,6 @@ example.delete_intp(c);
//// This should be much easier. Now how it is no longer //// This should be much easier. Now how it is no longer
//// necessary to manufacture pointers. //// necessary to manufacture pointers.
//"OUTPUT" Mapping is not supported //"OUTPUT" Mapping is not supported
//console.log("Trying the typemap library");
//print("Trying the typemap library");
//r = example.subtract(37,42); //r = example.subtract(37,42);
//print("37 - 42 =" + r); //console.log("37 - 42 =" + r);

View file

@ -1,21 +1,21 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cpp CXXSRCS = example.cxx
JS_SCRIPT = runme.js JS_SCRIPT = runme.js
TARGET = example TARGET = example
INTERFACE = example.i INTERFACE = example.i
all:: wrapper::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_cpp 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:: clean::
$(MAKE) -f $(TOP)/Makefile javascript_clean $(MAKE) -f $(TOP)/Makefile javascript_clean
javascript_exe:: check:: build
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' javascript_exe
check:: all
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run

View file

@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "example",
"sources": [ "example.cxx", "example_wrap.cxx" ]
}
]
}

View file

@ -1,23 +1,23 @@
// This file illustrates the manipulation of C++ references in Javascript. // This file illustrates the manipulation of C++ references in Javascript.
// TODO: deleteion of vector objects created here var example = require("./build/Release/example");
// ----- Object creation ----- // ----- Object creation -----
print("Creating some objects:\n"); console.log("Creating some objects:\n");
a = new example.Vector(3,4,5); a = new example.Vector(3,4,5);
b = new example.Vector(10,11,12); b = new example.Vector(10,11,12);
print(" created" + a.print()); console.log(" created" + a.print());
print(" created" + b.print()); console.log(" created" + b.print());
// ----- Call an overloaded operator ----- // ----- Call an overloaded operator -----
// This calls the wrapper we placed around operator+(const Vector &a, const Vector &) // This calls the wrapper we placed around operator+(const Vector &a, const Vector &)
// It returns a new allocated object. // It returns a new allocated object.
print("Adding a+b\n"); console.log("Adding a+b\n");
c = example.addv(a, b); c = example.addv(a, b);
print("a+b = " + c.print()); console.log("a+b = " + c.print());
// TODO: Note: Unless we free the result, a memory leak will occur // TODO: Note: Unless we free the result, a memory leak will occur
@ -26,9 +26,9 @@ print("a+b = " + c.print());
// ----- Create a vector array ----- // ----- Create a vector array -----
// Note: Using the high-level interface here // Note: Using the high-level interface here
print("Creating an array of vectors\n"); console.log("Creating an array of vectors\n");
va = new example.VectorArray(10); va = new example.VectorArray(10);
print("va = " + va + "\n"); console.log("va = " + va + "\n");
// ----- Set some values in the array ----- // ----- Set some values in the array -----
@ -46,20 +46,20 @@ va.set(2,example.addv(a,b));
// Get some values from the array // Get some values from the array
print("Getting some array values\n"); console.log("Getting some array values\n");
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
temp = va.get(i); temp = va.get(i);
print(i,temp.print()); console.log(i,temp.print());
} }
// Watch under resource meter to check on this // Watch under resource meter to check on this
print("Making sure we don't leak memory.\n"); console.log("Making sure we don't leak memory.\n");
for (i = 0; i < 1000000; i++) { for (i = 0; i < 1000000; i++) {
c = va.get(i % 10); c = va.get(i % 10);
} }
//---------TODO--------- //---------TODO---------
//----- Clean up ----- //----- Clean up -----
//print("Cleaning up\n"); //console.log("Cleaning up\n");
//example.delete_VectorArray(va); //example.delete_VectorArray(va);
//example.delete_Vector(a); //example.delete_Vector(a);

View file

@ -1,21 +1,21 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.c CXXSRCS = example.cxx
JS_SCRIPT = runme.js JS_SCRIPT = runme.js
TARGET = example TARGET = example
INTERFACE = example.i INTERFACE = example.i
all:: wrapper::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript 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:: clean::
$(MAKE) -f $(TOP)/Makefile javascript_clean $(MAKE) -f $(TOP)/Makefile javascript_clean
javascript_exe:: check:: build
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' javascript_exe
check:: all
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run

View file

@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "example",
"sources": [ "example.cxx", "example_wrap.cxx" ]
}
]
}

View file

@ -1,22 +1,22 @@
/* file: runme.js */ var example = require("./build/Release/example");
/* Call our gcd() function */ /* Call our gcd() function */
x = 42; x = 42;
y = 105; y = 105;
g = example.gcd(x,y); g = example.gcd(x,y);
print("GCD of x and y is=" + g); console.log("GCD of x and y is=" + g);
/* Manipulate the Foo global variable */ /* Manipulate the Foo global variable */
/* Output its current value */ /* Output its current value */
print("Global variable Foo=" + example.Foo); console.log("Global variable Foo=" + example.Foo);
/* Change its value */ /* Change its value */
example.Foo = 3.1415926; example.Foo = 3.1415926;
/* See if the change took effect */ /* See if the change took effect */
print("Variable Foo changed to=" + example.Foo); console.log("Variable Foo changed to=" + example.Foo);

View file

@ -1,21 +1,21 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cpp CXXSRCS = example.cxx
JS_SCRIPT = runme.js JS_SCRIPT = runme.js
TARGET = example TARGET = example
INTERFACE = example.i INTERFACE = example.i
all:: wrapper::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_cpp 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:: clean::
$(MAKE) -f $(TOP)/Makefile javascript_clean $(MAKE) -f $(TOP)/Makefile javascript_clean
javascript_exe:: check:: build
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' javascript_exe
check:: all
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run

View file

@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "example",
"sources": [ "example_wrap.cxx" ]
}
]
}

View file

@ -1,8 +1,8 @@
// file: runme.js var example = require("./build/Release/example");
//Call some templated functions //Call some templated functions
print(example.maxint(3,7)); console.log(example.maxint(3,7));
print(example.maxdouble(3.14,2.18)); console.log(example.maxdouble(3.14,2.18));
// Create some class // Create some class
@ -19,14 +19,12 @@ sum = 0;
for(i=0;i<=100;i++) for(i=0;i<=100;i++)
sum = sum + iv.getitem(i); sum = sum + iv.getitem(i);
print(sum); console.log(sum);
sum = 0.0; sum = 0.0;
for(i=0;i<=1000;i++) for(i=0;i<=1000;i++)
sum = sum + dv.getitem(i); sum = sum + dv.getitem(i);
print(sum); console.log(sum);
delete iv; delete iv;
delete dv; delete dv;

View file

@ -1,21 +1,21 @@
TOP = ../.. TOP = ../..
SWIG = $(TOP)/../preinst-swig SWIG = $(TOP)/../preinst-swig
SRCS = example.c CXXSRCS = example.cxx
JS_SCRIPT = runme.js JS_SCRIPT = runme.js
TARGET = example TARGET = example
INTERFACE = example.i INTERFACE = example.i
all:: wrapper::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript 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:: clean::
$(MAKE) -f $(TOP)/Makefile javascript_clean $(MAKE) -f $(TOP)/Makefile javascript_clean
javascript_exe:: check:: build
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' javascript_exe
check:: all
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \ $(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run

View file

@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "example",
"sources": [ "example.cxx", "example_wrap.cxx" ]
}
]
}

View file

@ -1,4 +1,4 @@
// file: runme.js var example = require("./build/Release/example");
// Try to set the values of some global variables // Try to set the values of some global variables
example.ivar = 42; example.ivar = 42;
@ -17,52 +17,52 @@ example.iptrvar= example.new_int(37);
example.ptptr = example.new_Point(37,42); example.ptptr = example.new_Point(37,42);
example.name = "Bill"; example.name = "Bill";
// Now print out the values of the variables // Now console.log out the values of the variables
print("Variables (values printed from Python)" + "\n"); console.log("Variables (values console.loged from Python)" + "\n");
print("ivar = " + example.ivar + "\n"); console.log("ivar = " + example.ivar + "\n");
print("svar = " + example.svar + "\n"); console.log("svar = " + example.svar + "\n");
print("lvar = " + example.lvar + "\n"); console.log("lvar = " + example.lvar + "\n");
print("uivar = " + example.uivar + "\n"); console.log("uivar = " + example.uivar + "\n");
print("usvar = " + example.usvar + "\n"); console.log("usvar = " + example.usvar + "\n");
print("ulvar = " + example.ulvar + "\n"); console.log("ulvar = " + example.ulvar + "\n");
print("scvar = " + example.scvar + "\n"); console.log("scvar = " + example.scvar + "\n");
print("ucvar = " + example.ucvar + "\n"); console.log("ucvar = " + example.ucvar + "\n");
print("fvar = " + example.fvar + "\n"); console.log("fvar = " + example.fvar + "\n");
print("dvar = " + example.dvar + "\n"); console.log("dvar = " + example.dvar + "\n");
print("cvar = " + example.cvar + "\n"); console.log("cvar = " + example.cvar + "\n");
print("strvar = " + example.strvar+ "\n"); console.log("strvar = " + example.strvar+ "\n");
print("cstrvar = " + example.cstrvar+ "\n"); console.log("cstrvar = " + example.cstrvar+ "\n");
print("iptrvar = " + example.iptrvar+ "\n"); console.log("iptrvar = " + example.iptrvar+ "\n");
print("name = " + example.name + "\n"); console.log("name = " + example.name + "\n");
print("ptptr = " + example.ptptr + ": " + example.Point_print(example.ptptr) + "\n"); console.log("ptptr = " + example.ptptr + ": " + example.Point_print(example.ptptr) + "\n");
print("pt = " + example.pt + ": " + example.Point_print(example.pt) + "\n"); console.log("pt = " + example.pt + ": " + example.Point_print(example.pt) + "\n");
print("\nVariables (values printed from C)"); console.log("\nVariables (values console.loged from C)");
example.print_vars(); example.print_vars();
print("\nNow I'm going to try and modify some read only variables"); console.log("\nNow I'm going to try and modify some read only variables");
print("Tring to set 'path'"); console.log("Tring to set 'path'");
try{ try{
example.path = "Whoa!"; example.path = "Whoa!";
print("Hey, what's going on?!?! This shouldn't work"); console.log("Hey, what's going on?!?! This shouldn't work");
} }
catch(e){ catch(e){
print("Good."); console.log("Good.");
} }
print("Trying to set 'status'"); console.log("Trying to set 'status'");
try{ try{
example.status = 0; example.status = 0;
print("Hey, what's going on?!?! This shouldn't work"); console.log("Hey, what's going on?!?! This shouldn't work");
} catch(e){ } catch(e){
print("Good."); console.log("Good.");
} }
print("\nI'm going to try and update a structure variable.\n"); console.log("\nI'm going to try and update a structure variable.\n");
example.pt = example.ptptr; example.pt = example.ptptr;
print("The new value is: "); console.log("The new value is: ");
example.pt_print(); example.pt_print();
print("You should see the value: " + example.Point_print(example.ptptr)); console.log("You should see the value: " + example.Point_print(example.ptptr));