Merge branch 'devel' of https://github.com/Neha03/gsoc2012-javascript into devel
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:
parent
360ef44e09
commit
050219d998
136 changed files with 7987 additions and 141 deletions
24
Examples/javascript/class/Makefile
Executable file
24
Examples/javascript/class/Makefile
Executable 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
|
||||
|
||||
28
Examples/javascript/class/example.cpp
Executable file
28
Examples/javascript/class/example.cpp
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
/* File : example.c */
|
||||
#include <iostream>
|
||||
#include "example.h"
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
/* Move the shape to a new location */
|
||||
void Shape::move(double dx, double dy) {
|
||||
x += dx;
|
||||
y += dy;
|
||||
}
|
||||
|
||||
int Shape::nshapes = 0;
|
||||
|
||||
double Circle::area(void) {
|
||||
return M_PI*radius*radius;
|
||||
}
|
||||
|
||||
double Circle::perimeter(void) {
|
||||
return 2*M_PI*radius;
|
||||
}
|
||||
|
||||
double Square::area(void) {
|
||||
return width*width;
|
||||
}
|
||||
|
||||
double Square::perimeter(void) {
|
||||
return 4*width;
|
||||
}
|
||||
35
Examples/javascript/class/example.h
Executable file
35
Examples/javascript/class/example.h
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
/* File : example.h */
|
||||
|
||||
class Shape {
|
||||
public:
|
||||
Shape() {
|
||||
nshapes++;
|
||||
}
|
||||
virtual ~Shape() {
|
||||
nshapes--;
|
||||
};
|
||||
double x, y;
|
||||
void move(double dx, double dy);
|
||||
virtual double area(void) = 0;
|
||||
virtual double perimeter(void) = 0;
|
||||
static void printMe(void);
|
||||
static int nshapes;
|
||||
};
|
||||
|
||||
class Circle : public Shape {
|
||||
private:
|
||||
double radius;
|
||||
public:
|
||||
Circle(double r) : radius(r) { };
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
};
|
||||
|
||||
class Square : public Shape {
|
||||
private:
|
||||
double width;
|
||||
public:
|
||||
Square(double w) : width(w) { };
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
};
|
||||
10
Examples/javascript/class/example.i
Executable file
10
Examples/javascript/class/example.i
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
51
Examples/javascript/class/runme.js
Executable file
51
Examples/javascript/class/runme.js
Executable file
|
|
@ -0,0 +1,51 @@
|
|||
// file: runme.js
|
||||
|
||||
// ----- Object creation -----
|
||||
|
||||
print("Creating some objects:");
|
||||
c = new example.Circle(10);
|
||||
print("Created circle " + c);
|
||||
s = new example.Square(10);
|
||||
print("Created square " + s);
|
||||
|
||||
// ----- Access a static member -----
|
||||
print("\nA total of " + example.Shape.nshapes + " shapes were created"); // access static member as properties of the class object
|
||||
|
||||
// ----- Member data access -----
|
||||
// Set the location of the object.
|
||||
// Note: methods in the base class Shape are used since
|
||||
// x and y are defined there.
|
||||
|
||||
c.x = 20;
|
||||
c.y = 30;
|
||||
s.x = -10;
|
||||
s.y = 5;
|
||||
|
||||
print("\nHere is their current position:");
|
||||
print("Circle = (" + c.x + "," + c.y + ")");
|
||||
print("Square = (" + s.x + "," + s.y + ")");
|
||||
|
||||
print("\nHere is their new position:");
|
||||
print("Circle = (" + c.x + "," + c.y + ")");
|
||||
print("Square = (" + s.x + "," + s.y + ")");
|
||||
|
||||
|
||||
// ----- Call some methods -----
|
||||
print("\nHere are some properties of the shapes:");
|
||||
print("Circle:");
|
||||
print("area = " + c.area() + "");
|
||||
print("perimeter = " + c.perimeter() + "");
|
||||
print("\n");
|
||||
print("Square:");
|
||||
print("area = " + s.area() + "");
|
||||
print("perimeter = " + s.perimeter() + "");
|
||||
|
||||
// ----- Delete everything -----
|
||||
print("\nGuess I'll clean up now");
|
||||
// Note: this invokes the virtual destructor
|
||||
delete c;
|
||||
delete s;
|
||||
|
||||
print (example.Shape.nshapes + " shapes remain");
|
||||
|
||||
print("Goodbye");
|
||||
Loading…
Add table
Add a link
Reference in a new issue