Merge branch 'master' into array_fix
This commit is contained in:
commit
1a4dc82931
1964 changed files with 57298 additions and 30865 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,11 +0,0 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int Circle (int x, int y, int radius) {
|
||||
/* Draw Circle */
|
||||
printf("Drawing the circle...\n");
|
||||
/* Return -1 to test contract post assertion */
|
||||
if (radius == 2)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
/* File : example.i */
|
||||
|
||||
/* Basic C example for swig contract */
|
||||
/* Tiger, University of Chicago, 2003 */
|
||||
|
||||
%module example
|
||||
|
||||
%contract Circle (int x, int y, int radius) {
|
||||
require:
|
||||
x >= 0;
|
||||
y >= 0;
|
||||
radius > x;
|
||||
ensure:
|
||||
Circle >= 0;
|
||||
}
|
||||
|
||||
%inline %{
|
||||
extern int Circle (int x, int y, int radius);
|
||||
%}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
import example
|
||||
# Call the Circle() function correctly
|
||||
|
||||
x = 1;
|
||||
y = 1;
|
||||
r = 3;
|
||||
|
||||
c = example.Circle(x, y, r)
|
||||
|
||||
# test post-assertion
|
||||
x = 1;
|
||||
y = 1;
|
||||
r = 2;
|
||||
|
||||
c = example.Circle(x, y, r)
|
||||
|
||||
print "The return value of Circle(%d, %d, %d) is %d" % (x,y,r,c)
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
import example
|
||||
|
||||
# Call the Circle() function correctly
|
||||
|
||||
x = 1;
|
||||
y = 1;
|
||||
r = 3;
|
||||
|
||||
c = example.Circle(x, y, r)
|
||||
|
||||
print "The return value of Circle(%d, %d, %d) is %d" % (x,y,r,c)
|
||||
|
||||
# test pre-assertion
|
||||
x = 1;
|
||||
y = -1;
|
||||
r = 3;
|
||||
|
||||
c = example.Circle(x, y, r)
|
||||
|
||||
print "The return value of Circle(%d, %d, %d) is %d" % (x,y,r,c)
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
%module example
|
||||
|
||||
%contract Circle::Circle(double radius) {
|
||||
require:
|
||||
radius > 0;
|
||||
}
|
||||
|
||||
%contract Circle::area(void) {
|
||||
ensure:
|
||||
area > 0;
|
||||
}
|
||||
|
||||
%contract Shape::move(double dx, double dy) {
|
||||
require:
|
||||
dx > 0;
|
||||
}
|
||||
|
||||
/* should be no effect, since there is no move() for class Circle */
|
||||
%contract Circle::move(double dx, double dy) {
|
||||
require:
|
||||
dy > 1;
|
||||
}
|
||||
|
||||
# include must be after contracts
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
%include "example.h"
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
import example
|
||||
|
||||
# Create the Circle object
|
||||
|
||||
r = 2;
|
||||
print " Creating circle (radium: %d) :" % r
|
||||
c = example.Circle(r)
|
||||
|
||||
# Set the location of the object
|
||||
|
||||
c.x = 20
|
||||
c.y = 30
|
||||
print " Here is its current position:"
|
||||
print " Circle = (%f, %f)" % (c.x,c.y)
|
||||
|
||||
# ----- Call some methods -----
|
||||
|
||||
print "\n Here are some properties of the Circle:"
|
||||
print " area = ", c.area()
|
||||
print " perimeter = ", c.perimeter()
|
||||
dx = 1;
|
||||
dy = 1;
|
||||
print " Moving with (%d, %d)..." % (dx, dy)
|
||||
c.move(dx, dy)
|
||||
|
||||
del c
|
||||
|
||||
print "==================================="
|
||||
|
||||
# test construction */
|
||||
r = -1;
|
||||
print " Creating circle (radium: %d) :" % r
|
||||
c = example.Circle(r)
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
import example
|
||||
|
||||
# Create the Circle object
|
||||
|
||||
r = 2;
|
||||
print " Creating circle (radium: %d) :" % r
|
||||
c = example.Circle(r)
|
||||
|
||||
# Set the location of the object
|
||||
|
||||
c.x = 20
|
||||
c.y = 30
|
||||
print " Here is its current position:"
|
||||
print " Circle = (%f, %f)" % (c.x,c.y)
|
||||
|
||||
# ----- Call some methods -----
|
||||
|
||||
print "\n Here are some properties of the Circle:"
|
||||
print " area = ", c.area()
|
||||
print " perimeter = ", c.perimeter()
|
||||
dx = 1;
|
||||
dy = 1;
|
||||
print " Moving with (%d, %d)..." % (dx, dy)
|
||||
c.move(dx, dy)
|
||||
|
||||
del c
|
||||
|
||||
print "==================================="
|
||||
|
||||
# test area function */
|
||||
r = 1;
|
||||
print " Creating circle (radium: %d) :" % r
|
||||
c = example.Circle(r)
|
||||
# Set the location of the object
|
||||
|
||||
c.x = 20
|
||||
c.y = 30
|
||||
print " Here is its current position:"
|
||||
print " Circle = (%f, %f)" % (c.x,c.y)
|
||||
|
||||
# ----- Call some methods -----
|
||||
|
||||
print "\n Here are some properties of the Circle:"
|
||||
print " area = ", c.area()
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
import example
|
||||
|
||||
# Create the Circle object
|
||||
|
||||
r = 2;
|
||||
print " Creating circle (radium: %d) :" % r
|
||||
c = example.Circle(r)
|
||||
|
||||
# Set the location of the object
|
||||
|
||||
c.x = 20
|
||||
c.y = 30
|
||||
print " Here is its current position:"
|
||||
print " Circle = (%f, %f)" % (c.x,c.y)
|
||||
|
||||
# ----- Call some methods -----
|
||||
|
||||
print "\n Here are some properties of the Circle:"
|
||||
print " area = ", c.area()
|
||||
print " perimeter = ", c.perimeter()
|
||||
dx = 1;
|
||||
dy = 1;
|
||||
print " Moving with (%d, %d)..." % (dx, dy)
|
||||
c.move(dx, dy)
|
||||
|
||||
del c
|
||||
|
||||
print "==================================="
|
||||
|
||||
# test move function */
|
||||
r = 2;
|
||||
print " Creating circle (radium: %d) :" % r
|
||||
c = example.Circle(r)
|
||||
# Set the location of the object
|
||||
|
||||
c.x = 20
|
||||
c.y = 30
|
||||
print " Here is its current position:"
|
||||
print " Circle = (%f, %f)" % (c.x,c.y)
|
||||
|
||||
# ----- Call some methods -----
|
||||
|
||||
print "\n Here are some properties of the Circle:"
|
||||
print " area = ", c.area()
|
||||
print " perimeter = ", c.perimeter()
|
||||
|
||||
# no error for Circle's pre-assertion
|
||||
dx = 1;
|
||||
dy = -1;
|
||||
print " Moving with (%d, %d)..." % (dx, dy)
|
||||
c.move(dx, dy)
|
||||
|
||||
# error with Shape's pre-assertion
|
||||
dx = -1;
|
||||
dy = 1;
|
||||
print " Moving with (%d, %d)..." % (dx, dy)
|
||||
c.move(dx, dy)
|
||||
|
|
@ -36,6 +36,6 @@ func DeleteGoCallback(p GoCallback) {
|
|||
p.deleteCallback()
|
||||
}
|
||||
|
||||
func (p *goCallback) Run() {
|
||||
func (p *overwrittenMethodsOnCallback) Run() {
|
||||
fmt.Println("GoCallback.Run")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
. "./example"
|
||||
"fmt"
|
||||
|
||||
. "swigtests/example"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
. "./example"
|
||||
"fmt"
|
||||
|
||||
. "swigtests/example"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"./example"
|
||||
"fmt"
|
||||
|
||||
"swigtests/example"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ type overwrittenMethodsOnFooBarAbstract struct {
|
|||
fb FooBarAbstract
|
||||
|
||||
// If additional constructor arguments have been given they are typically
|
||||
// stored here so that the overriden methods can use them.
|
||||
// stored here so that the overridden methods can use them.
|
||||
}
|
||||
|
||||
func (om *overwrittenMethodsOnFooBarAbstract) Foo() string {
|
||||
|
|
@ -59,7 +59,7 @@ func NewFooBarGo() FooBarGo {
|
|||
// The memory of the FooBarAbstract director object instance can be
|
||||
// automatically freed once the FooBarGo instance is garbage collected by
|
||||
// uncommenting the following line. Please make sure to understand the
|
||||
// runtime.SetFinalizer specific gotchas before doing this. Furthemore
|
||||
// runtime.SetFinalizer specific gotchas before doing this. Furthermore
|
||||
// DeleteFooBarGo should be deleted if a finalizer is in use or the fooBarGo
|
||||
// struct needs additional data to prevent double deletion.
|
||||
// runtime.SetFinalizer(fbgs, FooBarGo.deleteFooBarAbstract)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"./example"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"swigtests/example"
|
||||
)
|
||||
|
||||
func Compare(name string, got string, exp string) error {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
. "./example"
|
||||
"fmt"
|
||||
|
||||
. "swigtests/example"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
. "./example"
|
||||
"fmt"
|
||||
|
||||
. "swigtests/example"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
. "./example"
|
||||
"fmt"
|
||||
|
||||
. "swigtests/example"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
. "./example"
|
||||
"fmt"
|
||||
|
||||
. "swigtests/example"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
. "./example"
|
||||
"fmt"
|
||||
|
||||
. "swigtests/example"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
. "./example"
|
||||
"fmt"
|
||||
|
||||
. "swigtests/example"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"./example"
|
||||
"fmt"
|
||||
|
||||
"swigtests/example"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
. "./example"
|
||||
"fmt"
|
||||
|
||||
. "swigtests/example"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"./example"
|
||||
"fmt"
|
||||
|
||||
"swigtests/example"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
# see top-level Makefile.in
|
||||
constants
|
||||
class
|
||||
port
|
||||
simple
|
||||
std_vector
|
||||
constants
|
||||
matrix
|
||||
multimap
|
||||
multivalue
|
||||
port
|
||||
simple
|
||||
std_vector
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
#!./matrix \
|
||||
-e do-test -s
|
||||
!#
|
||||
;;; Authors: David Beazley <beazley@cs.uchicago.edu>, 1999
|
||||
;;; Martin Froehlich <MartinFroehlich@ACM.org>, 2000
|
||||
;;;
|
||||
|
|
@ -15,7 +12,7 @@
|
|||
;;; Explanation: The three lines at the beginning of this script are
|
||||
;;; telling the kernel to load the enhanced guile interpreter named
|
||||
;;; "matrix"; to execute the function "do-test" (-e option) after loading
|
||||
;;; this script (-s option). There are a lot more options wich allow for
|
||||
;;; this script (-s option). There are a lot more options which allow for
|
||||
;;; even finer tuning. SEE ALSO: Section "Guile Scripts" in the "Guile
|
||||
;;; reference manual -- Part I: Preliminaries".
|
||||
;;;
|
||||
|
|
|
|||
|
|
@ -15,14 +15,14 @@ back to this behavior, use: */
|
|||
|
||||
void divide_l(int a, int b, int *OUTPUT, int *OUTPUT);
|
||||
|
||||
/* Multiple values as vectors. By issueing: */
|
||||
/* Multiple values as vectors. By issuing: */
|
||||
%values_as_vector;
|
||||
/* vectors instead of lists will be used. */
|
||||
|
||||
void divide_v(int a, int b, int *OUTPUT, int *OUTPUT);
|
||||
|
||||
/* Multiple values for multiple-value continuations.
|
||||
(This is the most elegant way.) By issueing: */
|
||||
(This is the most elegant way.) By issuing: */
|
||||
%multiple_values;
|
||||
/* multiple values are passed to the multiple-value
|
||||
continuation, as created by `call-with-values' or the
|
||||
|
|
|
|||
|
|
@ -1,21 +1,18 @@
|
|||
/* Simple example from documentation */
|
||||
/* File : example.c */
|
||||
|
||||
#include <time.h>
|
||||
/* A global variable */
|
||||
double Foo = 3.0;
|
||||
|
||||
double My_variable = 3.0;
|
||||
|
||||
int fact(int n) {
|
||||
if (n <= 1) return 1;
|
||||
else return n*fact(n-1);
|
||||
/* Compute the greatest common divisor of positive integers */
|
||||
int gcd(int x, int y) {
|
||||
int g;
|
||||
g = y;
|
||||
while (x > 0) {
|
||||
g = x;
|
||||
x = y % x;
|
||||
y = g;
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
int mod(int n, int m) {
|
||||
return (n % m);
|
||||
}
|
||||
|
||||
char *get_time() {
|
||||
long ltime;
|
||||
time(<ime);
|
||||
return ctime(<ime);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,8 @@
|
|||
%}
|
||||
|
||||
%inline %{
|
||||
extern double My_variable;
|
||||
extern int fact(int);
|
||||
extern int mod(int n, int m);
|
||||
extern char *get_time();
|
||||
extern int gcd(int x, int y);
|
||||
extern double Foo;
|
||||
%}
|
||||
|
||||
%include guile/guilemain.i
|
||||
|
|
|
|||
|
|
@ -3,24 +3,20 @@
|
|||
(for-each display args)
|
||||
(newline))
|
||||
|
||||
(mdisplay-newline (get-time) "My variable = " (My-variable))
|
||||
; Call our gcd() function
|
||||
|
||||
(do ((i 0 (1+ i)))
|
||||
((= 14 i))
|
||||
(mdisplay-newline i " factorial is " (fact i)))
|
||||
(define x 42)
|
||||
(define y 105)
|
||||
(define g (gcd x y))
|
||||
(mdisplay-newline "The gcd of " x " and " y " is " g)
|
||||
|
||||
(define (mods i imax j jmax)
|
||||
(if (< i imax)
|
||||
(if (< j jmax)
|
||||
(begin
|
||||
(My-variable (+ (My-variable) (mod i j)))
|
||||
(mods i imax (+ j 1) jmax))
|
||||
(mods (+ i 1) imax 1 jmax))))
|
||||
; Manipulate the Foo global variable
|
||||
|
||||
(mods 1 150 1 150)
|
||||
; Output its current value
|
||||
(mdisplay-newline "Foo = " (Foo))
|
||||
|
||||
(mdisplay-newline "My-variable = " (My-variable))
|
||||
|
||||
(exit (and (= 1932053504 (fact 13))
|
||||
(= 745470.0 (My-variable))))
|
||||
; Change its value
|
||||
(Foo 3.1415926)
|
||||
|
||||
; See if the change took effect
|
||||
(mdisplay-newline "Foo = " (Foo))
|
||||
|
|
|
|||
|
|
@ -17,9 +17,8 @@ std::vector<double> half(const std::vector<double>& v) {
|
|||
}
|
||||
|
||||
void halve_in_place(std::vector<double>& v) {
|
||||
// would you believe this is the same as the above?
|
||||
std::transform(v.begin(),v.end(),v.begin(),
|
||||
std::bind2nd(std::divides<double>(),2.0));
|
||||
for (std::vector<double>::iterator it = v.begin(); it != v.end(); ++it)
|
||||
*it /= 2.0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
callback
|
||||
class
|
||||
constants
|
||||
doxygen
|
||||
enum
|
||||
extend
|
||||
funcptr
|
||||
|
|
|
|||
|
|
@ -4,17 +4,18 @@ SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
|||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS =
|
||||
SWIGOPT =
|
||||
SWIGOPT = -doxygen
|
||||
JAVASRCS = *.java
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_run
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||
php5_cpp
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_clean
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' java_clean
|
||||
rm -rf javadocs
|
||||
48
Examples/java/doxygen/example.cxx
Normal file
48
Examples/java/doxygen/example.cxx
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* File : example.cxx */
|
||||
|
||||
#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;
|
||||
|
||||
Circle::Circle(double r) : radius(r) {
|
||||
NumCircles++;
|
||||
}
|
||||
|
||||
double Circle::area() {
|
||||
return M_PI*radius*radius;
|
||||
}
|
||||
|
||||
double Circle::perimeter() {
|
||||
return 2*M_PI*radius;
|
||||
}
|
||||
|
||||
Square::Square(double w) : width(w) {
|
||||
NumSquares++;
|
||||
}
|
||||
|
||||
double Square::area() {
|
||||
return width*width;
|
||||
}
|
||||
|
||||
double Square::perimeter() {
|
||||
return 4*width;
|
||||
}
|
||||
|
||||
int NumSquares = 0;
|
||||
int NumCircles = 0;
|
||||
|
||||
Square MakeSquare(double r) {
|
||||
return Square(r);
|
||||
}
|
||||
|
||||
Circle MakeCircle(double w) {
|
||||
return Circle(w);
|
||||
}
|
||||
|
||||
162
Examples/java/doxygen/example.dsp
Normal file
162
Examples/java/doxygen/example.dsp
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
# Microsoft Developer Studio Project File - Name="example" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=example - Win32 Release
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "example.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "example.mak" CFG="example - Win32 Release"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "example - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "example - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "example - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(JAVA_INCLUDE)" /I "$(JAVA_INCLUDE)\win32" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /out:"example.dll" /pdbtype:sept
|
||||
# Begin Special Build Tool
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Desc=Java compile post-build step
|
||||
PostBuild_Cmds=echo on "%JAVA_BIN%\javac" *.java
|
||||
# End Special Build Tool
|
||||
|
||||
!ELSEIF "$(CFG)" == "example - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /I "$(JAVA_INCLUDE)" /I "$(JAVA_INCLUDE)\win32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386 /out:"example.dll"
|
||||
# Begin Special Build Tool
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Desc=Java compile post-build step
|
||||
PostBuild_Cmds=echo on "%JAVA_BIN%\javac" *.java
|
||||
# End Special Build Tool
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "example - Win32 Debug"
|
||||
# Name "example - Win32 Release"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\example.cxx
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\example_wrap.cxx
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\example.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\example.i
|
||||
|
||||
!IF "$(CFG)" == "example - Win32 Debug"
|
||||
|
||||
# Begin Custom Build
|
||||
InputPath=.\example.i
|
||||
InputName=example
|
||||
|
||||
"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
|
||||
echo In order to function correctly, please ensure the following environment variables are correctly set:
|
||||
echo JAVA_INCLUDE: %JAVA_INCLUDE%
|
||||
echo JAVA_BIN: %JAVA_BIN%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -java "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
!ELSEIF "$(CFG)" == "example - Win32 Release"
|
||||
|
||||
# Begin Custom Build
|
||||
InputPath=.\example.i
|
||||
InputName=example
|
||||
|
||||
"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
|
||||
echo In order to function correctly, please ensure the following environment variables are correctly set:
|
||||
echo JAVA_INCLUDE: %JAVA_INCLUDE%
|
||||
echo JAVA_BIN: %JAVA_BIN%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -java "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
107
Examples/java/doxygen/example.h
Normal file
107
Examples/java/doxygen/example.h
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
/*! \file example.h
|
||||
This file provides a simple set of Shape classes. */
|
||||
|
||||
/*! Base class for all shapes.
|
||||
\author Bob
|
||||
*/
|
||||
class Shape {
|
||||
public:
|
||||
/*! Default constructor for creating a Shape */
|
||||
Shape() {
|
||||
nshapes++;
|
||||
}
|
||||
/*! Destructor for destroying a Shape */
|
||||
virtual ~Shape() {
|
||||
nshapes--;
|
||||
}
|
||||
double x; /*!< x co-ordinate */
|
||||
double y; /*!< y co-ordinate */
|
||||
void move(double dx, double dy); /*!< Move a shape to a new co-ordinate
|
||||
\param dx x co-ordinate
|
||||
\param dy y co-ordinate */
|
||||
virtual double area() = 0; /*!< \return the area */
|
||||
virtual double perimeter() = 0; /*!< \return the perimeter */
|
||||
static int nshapes; /*!< Number of shapes currently in existence */
|
||||
};
|
||||
|
||||
/*! A class for representing a circle.
|
||||
\author Jack
|
||||
*/
|
||||
class Circle : public Shape {
|
||||
private:
|
||||
double radius;
|
||||
public:
|
||||
/*! Construct a circle
|
||||
* \param r radius of the circle */
|
||||
Circle(double r);
|
||||
/*! Calculate the area of the circle
|
||||
* \return calculated area */
|
||||
virtual double area();
|
||||
/*! Calculate the perimeter of the circle
|
||||
* \return calculated perimeter of the circle */
|
||||
virtual double perimeter();
|
||||
};
|
||||
|
||||
/// A class for representing a square.
|
||||
class Square : public Shape {
|
||||
private:
|
||||
double width;
|
||||
public:
|
||||
/** Construct a square
|
||||
* \param w width of the square */
|
||||
Square(double w);
|
||||
/** Calculate the area of the square
|
||||
* \return calculated area */
|
||||
virtual double area();
|
||||
/** Calculate the perimeter of the square
|
||||
* \return calculated perimeter of the square */
|
||||
virtual double perimeter();
|
||||
};
|
||||
|
||||
/// A class for representing a rectangle, templated on the type for the rectangle dimensions
|
||||
template<typename T>
|
||||
class Rectangle : public Shape {
|
||||
private:
|
||||
T height;
|
||||
T width;
|
||||
public:
|
||||
/** Construct a rectangle
|
||||
* \param h height of the rectangle
|
||||
* \param w width of the rectangle */
|
||||
Rectangle(T h, T w) : height(h), width(w) {}
|
||||
/** Calculate the area of the rectangle
|
||||
* \return calculated area */
|
||||
virtual double area() { return width*height; }
|
||||
/** Calculate the perimeter of the rectangle
|
||||
* \return calculated perimeter of the rectangle */
|
||||
virtual double perimeter() { return 2*height + 2*width; }
|
||||
};
|
||||
|
||||
|
||||
/*! Factory function for creating a square
|
||||
* \param r width of the square
|
||||
* \return a fully constructed square */
|
||||
Square MakeSquare(double r);
|
||||
|
||||
/*! Factory function for creating a circle
|
||||
* \param w radius of the circle
|
||||
* \return a fully constructed circle */
|
||||
Circle MakeCircle(double w);
|
||||
|
||||
/*! Factory function for creating a rectangle
|
||||
* \param h height of the rectangle
|
||||
* \param w width of the rectangle
|
||||
* \return a fully constructed rectangle */
|
||||
template<typename T>
|
||||
Rectangle<T> MakeRectangle(T h, T w) {
|
||||
return Rectangle<T>(h, w);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*! Total number of circles ever created */
|
||||
extern int NumCircles;
|
||||
|
||||
/// Total number of squares ever created
|
||||
extern int NumSquares;
|
||||
|
||||
17
Examples/java/doxygen/example.i
Normal file
17
Examples/java/doxygen/example.i
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%immutable NumSquares;
|
||||
%immutable NumCircles;
|
||||
|
||||
%include "example.h"
|
||||
|
||||
/*! - this instantiation uses type int */
|
||||
%template(RectangleInt) Rectangle<int>;
|
||||
|
||||
/*! - this instantiation uses type int */
|
||||
%template(MakeRectangleInt) MakeRectangle<int>;
|
||||
|
||||
63
Examples/java/doxygen/runme.java
Normal file
63
Examples/java/doxygen/runme.java
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
// This example shows simple usage of the wrapped Shape classes.
|
||||
// The main purpose of this example is to show the doxygen comments translation to JavaDoc comments.
|
||||
// Users should look at the generated .java files and if javadoc is installed and working on your system,
|
||||
// the generated Java docs can be viewed in a browser by opening the javadocs/index.html file.
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class runme {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("example");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) throws InterruptedException, IOException
|
||||
{
|
||||
System.out.println("Creating some objects:");
|
||||
Circle c = example.MakeCircle(10);
|
||||
System.out.println(" Created circle " + c);
|
||||
Square s = example.MakeSquare(10);
|
||||
System.out.println(" Created square " + s);
|
||||
RectangleInt r = example.MakeRectangleInt(10, 20);
|
||||
System.out.println(" Created rectangle " + r);
|
||||
|
||||
System.out.println("\nHere are some properties of the shapes:");
|
||||
Shape[] shapes = {c, s, r};
|
||||
for (int i=0; i<shapes.length; i++) {
|
||||
System.out.println(" " + shapes[i].toString());
|
||||
System.out.println(" area = " + shapes[i].area());
|
||||
System.out.println(" perimeter = " + shapes[i].perimeter());
|
||||
}
|
||||
|
||||
String command = "javadoc -quiet -public -d javadocs example.java Shape.java Circle.java Square.java RectangleInt.java";
|
||||
System.out.println("\nRunning: " + command);
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
int exitCode = p.waitFor();
|
||||
System.out.println("javadoc exited with code " + exitCode);
|
||||
|
||||
BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
|
||||
|
||||
String line = null;
|
||||
|
||||
System.out.println("stdout from javadoc:\n");
|
||||
while ((line = stdout.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
}
|
||||
|
||||
System.out.println("\nstderr from javadoc:\n");
|
||||
while ((line = stderr.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
}
|
||||
|
||||
if (exitCode != 0) {
|
||||
System.out.println("No java docs were generated!\n");
|
||||
} else {
|
||||
System.out.println("javadoc ran successfully, open javadocs/index.html in your browser to view the generated java docs.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -76,7 +76,7 @@ public class runme {
|
|||
System.out.println( " Trying to set 'status'" );
|
||||
try {
|
||||
Method m = example.class.getDeclaredMethod("setStatus", new Class[] {Integer.class});
|
||||
m.invoke(example.class, new Object[] {new Integer(0)} );
|
||||
m.invoke(example.class, new Object[] {Integer.valueOf(0)} );
|
||||
System.out.println( "Hey, what's going on?!?! This shouldn't work" );
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ constant
|
|||
enum
|
||||
exception
|
||||
functor
|
||||
native
|
||||
nspace
|
||||
operator
|
||||
overload
|
||||
|
|
|
|||
|
|
@ -30,5 +30,5 @@ f.enum_test(example.Foo.LUDICROUS);
|
|||
// enum value BLUE of enum color is accessed as property of cconst
|
||||
console.log("example.BLUE= " + example.BLUE);
|
||||
|
||||
// enum value LUDICROUS of enum Foo::speed is accessed as as property of cconst
|
||||
// enum value LUDICROUS of enum Foo::speed is accessed as property of cconst
|
||||
console.log("example.speed.LUDICROUS= " + example.Foo.LUDICROUS);
|
||||
|
|
|
|||
|
|
@ -16,30 +16,26 @@ public:
|
|||
char msg[256];
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
class Test {
|
||||
public:
|
||||
int simple() throw(int) {
|
||||
int simple() {
|
||||
throw(37);
|
||||
return 1;
|
||||
}
|
||||
int message() throw(const char *) {
|
||||
int message() {
|
||||
throw("I died.");
|
||||
return 1;
|
||||
}
|
||||
int hosed() throw(Exc) {
|
||||
int hosed() {
|
||||
throw(Exc(42,"Hosed"));
|
||||
return 1;
|
||||
}
|
||||
int unknown() throw(A*) {
|
||||
int unknown() {
|
||||
static A a;
|
||||
throw &a;
|
||||
return 1;
|
||||
}
|
||||
int multi(int x) throw(int, const char *, Exc) {
|
||||
int multi(int x) {
|
||||
if (x == 1) throw(37);
|
||||
if (x == 2) throw("Bleah!");
|
||||
if (x == 3) throw(Exc(42,"No-go-diggy-die"));
|
||||
|
|
@ -47,7 +43,3 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,12 @@
|
|||
|
||||
%include "std_string.i"
|
||||
|
||||
%catches(int) Test::simple();
|
||||
%catches(const char *) Test::message();
|
||||
%catches(Exc) Test::hosed();
|
||||
%catches(A*) Test::unknown();
|
||||
%catches(int, const char *, Exc) Test::multi(int x);
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ try{
|
|||
if(error == -1) {
|
||||
console.log("t.unknown() didn't throw");
|
||||
} else {
|
||||
console.log("successfully catched throw in Test::unknown().");
|
||||
console.log("successfully caught throw in Test::unknown().");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ catch(error){
|
|||
if(error == -1) {
|
||||
console.log("t.simple() did not throw");
|
||||
} else {
|
||||
console.log("successfully catched throw in Test::simple().");
|
||||
console.log("successfully caught throw in Test::simple().");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ try{
|
|||
if(error == -1) {
|
||||
console.log("t.message() did not throw");
|
||||
} else {
|
||||
console.log("successfully catched throw in Test::message().");
|
||||
console.log("successfully caught throw in Test::message().");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ catch(error){
|
|||
if(error == -1) {
|
||||
console.log("t.hosed() did not throw");
|
||||
} else {
|
||||
console.log("successfully catched throw in Test::hosed().");
|
||||
console.log("successfully caught throw in Test::hosed().");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ for (var i=1; i<4; i++) {
|
|||
if(error == -1) {
|
||||
console.log("t.multi(" + i + ") did not throw");
|
||||
} else {
|
||||
console.log("successfully catched throw in Test::multi().");
|
||||
console.log("successfully caught throw in Test::multi().");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
3
Examples/javascript/native/Makefile
Normal file
3
Examples/javascript/native/Makefile
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
SRCS =
|
||||
|
||||
include $(SRCDIR)../example.mk
|
||||
9
Examples/javascript/native/binding.gyp.in
Normal file
9
Examples/javascript/native/binding.gyp.in
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "example",
|
||||
"sources": [ "example_wrap.cxx" ],
|
||||
"include_dirs": ["$srcdir"]
|
||||
}
|
||||
]
|
||||
}
|
||||
47
Examples/javascript/native/example.i
Normal file
47
Examples/javascript/native/example.i
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
// placeholder() used to help SWIG generate "SWIG_From_int" call
|
||||
%{
|
||||
int placeholder();
|
||||
%}
|
||||
int placeholder() { return 0; }
|
||||
|
||||
// actual demo code
|
||||
%wrapper
|
||||
%{
|
||||
#ifdef SWIG_V8_VERSION /* Engine: Node || V8 */
|
||||
|
||||
static SwigV8ReturnValue JavaScript_do_work(const SwigV8Arguments &args) {
|
||||
SWIGV8_HANDLESCOPE();
|
||||
const int MY_MAGIC_NUMBER = 5;
|
||||
SWIGV8_VALUE jsresult =
|
||||
SWIG_From_int(static_cast< int >(MY_MAGIC_NUMBER));
|
||||
if (args.Length() != 0)
|
||||
SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments.");
|
||||
SWIGV8_RETURN(jsresult);
|
||||
fail:
|
||||
SWIGV8_RETURN(SWIGV8_UNDEFINED());
|
||||
}
|
||||
|
||||
#else /* Engine: JavaScriptCore */
|
||||
|
||||
static JSValueRef JavaScript_do_work(JSContextRef context,
|
||||
JSObjectRef function, JSObjectRef thisObject, size_t argc,
|
||||
const JSValueRef argv[], JSValueRef* exception) {
|
||||
const int MY_MAGIC_NUMBER = 5;
|
||||
JSValueRef jsresult =
|
||||
SWIG_From_int SWIG_JSC_FROM_CALL_ARGS(
|
||||
static_cast< int >(MY_MAGIC_NUMBER));
|
||||
if (argc != 0)
|
||||
SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments.");
|
||||
return jsresult;
|
||||
fail:
|
||||
return JSValueMakeUndefined(context);
|
||||
}
|
||||
|
||||
#endif
|
||||
%}
|
||||
|
||||
|
||||
%native(magicNumber) void JavaScript_do_work();
|
||||
1
Examples/javascript/native/example.js
Normal file
1
Examples/javascript/native/example.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
module.exports = require("build/Release/example");
|
||||
31
Examples/javascript/native/index.html
Normal file
31
Examples/javascript/native/index.html
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>SWIG:Examples:javascript:native</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
|
||||
|
||||
<tt>SWIG/Examples/javascript/native/</tt>
|
||||
<hr>
|
||||
|
||||
<H2>Manually wrapped callback function in JavaScript</H2>
|
||||
|
||||
<p>
|
||||
This example demonstrates how to manually add callback feature support to a SWIG module.
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="example.i">example.i</a>. Interface file containing the API function and async behind-the-scenes functions.
|
||||
<li><a href="runme.java">runme.js</a>. Sample JavaScript program showing the API function being called with a callback function parameter.
|
||||
</ul>
|
||||
|
||||
<h2>Notes</h2>
|
||||
|
||||
The V8 code queues the callback request for processing using the UV interface. An async function callback is invoked when the system is ready to process the next request. When the async function finishes, a completion function callback is invoked to finalize the request. Here the callback function parameter is invoked.
|
||||
<br/><br/>
|
||||
UV request queueing is only necessary for operations that would take a really long or otherwise unpredictable amount of time (async operations). A callback parameter could also be invoked immediately within the API function.
|
||||
|
||||
<hr>
|
||||
</body>
|
||||
</html>
|
||||
3
Examples/javascript/native/runme.js
Normal file
3
Examples/javascript/native/runme.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
var example = require("example");
|
||||
|
||||
console.log("My magic number is: ", example.magicNumber());
|
||||
|
|
@ -44,7 +44,7 @@ example.print_vars();
|
|||
|
||||
console.log("\nNow I'm going to try and modify some read only variables");
|
||||
|
||||
console.log("Tring to set 'path'");
|
||||
console.log("Trying to set 'path'");
|
||||
try{
|
||||
example.path = "Whoa!";
|
||||
console.log("Hey, what's going on?!?! This shouldn't work");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
-- lua5.0 doesn't have a nice way to do this
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
-- lua5.0 doesn't have a nice way to do this
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
-- lua5.0 doesn't have a nice way to do this
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ and check to see if types Foo and Bar are registered with it
|
|||
(Bar should be & Foo should not)
|
||||
|
||||
Note: Though both the modules exist and are loaded, they are not linked together,
|
||||
as they are connected to seperate lua interpreters.
|
||||
as they are connected to separate lua interpreters.
|
||||
|
||||
When the third lua state loads both example.i and example2.i,
|
||||
the two modules are now linked together, and all can now find
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/* File : example.h */
|
||||
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#ifndef SWIG
|
||||
struct A {
|
||||
};
|
||||
|
|
@ -16,30 +16,26 @@ public:
|
|||
char msg[256];
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
class Test {
|
||||
public:
|
||||
int simple() throw(int&) {
|
||||
int simple() {
|
||||
throw(37);
|
||||
return 1;
|
||||
}
|
||||
int message() throw(const char *) {
|
||||
int message() {
|
||||
throw("I died.");
|
||||
return 1;
|
||||
}
|
||||
int hosed() throw(Exc) {
|
||||
int hosed() {
|
||||
throw(Exc(42,"Hosed"));
|
||||
return 1;
|
||||
}
|
||||
int unknown() throw(A*) {
|
||||
int unknown() {
|
||||
static A a;
|
||||
throw &a;
|
||||
return 1;
|
||||
}
|
||||
int multi(int x) throw(int, const char *, Exc) {
|
||||
int multi(int x) {
|
||||
if (x == 1) throw(37);
|
||||
if (x == 2) throw("Bleah!");
|
||||
if (x == 3) throw(Exc(42,"No-go-diggy-die"));
|
||||
|
|
@ -47,7 +43,3 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,12 @@
|
|||
// note: only works if Exc is copyable
|
||||
%apply SWIGTYPE EXCEPTION_BY_VAL {Exc};
|
||||
|
||||
%catches(int) Test::simple();
|
||||
%catches(const char *) Test::message();
|
||||
%catches(Exc) Test::hosed();
|
||||
%catches(A*) Test::unknown();
|
||||
%catches(int, const char *, Exc) Test::multi(int x);
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
-- lua5.0 doesn't have a nice way to do this
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
|
|
@ -48,7 +48,7 @@ else
|
|||
end
|
||||
|
||||
-- this is a rather strange way to perform the multiple catch of exceptions
|
||||
print "calling t:mutli()"
|
||||
print "calling t:multi()"
|
||||
for i=1,3 do
|
||||
ok,res=pcall(function() t:multi(i) end)
|
||||
if ok then
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
-- lua5.0 doesn't have a nice way to do this
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
-- lua5.0 doesn't have a nice way to do this
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
-- Operator overloading example
|
||||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
-- lua5.0 doesn't have a nice way to do this
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
print("Testing the %import directive")
|
||||
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
-- lua5.0 doesn't have a nice way to do this
|
||||
function loadit(a)
|
||||
lib=loadlib(a..'.dll','luaopen_'..a) or loadlib(a..'.so','luaopen_'..a)
|
||||
assert(lib)()
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
-- lua5.0 doesn't have a nice way to do this
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@
|
|||
#include "example.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
/* Move the shape to a new location */
|
||||
void Shape::move(double dx, double dy) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
-- Operator overloading example
|
||||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
-- lua5.0 doesn't have a nice way to do this
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
-- lua5.0 doesn't have a nice way to do this
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
-- lua5.0 doesn't have a nice way to do this
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
-- lua5.0 doesn't have a nice way to do this
|
||||
lib=loadlib('example.dll','luaopen_example') or loadlib('example.so','luaopen_example')
|
||||
assert(lib)()
|
||||
else
|
||||
|
|
@ -54,9 +54,9 @@ example.print_vars()
|
|||
|
||||
print "\nNow I'm going to try and modify some read only variables";
|
||||
|
||||
print " Tring to set 'path' to 'Whoa!'";
|
||||
print " Trying to set 'path' to 'Whoa!'";
|
||||
if pcall(function() example.path = "Whoa!" end)==true then
|
||||
print " Thats funny, it didn't give an error!"
|
||||
print " That's funny, it didn't give an error!"
|
||||
else
|
||||
print " It gave an error, as it should"
|
||||
end
|
||||
|
|
@ -64,7 +64,7 @@ print(" Just checking the value: path =", example.path)
|
|||
|
||||
print " Trying to set 'status' to '0'";
|
||||
if pcall(function() example.status = 0 end)==true then
|
||||
print " Thats funny, it didn't give an error!"
|
||||
print " That's funny, it didn't give an error!"
|
||||
else
|
||||
print " It gave an error, as it should"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
# see top-level Makefile.in
|
||||
class
|
||||
multimap
|
||||
simple
|
||||
std_vector
|
||||
|
|
|
|||
|
|
@ -4,17 +4,15 @@ SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
|||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS =
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_run
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||
php5_cpp
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme_cpp
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_clean
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean
|
||||
60
Examples/mzscheme/class/runme.scm
Normal file
60
Examples/mzscheme/class/runme.scm
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
; file: runme.scm
|
||||
|
||||
; This file illustrates the proxy class C++ interface generated
|
||||
; by SWIG.
|
||||
|
||||
(load-extension "example.so")
|
||||
|
||||
; Convenience wrapper around the display function
|
||||
; (which only accepts one argument at the time)
|
||||
|
||||
(define (mdisplay-newline . args)
|
||||
(for-each display args)
|
||||
(newline))
|
||||
|
||||
; ----- Object creation -----
|
||||
|
||||
(mdisplay-newline "Creating some objects:")
|
||||
(define c (new-Circle 10))
|
||||
(mdisplay-newline " Created circle " c)
|
||||
(define s (new-Square 10))
|
||||
(mdisplay-newline " Created square " s)
|
||||
|
||||
; ----- Access a static member -----
|
||||
|
||||
(mdisplay-newline "\nA total of " (Shape-nshapes) " shapes were created")
|
||||
|
||||
; ----- Member data access -----
|
||||
|
||||
; Set the location of the object
|
||||
|
||||
(Shape-x-set c 20)
|
||||
(Shape-y-set c 30)
|
||||
|
||||
(Shape-x-set s -10)
|
||||
(Shape-y-set s 5)
|
||||
|
||||
(mdisplay-newline "\nHere is their current position:")
|
||||
(mdisplay-newline " Circle = (" (Shape-x-get c) "," (Shape-y-get c) ")")
|
||||
(mdisplay-newline " Square = (" (Shape-x-get s) "," (Shape-y-get s) ")")
|
||||
|
||||
; ----- Call some methods -----
|
||||
|
||||
(mdisplay-newline "\nHere are some properties of the shapes:")
|
||||
(define (shape-props o)
|
||||
(mdisplay-newline " " o)
|
||||
(mdisplay-newline " area = " (Shape-area o))
|
||||
(mdisplay-newline " perimeter = " (Shape-perimeter o)))
|
||||
(for-each shape-props (list c s))
|
||||
|
||||
(mdisplay-newline "\nGuess I'll clean up now")
|
||||
|
||||
; Note: this invokes the virtual destructor
|
||||
(delete-Shape c)
|
||||
(delete-Shape s)
|
||||
|
||||
(define s 3)
|
||||
(mdisplay-newline (Shape-nshapes) " shapes remain")
|
||||
(mdisplay-newline "Goodbye")
|
||||
|
||||
(exit 0)
|
||||
|
|
@ -13,5 +13,6 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ int gcdmain(int argc, char *argv[]) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int count(char *bytes, int len, char c) {
|
||||
int charcount(char *bytes, int len, char c) {
|
||||
int i;
|
||||
int count = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
%{
|
||||
extern int gcd(int x, int y);
|
||||
extern int gcdmain(int argc, char *argv[]);
|
||||
extern int count(char *bytes, int len, char c);
|
||||
extern int charcount(char *bytes, int len, char c);
|
||||
extern void capitalize (char *str, int len);
|
||||
extern void circle (double cx, double cy);
|
||||
extern int squareCubed (int n, int *OUTPUT);
|
||||
|
|
@ -50,7 +50,7 @@ extern int gcdmain(int argc, char *argv[]);
|
|||
$2 = SCHEME_STRLEN_VAL($input);
|
||||
}
|
||||
|
||||
extern int count(char *bytes, int len, char c);
|
||||
extern int charcount(char *bytes, int len, char c);
|
||||
|
||||
|
||||
/* This example shows how to wrap a function that mutates a string */
|
||||
|
|
@ -68,7 +68,7 @@ extern int count(char *bytes, int len, char c);
|
|||
|
||||
%typemap(argout) (char *str, int len) {
|
||||
Scheme_Object *s;
|
||||
s = scheme_make_sized_string($1,$2,1);
|
||||
s = scheme_make_sized_string($1,$2);
|
||||
SWIG_APPEND_VALUE(s);
|
||||
free($1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
(gcdmain #("gcdmain" "42" "105"))
|
||||
|
||||
|
||||
(display (count "Hello World" #\l))
|
||||
(display (charcount "Hello World" #\l))
|
||||
(newline)
|
||||
|
||||
(display (capitalize "hello world"))
|
||||
|
|
|
|||
|
|
@ -13,5 +13,6 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
Simple example from users manual.
|
||||
|
|
@ -1,24 +1,18 @@
|
|||
/* Simple example from documentation */
|
||||
/* File : example.c */
|
||||
|
||||
#include <time.h>
|
||||
/* A global variable */
|
||||
double Foo = 3.0;
|
||||
|
||||
double My_variable = 3.0;
|
||||
|
||||
/* Compute factorial of n */
|
||||
int fact(int n) {
|
||||
if (n <= 1) return 1;
|
||||
else return n*fact(n-1);
|
||||
}
|
||||
|
||||
/* Compute n mod m */
|
||||
int my_mod(int n, int m) {
|
||||
return (n % m);
|
||||
/* Compute the greatest common divisor of positive integers */
|
||||
int gcd(int x, int y) {
|
||||
int g;
|
||||
g = y;
|
||||
while (x > 0) {
|
||||
g = x;
|
||||
x = y % x;
|
||||
y = g;
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
|
||||
char *get_time() {
|
||||
long ltime;
|
||||
time(<ime);
|
||||
return ctime(<ime);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,7 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%{
|
||||
/* Put headers and other declarations here */
|
||||
%}
|
||||
|
||||
%include typemaps.i
|
||||
|
||||
%rename(mod) my_mod;
|
||||
|
||||
%inline %{
|
||||
extern double My_variable;
|
||||
extern int fact(int);
|
||||
extern int my_mod(int n, int m);
|
||||
extern char *get_time();
|
||||
extern int gcd(int x, int y);
|
||||
extern double Foo;
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -2,23 +2,30 @@
|
|||
|
||||
(load-extension "example.so")
|
||||
|
||||
(display (get-time))
|
||||
; Call our gcd() function
|
||||
|
||||
(printf "My-variable = ~a~n" (my-variable))
|
||||
(define x 42)
|
||||
(define y 105)
|
||||
(define g (gcd x y))
|
||||
(display "The gcd of ")
|
||||
(display x)
|
||||
(display " and ")
|
||||
(display y)
|
||||
(display " is ")
|
||||
(display g)
|
||||
(newline)
|
||||
|
||||
(let loop ((i 0))
|
||||
(when (< i 14) (begin (display i)
|
||||
(display " factorial is ")
|
||||
(display (fact i))
|
||||
(newline)
|
||||
(loop (+ i 1)))))
|
||||
; Manipulate the Foo global variable
|
||||
|
||||
(let loop ((i 1))
|
||||
(when (< i 250)
|
||||
(begin
|
||||
(let loopi ((j 1))
|
||||
(when (< j 250) (begin (my-variable (+ (my-variable) (mod i j)))
|
||||
(loopi (+ j 1)))))
|
||||
(loop (+ i 1)))))
|
||||
; Output its current value
|
||||
(display "Foo = ")
|
||||
(display (Foo))
|
||||
(newline)
|
||||
|
||||
(printf "My-variable = ~a~n" (my-variable))
|
||||
; Change its value
|
||||
(Foo 3.1415926)
|
||||
|
||||
; See if the change took effect
|
||||
(display "Foo = ")
|
||||
(display (Foo))
|
||||
(newline)
|
||||
|
|
|
|||
|
|
@ -1,21 +1,18 @@
|
|||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SRCS =
|
||||
CXXSRCS =
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
SWIGOPT =
|
||||
|
||||
GPP = `which g++`
|
||||
MZC = test -n "/usr/bin/mzc" && /usr/bin/mzc
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_run
|
||||
|
||||
build:
|
||||
$(SWIGEXE) -mzscheme -c++ $(SWIGOPT) $(INTERFACE)
|
||||
$(MZC) --compiler $(GPP) ++ccf "-I." --cc example_wrap.cxx
|
||||
$(MZC) --linker $(GPP) --ld $(TARGET).so example_wrap.o
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' mzscheme_cpp
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' mzscheme_clean
|
||||
|
|
|
|||
|
|
@ -17,9 +17,8 @@ std::vector<double> half(const std::vector<double>& v) {
|
|||
}
|
||||
|
||||
void halve_in_place(std::vector<double>& v) {
|
||||
// would you believe this is the same as the above?
|
||||
std::transform(v.begin(),v.end(),v.begin(),
|
||||
std::bind2nd(std::divides<double>(),2.0));
|
||||
for (std::vector<double>::iterator it = v.begin(); it != v.end(); ++it)
|
||||
*it /= 2.0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,16 +9,17 @@
|
|||
(if (< i size)
|
||||
(begin
|
||||
(proc v i)
|
||||
(with-vector-item v (+ i 1)))))
|
||||
(with-vector-item v (+ i 1)))
|
||||
(void)))
|
||||
(with-vector-item v 0)))
|
||||
|
||||
(define (with-intvector v proc)
|
||||
(with-vector v proc intvector-length))
|
||||
(define (with-doublevector v proc)
|
||||
(with-vector v proc doublevector-length))
|
||||
(define (with-IntVector v proc)
|
||||
(with-vector v proc IntVector-length))
|
||||
(define (with-DoubleVector v proc)
|
||||
(with-vector v proc DoubleVector-length))
|
||||
|
||||
(define (print-doublevector v)
|
||||
(with-doublevector v (lambda (v i) (display (doublevector-ref v i))
|
||||
(define (print-DoubleVector v)
|
||||
(with-DoubleVector v (lambda (v i) (display (DoubleVector-ref v i))
|
||||
(display " ")))
|
||||
(newline))
|
||||
|
||||
|
|
@ -29,11 +30,11 @@
|
|||
(newline)
|
||||
|
||||
; ... or a wrapped std::vector<int>
|
||||
(define v (new-intvector 4))
|
||||
(with-intvector v (lambda (v i) (intvector-set! v i (+ i 1))))
|
||||
(define v (new-IntVector 4))
|
||||
(with-IntVector v (lambda (v i) (IntVector-set! v i (+ i 1))))
|
||||
(display (average v))
|
||||
(newline)
|
||||
(delete-intvector v)
|
||||
(delete-IntVector v)
|
||||
|
||||
; half will return a Scheme vector.
|
||||
; Call it with a Scheme vector...
|
||||
|
|
@ -42,13 +43,12 @@
|
|||
(newline)
|
||||
|
||||
; ... or a wrapped std::vector<double>
|
||||
(define v (new-doublevector))
|
||||
(map (lambda (i) (doublevector-push! v i)) '(1 2 3 4))
|
||||
(define v (new-DoubleVector))
|
||||
(map (lambda (i) (DoubleVector-push! v i)) '(1 2 3 4))
|
||||
(display (half v))
|
||||
(newline)
|
||||
|
||||
; now halve a wrapped std::vector<double> in place
|
||||
(halve-in-place v)
|
||||
(print-doublevector v)
|
||||
(delete-doublevector v)
|
||||
|
||||
(print-DoubleVector v)
|
||||
(delete-DoubleVector v)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
|||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
MLFILE = example.ml
|
||||
PROGFILE = example_prog.ml
|
||||
PROGFILE = runme.ml
|
||||
OBJS = example.o
|
||||
|
||||
check: build
|
||||
|
|
@ -16,16 +15,20 @@ build: static
|
|||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
|
||||
PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||
ocaml_core
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||
PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
|
||||
ocaml_static_cpp
|
||||
|
||||
dynamic:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' MLFILE='$(MLFILE)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||
PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
|
||||
ocaml_dynamic_cpp
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' MLFILE='$(MLFILE)' ocaml_clean
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_clean
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%typemap(argout) (const int &x, const int &y) {
|
||||
swig_result = caml_list_append(swig_result, caml_val_int(*$1));
|
||||
swig_result = caml_list_append(swig_result, caml_val_int(*$2));
|
||||
}
|
||||
|
||||
%{
|
||||
extern "C" void factor(int &x, int &y);
|
||||
extern "C" void factor(const int &x, const int &y);
|
||||
%}
|
||||
|
||||
extern "C" void factor(int &x, int &y);
|
||||
extern "C" void factor(const int &x, const int &y);
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
(* example_prog.ml *)
|
||||
|
||||
open Swig
|
||||
open Example
|
||||
|
||||
exception BadReturn
|
||||
|
||||
let _ = if Array.length Sys.argv < 3 then
|
||||
begin
|
||||
print_endline
|
||||
("Usage: " ^ Sys.argv.(0) ^ " n1 n2\n" ^
|
||||
" Displays the least factors of the numbers that have the same\n" ^
|
||||
" relationship, 16 12 -> 4 3\n") ;
|
||||
exit 0
|
||||
end
|
||||
|
||||
let x = int_of_string Sys.argv.(1)
|
||||
let y = int_of_string Sys.argv.(2)
|
||||
let (xf,yf) = match _factor '((x to int),(y to int)) with
|
||||
C_list [ C_int a ; C_int b ] -> a,b
|
||||
| _ -> raise BadReturn
|
||||
let _ = print_endline
|
||||
("Factorization of " ^ (string_of_int x) ^
|
||||
" and " ^ (string_of_int y) ^
|
||||
" is " ^ (string_of_int xf) ^
|
||||
" and " ^ (string_of_int yf))
|
||||
17
Examples/ocaml/argout_ref/runme.ml
Normal file
17
Examples/ocaml/argout_ref/runme.ml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
(* runme.ml *)
|
||||
|
||||
open Swig
|
||||
open Example
|
||||
|
||||
exception BadReturn
|
||||
|
||||
let x = if Array.length Sys.argv > 1 then int_of_string Sys.argv.(1) else 16
|
||||
let y = if Array.length Sys.argv > 2 then int_of_string Sys.argv.(2) else 12
|
||||
let (xf,yf) = match _factor '((x to int),(y to int)) with
|
||||
C_list [ C_int a ; C_int b ] -> a,b
|
||||
| _ -> raise BadReturn
|
||||
let _ = print_endline
|
||||
("Factorization of " ^ (string_of_int x) ^
|
||||
" and " ^ (string_of_int y) ^
|
||||
" is " ^ (string_of_int xf) ^
|
||||
" and " ^ (string_of_int yf))
|
||||
35
Examples/ocaml/callback/Makefile
Normal file
35
Examples/ocaml/callback/Makefile
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT =
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
PROGFILE = runme.ml
|
||||
OBJS = example.o
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run
|
||||
|
||||
build: static
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||
ocaml_core
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||
PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
|
||||
ocaml_static_cpp
|
||||
|
||||
toplevel:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||
PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
|
||||
ocaml_static_cpp_toplevel
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_clean
|
||||
3
Examples/ocaml/callback/example.c
Normal file
3
Examples/ocaml/callback/example.c
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
/* File : example.c */
|
||||
|
||||
#include "example.h"
|
||||
|
|
@ -4,13 +4,12 @@
|
|||
|
||||
class Callback {
|
||||
public:
|
||||
virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; }
|
||||
virtual ~Callback() { std::cout << "Callback::~Callback()" << std::endl; }
|
||||
virtual void run() { std::cout << "Callback::run()" << std::endl; }
|
||||
};
|
||||
|
||||
|
||||
class Caller {
|
||||
private:
|
||||
Callback *_callback;
|
||||
public:
|
||||
Caller(): _callback(0) {}
|
||||
|
|
@ -19,4 +18,3 @@ public:
|
|||
void setCallback(Callback *cb) { delCallback(); _callback = cb; }
|
||||
void call() { if (_callback) _callback->run(); }
|
||||
};
|
||||
|
||||
|
|
@ -4,7 +4,6 @@
|
|||
#include "example.h"
|
||||
%}
|
||||
|
||||
/* turn on director wrapping Callback */
|
||||
%feature("director") Callback;
|
||||
|
||||
%include "example.h"
|
||||
30
Examples/ocaml/callback/runme.ml
Normal file
30
Examples/ocaml/callback/runme.ml
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
(* file: runme.ml
|
||||
|
||||
This file illustrates cross-language polymorphism using directors. *)
|
||||
|
||||
open Swig
|
||||
open Example
|
||||
|
||||
let new_OCamlCallback ob meth args =
|
||||
match meth with
|
||||
| "run" -> print_endline "OCamlCallback.run()"; C_void
|
||||
| _ -> (invoke ob) meth args
|
||||
|
||||
let caller = new_Caller '()
|
||||
|
||||
let _ = print_endline "Adding and calling a normal C++ callback"
|
||||
let _ = print_endline "----------------------------------------"
|
||||
|
||||
let callback = new_Callback '()
|
||||
let _ = caller -> "setCallback" (callback)
|
||||
let _ = caller -> "call" ()
|
||||
let _ = caller -> "delCallback" ()
|
||||
|
||||
let _ = print_endline "\nAdding and calling an OCaml callback"
|
||||
let _ = print_endline "------------------------------------"
|
||||
|
||||
let callback = new_derived_object new_Callback (new_OCamlCallback) '()
|
||||
let _ = caller -> "setCallback" (callback)
|
||||
let _ = caller -> "call" ()
|
||||
let _ = caller -> "delCallback" ()
|
||||
let _ = print_endline "\nOCaml exit"
|
||||
|
|
@ -1,10 +1,13 @@
|
|||
# see top-level Makefile.in
|
||||
simple
|
||||
std_string
|
||||
std_vector
|
||||
stl
|
||||
argout_ref
|
||||
shapes
|
||||
callback
|
||||
class
|
||||
contract
|
||||
scoped_enum
|
||||
shapes
|
||||
simple
|
||||
#std_string
|
||||
std_vector
|
||||
stl
|
||||
string_from_ptr
|
||||
strings_test
|
||||
|
|
|
|||
35
Examples/ocaml/class/Makefile
Normal file
35
Examples/ocaml/class/Makefile
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
SWIGOPT =
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
PROGFILE = runme.ml
|
||||
OBJS = example.o
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_run
|
||||
|
||||
build: static
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
PROGFILE='$(PROGFILE)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||
ocaml_core
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||
PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
|
||||
ocaml_static_cpp
|
||||
|
||||
toplevel:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||
PROGFILE='$(PROGFILE)' OBJS='$(OBJS)' \
|
||||
ocaml_static_cpp_toplevel
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' ocaml_clean
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
#include "example.h"
|
||||
/* File : example.c */
|
||||
|
||||
#include "example.h"
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
/* Move the shape to a new location */
|
||||
|
|
@ -10,21 +11,18 @@ void Shape::move(double dx, double dy) {
|
|||
|
||||
int Shape::nshapes = 0;
|
||||
|
||||
double Circle::area(void) {
|
||||
/* return -1 is to test post-assertion */
|
||||
if (radius == 1)
|
||||
return -1;
|
||||
double Circle::area() {
|
||||
return M_PI*radius*radius;
|
||||
}
|
||||
|
||||
double Circle::perimeter(void) {
|
||||
double Circle::perimeter() {
|
||||
return 2*M_PI*radius;
|
||||
}
|
||||
|
||||
double Square::area(void) {
|
||||
double Square::area() {
|
||||
return width*width;
|
||||
}
|
||||
|
||||
double Square::perimeter(void) {
|
||||
double Square::perimeter() {
|
||||
return 4*width;
|
||||
}
|
||||
|
|
@ -8,10 +8,10 @@ public:
|
|||
virtual ~Shape() {
|
||||
nshapes--;
|
||||
}
|
||||
double x, y;
|
||||
double x, y;
|
||||
void move(double dx, double dy);
|
||||
virtual double area(void) = 0;
|
||||
virtual double perimeter(void) = 0;
|
||||
virtual double area() = 0;
|
||||
virtual double perimeter() = 0;
|
||||
static int nshapes;
|
||||
};
|
||||
|
||||
|
|
@ -20,8 +20,8 @@ private:
|
|||
double radius;
|
||||
public:
|
||||
Circle(double r) : radius(r) { }
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
virtual double area();
|
||||
virtual double perimeter();
|
||||
};
|
||||
|
||||
class Square : public Shape {
|
||||
|
|
@ -29,6 +29,6 @@ private:
|
|||
double width;
|
||||
public:
|
||||
Square(double w) : width(w) { }
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
virtual double area();
|
||||
virtual double perimeter();
|
||||
};
|
||||
|
|
@ -5,8 +5,5 @@
|
|||
#include "example.h"
|
||||
%}
|
||||
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
|
||||
%include "example.h"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue