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