From: <ne...@us...> - 2012-08-06 21:49:28
|
Revision: 13544 http://swig.svn.sourceforge.net/swig/?rev=13544&view=rev Author: neha1 Date: 2012-08-06 21:49:22 +0000 (Mon, 06 Aug 2012) Log Message: ----------- Fixed operator example. From: Neha Narang <nar...@gm...> Modified Paths: -------------- branches/gsoc2012-javascript/Examples/javascript/operator/example.i branches/gsoc2012-javascript/Examples/javascript/operator/runme.js Modified: branches/gsoc2012-javascript/Examples/javascript/operator/example.i =================================================================== --- branches/gsoc2012-javascript/Examples/javascript/operator/example.i 2012-08-06 21:48:48 UTC (rev 13543) +++ branches/gsoc2012-javascript/Examples/javascript/operator/example.i 2012-08-06 21:49:22 UTC (rev 13544) @@ -11,18 +11,24 @@ /* This turns the copy constructor in a function ComplexCopy() that can be called */ -%rename(ComplexCopy) Complex::Complex(Complex const &); +%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 *__str__() { - static char temp[512]; - sprintf(temp,"(%g,%g)", $self->re(), $self->im()); - return temp; - } + 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); + } }; - Modified: branches/gsoc2012-javascript/Examples/javascript/operator/runme.js =================================================================== --- branches/gsoc2012-javascript/Examples/javascript/operator/runme.js 2012-08-06 21:48:48 UTC (rev 13543) +++ branches/gsoc2012-javascript/Examples/javascript/operator/runme.js 2012-08-06 21:49:22 UTC (rev 13544) @@ -1,20 +1,28 @@ // Operator overloading example -a = example.Complex(2,3); -b = example.Complex(-5,10); +a = new example.Complex(2,3); +b = new example.Complex(-5,10); print ("a =" + a); print ("b =" + b); -c = a + b; +c = a.plus(b); + print("c =" + c); -print("a*b =" + a*b); -print("a-c =" + a-c); +print("a*b =" + a.times(b)); +print("a-c =" + a.minus(c)); -e = example.ComplexCopy(a-c); +e = example.Complex.copy(a.minus(c)); print("e =" + e); // Big expression -f = ((a+b)*(c+b*e)) + (-a); +f = a.plus(b).times(c.plus(b.times(e))).plus(a.uminus()); print("f =" + f); +zero = new example.Complex(0,0); +f = a.plus(b).times(c.plus(b.times(e))).plus(zero.minus(a)); +print("f =" + f); + + + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |