Javascript examples.
This commit is contained in:
parent
ecf9f96079
commit
48af60d829
76 changed files with 1685 additions and 0 deletions
21
Examples/javascript/simple/Makefile
Executable file
21
Examples/javascript/simple/Makefile
Executable file
|
|
@ -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
|
||||
8
Examples/javascript/simple/binding.gyp
Normal file
8
Examples/javascript/simple/binding.gyp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "example",
|
||||
"sources": [ "example.cxx", "example_wrap.cxx" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
18
Examples/javascript/simple/example.cxx
Normal file
18
Examples/javascript/simple/example.cxx
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
7
Examples/javascript/simple/example.i
Normal file
7
Examples/javascript/simple/example.i
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%inline %{
|
||||
extern int gcd(int x, int y);
|
||||
extern double Foo;
|
||||
%}
|
||||
26
Examples/javascript/simple/runme.js
Executable file
26
Examples/javascript/simple/runme.js
Executable file
|
|
@ -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);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue