update swig on windows
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
SRCS =
|
||||
|
||||
include $(SRCDIR)../example.mk
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "example",
|
||||
"sources": [ "example_wrap.cxx" ],
|
||||
"include_dirs": ["$srcdir"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
|
||||
%inline %{
|
||||
// From B. Strousjoup, "The C++ Programming Language, Third Edition", p. 514
|
||||
template<class T> class Sum {
|
||||
T res;
|
||||
public:
|
||||
Sum(T i = 0) : res(i) { }
|
||||
void operator() (T x) { res += x; }
|
||||
T result() const { return res; }
|
||||
};
|
||||
|
||||
%}
|
||||
|
||||
%rename(call) *::operator(); // the fn call operator
|
||||
|
||||
// Instantiate a few versions
|
||||
%template(intSum) Sum<int>;
|
||||
%template(doubleSum) Sum<double>;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = require("build/Release/example");
|
||||
@@ -0,0 +1,15 @@
|
||||
var example = require("example");
|
||||
|
||||
a = new example.intSum(0);
|
||||
b = new example.doubleSum(100.0);
|
||||
|
||||
// Use the objects. They should be callable just like a normal
|
||||
// javascript function.
|
||||
|
||||
for (i=1;i<=100;i++)
|
||||
a.call(i); // Note: function call
|
||||
b.call(Math.sqrt(i)); // Note: function call
|
||||
|
||||
console.log(a.result());
|
||||
console.log(b.result());
|
||||
|
||||
Reference in New Issue
Block a user