swig/Examples/javascript/variables/runme.js
Karl Wette f574a34155 Allow examples and test-suite to be built out of source tree
- Examples/Makefile.in rules use SRCDIR as the relative source directory

- ./config.status replicates Examples/ source directory tree in build
  directory, and copies each Makefile to build directory, prefixed with
  a header which sets SRCDIR to source directory

- Examples/test-suite/.../Makefile.in set SRCDIR from Autoconf-set srcdir

- Examples/test-suite/errors/Makefile.in needs to filter out source
  directory from SWIG error messages

- Lua: embedded interpreters are passed location of run-time test

- Python: copy run-time scripts to build directory because of 2to3
  conversion; import_packages example copies __init__.py from source
  directory; test-suite sets SCRIPTDIR to location of run-time tests

- Javascript: binding.gyp renamed to binding.gyp.in so that $srcdir
  can be substituted with SRCDIR; removed './' from require() statements
  so that NODE_PATH can be used to point Node.js to build directory
2014-05-11 23:21:10 +02:00

68 lines
2.1 KiB
JavaScript

var example = require("example");
// Try to set the values of some global variables
example.ivar = 42;
example.svar = -31000;
example.lvar = 65537;
example.uivar = 123456;
example.usvar = 61000;
example.ulvar = 654321;
example.scvar = -13;
example.ucvar = 251;
example.cvar = "S";
example.fvar = 3.14159;
example.dvar = 2.1828;
example.strvar = "Hello World";
example.iptrvar= example.new_int(37);
example.ptptr = example.new_Point(37,42);
example.name = "Bill";
// Now console.log out the values of the variables
console.log("Variables (values printed from Javascript)");
console.log("ivar = " + example.ivar);
console.log("svar = " + example.svar);
console.log("lvar = " + example.lvar);
console.log("uivar = " + example.uivar);
console.log("usvar = " + example.usvar);
console.log("ulvar = " + example.ulvar);
console.log("scvar = " + example.scvar);
console.log("ucvar = " + example.ucvar);
console.log("fvar = " + example.fvar);
console.log("dvar = " + example.dvar);
console.log("cvar = " + example.cvar);
console.log("strvar = " + example.strvar);
console.log("cstrvar = " + example.cstrvar);
console.log("iptrvar = " + example.iptrvar);
console.log("name = " + example.name);
console.log("ptptr = " + example.ptptr + ": " + example.Point_print(example.ptptr));
console.log("pt = " + example.pt + ": " + example.Point_print(example.pt));
console.log("\nVariables (values printed from C)");
example.print_vars();
console.log("\nNow I'm going to try and modify some read only variables");
console.log("Tring to set 'path'");
try{
example.path = "Whoa!";
console.log("Hey, what's going on?!?! This shouldn't work");
}
catch(e){
console.log("Good.");
}
console.log("Trying to set 'status'");
try{
example.status = 0;
console.log("Hey, what's going on?!?! This shouldn't work");
} catch(e){
console.log("Good.");
}
console.log("\nI'm going to try and update a structure variable.");
example.pt = example.ptptr;
console.log("The new value is: ");
example.pt_print();
console.log("You should see the value: " + example.Point_print(example.ptptr));