Conflicts:
	.project
	COPYRIGHT
	Doc/Manual/style.css
	Examples/Makefile.in
	Examples/test-suite/common.mk
	Lib/typemaps/strings.swg
	Makefile.in
	Source/DOH/fio.c
	Source/Makefile.am
	Source/Modules/emit.cxx
	Source/Modules/javascript.cxx
	configure.in

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/oliverb-javascript-v8@13764 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Oliver Buchtala 2012-09-08 00:56:48 +00:00
commit 050219d998
136 changed files with 7987 additions and 141 deletions

View file

@ -0,0 +1,24 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
SRCS = example.cpp
JSCXXSRCS = $(TOP)/../Tools/javascript/javascript.cxx
JAVASCRIPT_EXE = $(TOP)/../Tools/javascript/javascript
JAVASCRIPT_MODULE = example
JS_SCRIPT = runme.js
TARGET = example
INTERFACE = example.i
SWIGOPT = -I$(TOP)/../Lib/javascript -I$(TOP)/../Lib/javascript/jsc
all::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_cpp
clean::
$(MAKE) -f $(TOP)/Makefile javascript_clean
check:: all
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
JAVASCRIPT_EXE='$(JAVASCRIPT_EXE)' javascript_exe
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
JAVASCRIPT_EXE='$(JAVASCRIPT_EXE)' JAVASCRIPT_MODULE='$(JAVASCRIPT_MODULE)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run

View file

View file

@ -0,0 +1,36 @@
/* File : example.h */
#include <math.h>
class Complex {
private:
double rpart, ipart;
public:
Complex(double r = 0, double i = 0) : rpart(r), ipart(i) { }
Complex(const Complex &c) : rpart(c.rpart), ipart(c.ipart) { }
Complex &operator=(const Complex &c) {
rpart = c.rpart;
ipart = c.ipart;
return *this;
}
Complex operator+(const Complex &c) const {
return Complex(rpart+c.rpart, ipart+c.ipart);
}
Complex operator-(const Complex &c) const {
return Complex(rpart-c.rpart, ipart-c.ipart);
}
Complex operator*(const Complex &c) const {
return Complex(rpart*c.rpart - ipart*c.ipart,
rpart*c.ipart + c.rpart*ipart);
}
Complex operator-() const {
return Complex(-rpart, -ipart);
}
double re() const { return rpart; }
double im() const { return ipart; }
};

View file

@ -0,0 +1,34 @@
/* File : example.i */
%module example
#pragma SWIG nowarn=SWIGWARN_IGNORE_OPERATOR_EQ
%{
#include "example.h"
%}
/* This header file is a little tough to handle because it has overloaded
operators and constructors. We're going to try and deal with that here */
/* This turns the copy constructor in a function ComplexCopy() that can
be called */
%rename(assign) Complex::operator=;
%rename(plus) Complex::operator+;
%rename(minus) Complex::operator-(const Complex &) const;
%rename(uminus) Complex::operator-() const;
%rename(times) Complex::operator*;
/* Now grab the original header file */
%include "example.h"
/* An output method that turns a complex into a short string */
%extend Complex {
char *toString() {
static char temp[512];
sprintf(temp,"(%g,%g)", $self->re(), $self->im());
return temp;
}
static Complex* copy(const Complex& c) {
return new Complex(c);
}
};

View file

@ -0,0 +1,25 @@
// Operator overloading example
a = new example.Complex(2,3);
b = new example.Complex(-5,10);
print ("a =" + a);
print ("b =" + b);
c = a.plus(b);
print("c =" + c);
print("a*b =" + a.times(b));
print("a-c =" + a.minus(c));
e = example.Complex.copy(a.minus(c));
print("e =" + e);
// Big expression
f = a.plus(b).times(c.plus(b.times(e))).plus(a.uminus());
print("f =" + f);