First example that addresses node.js as primary execution environment.
This commit is contained in:
parent
a48438c562
commit
11e2179dd3
3 changed files with 35 additions and 26 deletions
|
|
@ -5,17 +5,17 @@ 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
|
||||||
|
|
|
||||||
8
Examples/javascript/class/binding.gyp
Normal file
8
Examples/javascript/class/binding.gyp
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"target_name": "example",
|
||||||
|
"sources": [ "example.cxx", "example_wrap.cxx" ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
// file: runme.js
|
// file: runme.js
|
||||||
|
var example = require("./build/Release/example");
|
||||||
|
|
||||||
// ----- Object creation -----
|
// ----- Object creation -----
|
||||||
|
|
||||||
print("Creating some objects:");
|
console.log("Creating some objects:");
|
||||||
c = new example.Circle(10);
|
c = new example.Circle(10);
|
||||||
print("Created circle " + c);
|
console.log("Created circle " + c);
|
||||||
s = new example.Square(10);
|
s = new example.Square(10);
|
||||||
print("Created square " + s);
|
console.log("Created square " + s);
|
||||||
|
|
||||||
// ----- Access a static member -----
|
// ----- Access a static member -----
|
||||||
print("\nA total of " + example.Shape.nshapes + " shapes were created"); // access static member as properties of the class object
|
console.log("\nA total of " + example.Shape.nshapes + " shapes were created"); // access static member as properties of the class object
|
||||||
|
|
||||||
// ----- Member data access -----
|
// ----- Member data access -----
|
||||||
// Set the location of the object.
|
// Set the location of the object.
|
||||||
|
|
@ -21,26 +22,26 @@ c.y = 30;
|
||||||
s.x = -10;
|
s.x = -10;
|
||||||
s.y = 5;
|
s.y = 5;
|
||||||
|
|
||||||
print("\nHere is their new position:");
|
console.log("\nHere is their new position:");
|
||||||
print("Circle = (" + c.x + "," + c.y + ")");
|
console.log("Circle = (" + c.x + "," + c.y + ")");
|
||||||
print("Square = (" + s.x + "," + s.y + ")");
|
console.log("Square = (" + s.x + "," + s.y + ")");
|
||||||
|
|
||||||
// ----- Call some methods -----
|
// ----- Call some methods -----
|
||||||
print("\nHere are some properties of the shapes:");
|
console.log("\nHere are some properties of the shapes:");
|
||||||
print("Circle:");
|
console.log("Circle:");
|
||||||
print("area = " + c.area() + "");
|
console.log("area = " + c.area() + "");
|
||||||
print("perimeter = " + c.perimeter() + "");
|
console.log("perimeter = " + c.perimeter() + "");
|
||||||
print("\n");
|
console.log("\n");
|
||||||
print("Square:");
|
console.log("Square:");
|
||||||
print("area = " + s.area() + "");
|
console.log("area = " + s.area() + "");
|
||||||
print("perimeter = " + s.perimeter() + "");
|
console.log("perimeter = " + s.perimeter() + "");
|
||||||
|
|
||||||
// ----- Delete everything -----
|
// ----- Delete everything -----
|
||||||
print("\nGuess I'll clean up now");
|
console.log("\nGuess I'll clean up now");
|
||||||
// Note: this invokes the virtual destructor
|
// Note: this invokes the virtual destructor
|
||||||
delete c;
|
delete c;
|
||||||
delete s;
|
delete s;
|
||||||
|
|
||||||
print (example.Shape.nshapes + " shapes remain");
|
console.log(example.Shape.nshapes + " shapes remain");
|
||||||
|
|
||||||
print("Goodbye");
|
console.log("Goodbye");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue