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,21 +1,21 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cpp
CXXSRCS = example.cxx
JS_SCRIPT = runme.js
TARGET = example
INTERFACE = example.i
all::
wrapper::
$(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::
$(MAKE) -f $(TOP)/Makefile javascript_clean
javascript_exe::
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' javascript_exe
check:: all
check:: build
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
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 -----
// Print out the value of some enums
print("*** color ***");
print(" RED =" + example.RED);
print(" BLUE =" + example.BLUE);
print(" GREEN =" + example.GREEN);
console.log("*** color ***");
console.log(" RED =" + example.RED);
console.log(" BLUE =" + example.BLUE);
console.log(" GREEN =" + example.GREEN);
print("\n*** Foo::speed ***");
print(" Foo_IMPULSE =" + example.Foo.IMPULSE);
print(" Foo_WARP =" + example.Foo.WARP);
print(" Foo_LUDICROUS =" + example.Foo.LUDICROUS);
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);
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.BLUE, example.Foo.WARP);
example.enum_test(example.GREEN, example.Foo.LUDICROUS);
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.enum_test(example.Foo.IMPULSE);
@ -28,7 +28,7 @@ f.enum_test(example.Foo.WARP);
f.enum_test(example.Foo.LUDICROUS);
// 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
print("example.speed.LUDICROUS= " + example.Foo.LUDICROUS);
console.log("example.speed.LUDICROUS= " + example.Foo.LUDICROUS);