Javascript examples.
This commit is contained in:
parent
ecf9f96079
commit
48af60d829
76 changed files with 1685 additions and 0 deletions
21
Examples/javascript/constant/Makefile
Executable file
21
Examples/javascript/constant/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/constant/binding.gyp
Normal file
8
Examples/javascript/constant/binding.gyp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "example",
|
||||
"sources": [ "example_wrap.cxx" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
8
Examples/javascript/constant/example.h
Normal file
8
Examples/javascript/constant/example.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#define ICONST 42
|
||||
#define FCONST 2.1828
|
||||
#define CCONST 'x'
|
||||
#define CCONST2 '\n'
|
||||
#define SCONST "Hello World"
|
||||
#define SCONST2 "\"Hello World\""
|
||||
#define EXTERN extern
|
||||
#define FOO (ICONST + BAR)
|
||||
24
Examples/javascript/constant/example.i
Executable file
24
Examples/javascript/constant/example.i
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
/* A few preprocessor macros */
|
||||
|
||||
#define ICONST 42
|
||||
#define FCONST 2.1828
|
||||
#define CCONST 'x'
|
||||
#define CCONST2 '\n'
|
||||
#define SCONST "Hello World"
|
||||
#define SCONST2 "\"Hello World\""
|
||||
|
||||
/* This should work just fine */
|
||||
#define EXPR ICONST + 3*(FCONST)
|
||||
|
||||
/* This shouldn't do anything */
|
||||
#define EXTERN extern
|
||||
|
||||
/* Neither should this (BAR isn't defined) */
|
||||
#define FOO (ICONST + BAR)
|
||||
|
||||
/* The following directives also produce constants */
|
||||
%constant int iconst = 37;
|
||||
%constant double fconst = 3.14;
|
||||
14
Examples/javascript/constant/runme.js
Executable file
14
Examples/javascript/constant/runme.js
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
var example = require("./build/Release/example");
|
||||
|
||||
console.log("ICONST = " + example.ICONST + " (should be 42)\n");
|
||||
console.log("FCONST = " + example.FCONST + " (should be 2.1828)\n");
|
||||
console.log("CCONST = " + example.CCONST + " (should be 'x')\n");
|
||||
console.log("CCONST2 = " + example.CCONST2 + " (this should be on a new line)\n");
|
||||
console.log("SCONST = " + example.SCONST + " (should be 'Hello World')\n");
|
||||
console.log("SCONST2 = " + example.SCONST2 + " (should be '\"Hello World\"')\n");
|
||||
console.log("EXPR = " + example.EXPR + " (should be 48.5484)\n");
|
||||
console.log("iconst = " + example.iconst + " (should be 37)\n");
|
||||
console.log("fconst = " + example.fconst + " (should be 3.14)\n");
|
||||
|
||||
console.log("EXTERN = " + example.EXTERN + " (should be undefined)\n");
|
||||
console.log("FOO = " + example.FOO + " (should be undefined)\n");
|
||||
Loading…
Add table
Add a link
Reference in a new issue