Fixes to Octave examples
- rename example modules from "example" to "swigexample", to avoid a warning from shadowing the Octave built-in function "example" - remove deprecated "static" Makefile targets: there is no longer an option to build static Octave modules in the Examples Makefile - emacs whitespace cleanup run on all files
This commit is contained in:
parent
7964ebe34f
commit
c28d0c6c80
63 changed files with 211 additions and 345 deletions
|
|
@ -1,10 +1,10 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile octave_run
|
||||
|
|
@ -13,9 +13,5 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
/* File : example.cxx */
|
||||
|
||||
#include "example.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -20,4 +20,3 @@ public:
|
|||
void setCallback(Callback *cb) { delCallback(); _callback = cb; }
|
||||
void call() { if (_callback) _callback->run(); }
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module(directors="1") example
|
||||
%module(directors="1") swigexample
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
|
@ -10,4 +10,3 @@
|
|||
%feature("director") Callback;
|
||||
|
||||
%include "example.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -2,14 +2,13 @@
|
|||
|
||||
# This file illustrates the cross language polymorphism using directors.
|
||||
|
||||
example
|
||||
swigexample
|
||||
|
||||
OctCallback=@() subclass(example.Callback(), \
|
||||
'run',@(self) printf("OctCallback.run()\n"));
|
||||
OctCallback=@() subclass(swigexample.Callback(),"run",@(self) printf("OctCallback.run()\n"));
|
||||
|
||||
# Create an Caller instance
|
||||
|
||||
caller = example.Caller();
|
||||
caller = swigexample.Caller();
|
||||
|
||||
# Add a simple C++ callback (caller owns the callback, so
|
||||
# we disown it first)
|
||||
|
|
@ -17,7 +16,7 @@ caller = example.Caller();
|
|||
printf("Adding and calling a normal C++ callback\n");
|
||||
printf("----------------------------------------\n");
|
||||
|
||||
callback = example.Callback().__disown();
|
||||
callback = swigexample.Callback().__disown();
|
||||
caller.setCallback(callback);
|
||||
caller.call();
|
||||
caller.delCallback();
|
||||
|
|
@ -43,7 +42,7 @@ caller.call();
|
|||
caller.delCallback();
|
||||
|
||||
# careful-- using callback here may cause problems; octave_swig_type still
|
||||
# exists, but is holding a destroyed object (the C++ example.Callback).
|
||||
# exists, but is holding a destroyed object (the C++ swigexample.Callback).
|
||||
# to manually drop the octave-side reference, you can use
|
||||
clear callback;
|
||||
|
||||
|
|
@ -60,4 +59,3 @@ a.Callback.run();
|
|||
# All done.
|
||||
|
||||
printf("octave exit\n");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile octave_run
|
||||
|
|
@ -13,9 +13,5 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ 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;
|
||||
|
|
@ -32,8 +32,3 @@ public:
|
|||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%module swigexample
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
|
|
@ -7,4 +7,3 @@
|
|||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -3,17 +3,17 @@
|
|||
# This file illustrates the proxy class C++ interface generated
|
||||
# by SWIG.
|
||||
|
||||
example
|
||||
swigexample
|
||||
|
||||
# ----- Object creation -----
|
||||
|
||||
printf("Creating some objects:\n");
|
||||
c = example.Circle(10)
|
||||
s = example.Square(10)
|
||||
c = swigexample.Circle(10)
|
||||
s = swigexample.Square(10)
|
||||
|
||||
# ----- Access a static member -----
|
||||
|
||||
printf("\nA total of %i shapes were created\n", example.Shape.nshapes);
|
||||
printf("\nA total of %i shapes were created\n", swigexample.Shape.nshapes);
|
||||
|
||||
# ----- Member data access -----
|
||||
|
||||
|
|
@ -46,7 +46,5 @@ printf("\nGuess I'll clean up now\n");
|
|||
clear c
|
||||
clear s
|
||||
|
||||
printf("%i shapes remain\n", example.Shape.nshapes);
|
||||
printf("%i shapes remain\n", swigexample.Shape.nshapes);
|
||||
printf("Goodbye\n");
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS =
|
||||
TARGET = example
|
||||
CXXSRCS =
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile octave_run
|
||||
|
|
@ -13,9 +13,5 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%module swigexample
|
||||
|
||||
/* A few preprocessor macros */
|
||||
|
||||
|
|
@ -23,5 +23,3 @@
|
|||
|
||||
%constant int iconst = 37;
|
||||
%constant double fconst = 3.14;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,29 +1,25 @@
|
|||
# file: runme.m
|
||||
|
||||
example
|
||||
swigexample
|
||||
|
||||
printf("ICONST = %i (should be 42)\n", example.ICONST);
|
||||
printf("FCONST = %f (should be 2.1828)\n", example.FCONST);
|
||||
printf("CCONST = %s (should be 'x')\n", example.CCONST);
|
||||
printf("CCONST2 = %s (this should be on a new line)\n", example.CCONST2);
|
||||
printf("SCONST = %s (should be 'Hello World')\n", example.SCONST);
|
||||
printf("SCONST2 = %s (should be '\"Hello World\"')\n", example.SCONST2);
|
||||
printf("EXPR = %f (should be 48.5484)\n", example.EXPR);
|
||||
printf("iconst = %i (should be 37)\n", example.iconst);
|
||||
printf("fconst = %f (should be 3.14)\n", example.fconst);
|
||||
printf("ICONST = %i (should be 42)\n", swigexample.ICONST);
|
||||
printf("FCONST = %f (should be 2.1828)\n", swigexample.FCONST);
|
||||
printf("CCONST = %s (should be 'x')\n", swigexample.CCONST);
|
||||
printf("CCONST2 = %s (this should be on a new line)\n", swigexample.CCONST2);
|
||||
printf("SCONST = %s (should be 'Hello World')\n", swigexample.SCONST);
|
||||
printf("SCONST2 = %s (should be '\"Hello World\"')\n", swigexample.SCONST2);
|
||||
printf("EXPR = %f (should be 48.5484)\n", swigexample.EXPR);
|
||||
printf("iconst = %i (should be 37)\n", swigexample.iconst);
|
||||
printf("fconst = %f (should be 3.14)\n", swigexample.fconst);
|
||||
|
||||
try
|
||||
printf("EXTERN = %s (Arg! This shouldn't printf(anything)\n", example.EXTERN);
|
||||
printf("EXTERN = %s (Arg! This shouldn't printf(anything)\n", swigexample.EXTERN);
|
||||
catch
|
||||
printf("EXTERN isn't defined (good)\n");
|
||||
end_try_catch
|
||||
|
||||
try
|
||||
printf("FOO = %i (Arg! This shouldn't printf(anything)\n", example.FOO);
|
||||
printf("FOO = %i (Arg! This shouldn't printf(anything)\n", swigexample.FOO);
|
||||
catch
|
||||
printf("FOO isn't defined (good)\n");
|
||||
end_try_catch
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
|
||||
check: build
|
||||
|
|
@ -11,9 +11,5 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
|
|
|
|||
|
|
@ -19,5 +19,3 @@ int fact(int n) {
|
|||
if (n <= 0) return 1;
|
||||
return n*fact(n-1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%module swigexample
|
||||
|
||||
%contract gcd(int x, int y) {
|
||||
require:
|
||||
|
|
|
|||
|
|
@ -1,22 +1,21 @@
|
|||
# file: runme.m
|
||||
|
||||
example
|
||||
swigexample
|
||||
|
||||
# Call our gcd() function
|
||||
|
||||
x = 42;
|
||||
y = 105;
|
||||
g = example.gcd(x,y);
|
||||
g = swigexample.gcd(x,y);
|
||||
printf("The gcd of %d and %d is %d\n",x,y,g);
|
||||
|
||||
# Manipulate the Foo global variable
|
||||
|
||||
# Output its current value
|
||||
printf("Foo = %f\n", example.cvar.Foo);
|
||||
printf("Foo = %f\n", swigexample.cvar.Foo);
|
||||
|
||||
# Change its value
|
||||
example.cvar.Foo = 3.1415926;
|
||||
swigexample.cvar.Foo = 3.1415926;
|
||||
|
||||
# See if the change took effect
|
||||
printf("Foo = %f\n", example.cvar.Foo);
|
||||
|
||||
printf("Foo = %f\n", swigexample.cvar.Foo);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile octave_run
|
||||
|
|
@ -13,9 +13,5 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
|
|
|
|||
|
|
@ -10,4 +10,3 @@ class Foo {
|
|||
};
|
||||
|
||||
void enum_test(color c, Foo::speed s);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%module swigexample
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
|
|
@ -8,4 +8,3 @@
|
|||
/* Let's just grab the original header file here */
|
||||
|
||||
%include "example.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,32 +1,30 @@
|
|||
# file: runme.m
|
||||
|
||||
example
|
||||
swigexample
|
||||
|
||||
# ----- Object creation -----
|
||||
|
||||
# Print out the value of some enums
|
||||
printf("*** color ***\n");
|
||||
printf(" RED = %i\n", example.RED);
|
||||
printf(" BLUE = %i\n", example.BLUE);
|
||||
printf(" GREEN = %i\n", example.GREEN);
|
||||
printf(" RED = %i\n", swigexample.RED);
|
||||
printf(" BLUE = %i\n", swigexample.BLUE);
|
||||
printf(" GREEN = %i\n", swigexample.GREEN);
|
||||
|
||||
printf("\n*** Foo::speed ***\n");
|
||||
printf(" Foo_IMPULSE = %i\n", example.Foo_IMPULSE);
|
||||
printf(" Foo_WARP = %i\n", example.Foo_WARP);
|
||||
printf(" Foo_LUDICROUS = %i\n", example.Foo_LUDICROUS);
|
||||
printf(" Foo_IMPULSE = %i\n", swigexample.Foo_IMPULSE);
|
||||
printf(" Foo_WARP = %i\n", swigexample.Foo_WARP);
|
||||
printf(" Foo_LUDICROUS = %i\n", swigexample.Foo_LUDICROUS);
|
||||
|
||||
printf("\nTesting use of enums with functions\n");
|
||||
|
||||
example.enum_test(example.RED, example.Foo_IMPULSE);
|
||||
example.enum_test(example.BLUE, example.Foo_WARP);
|
||||
example.enum_test(example.GREEN, example.Foo_LUDICROUS);
|
||||
example.enum_test(1234,5678)
|
||||
swigexample.enum_test(swigexample.RED, swigexample.Foo_IMPULSE);
|
||||
swigexample.enum_test(swigexample.BLUE, swigexample.Foo_WARP);
|
||||
swigexample.enum_test(swigexample.GREEN, swigexample.Foo_LUDICROUS);
|
||||
swigexample.enum_test(1234,5678)
|
||||
|
||||
printf("\nTesting use of enum with class method\n");
|
||||
f = example.Foo();
|
||||
|
||||
f.enum_test(example.Foo_IMPULSE);
|
||||
f.enum_test(example.Foo_WARP);
|
||||
f.enum_test(example.Foo_LUDICROUS);
|
||||
|
||||
f = swigexample.Foo();
|
||||
|
||||
f.enum_test(swigexample.Foo_IMPULSE);
|
||||
f.enum_test(swigexample.Foo_WARP);
|
||||
f.enum_test(swigexample.Foo_LUDICROUS);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile octave_run
|
||||
|
|
@ -13,9 +13,5 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
/* File : example.cxx */
|
||||
|
||||
#include "example.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public:
|
|||
const Employee *get_item(int i) {
|
||||
return list[i];
|
||||
}
|
||||
~EmployeeList() {
|
||||
~EmployeeList() {
|
||||
std::vector<Employee*>::iterator i;
|
||||
std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl;
|
||||
for (i=list.begin(); i!=list.end(); i++) {
|
||||
|
|
@ -53,4 +53,3 @@ public:
|
|||
std::cout << "~EmployeeList empty." << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module(directors="1") example
|
||||
%module(directors="1") swigexample
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
|
@ -12,4 +12,3 @@
|
|||
%feature("director") Manager;
|
||||
|
||||
%include "example.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
# This file illustrates the cross language polymorphism using directors.
|
||||
|
||||
example
|
||||
swigexample
|
||||
|
||||
|
||||
# CEO class, which overrides Employee::getPosition().
|
||||
|
||||
CEO=@(name) subclass(example.Manager(name),'getPosition',@(self) "CEO");
|
||||
CEO=@(name) subclass(swigexample.Manager(name),'getPosition',@(self) "CEO");
|
||||
|
||||
# Create an instance of our employee extension class, CEO. The calls to
|
||||
# getName() and getPosition() are standard, the call to getTitle() uses
|
||||
|
|
@ -22,7 +22,7 @@ printf("----------------------\n");
|
|||
# Create a new EmployeeList instance. This class does not have a C++
|
||||
# director wrapper, but can be used freely with other classes that do.
|
||||
|
||||
list = example.EmployeeList();
|
||||
list = swigexample.EmployeeList();
|
||||
|
||||
# EmployeeList owns its items, so we must surrender ownership of objects
|
||||
# we add. This involves first calling the __disown__ method to tell the
|
||||
|
|
@ -71,4 +71,3 @@ printf("----------------------\n");
|
|||
# All done.
|
||||
|
||||
printf("octave exit\n");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
|
||||
check: build
|
||||
|
|
@ -11,9 +11,5 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
|
|
|
|||
|
|
@ -6,4 +6,3 @@ extern int sub(int,int);
|
|||
extern int mul(int,int);
|
||||
|
||||
extern int (*funcvar)(int,int);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%module swigexample
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
|
@ -13,4 +13,3 @@ extern int do_op(int a, int b, int (*op)(int, int));
|
|||
%constant int (*MUL)(int,int) = mul;
|
||||
|
||||
extern int (*funcvar)(int,int);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# file: runme.m
|
||||
|
||||
example
|
||||
swigexample
|
||||
|
||||
a = 37
|
||||
b = 42
|
||||
|
|
@ -10,12 +10,11 @@ b = 42
|
|||
printf("Trying some C callback functions\n");
|
||||
printf(" a = %i\n", a);
|
||||
printf(" b = %i\n", b);
|
||||
printf(" ADD(a,b) = %i\n", example.do_op(a,b,example.ADD));
|
||||
printf(" SUB(a,b) = %i\n", example.do_op(a,b,example.SUB));
|
||||
printf(" MUL(a,b) = %i\n", example.do_op(a,b,example.MUL));
|
||||
printf(" ADD(a,b) = %i\n", swigexample.do_op(a,b,swigexample.ADD));
|
||||
printf(" SUB(a,b) = %i\n", swigexample.do_op(a,b,swigexample.SUB));
|
||||
printf(" MUL(a,b) = %i\n", swigexample.do_op(a,b,swigexample.MUL));
|
||||
|
||||
printf("Here is what the C callback function objects look like in Octave\n");
|
||||
example.ADD
|
||||
example.SUB
|
||||
example.MUL
|
||||
|
||||
swigexample.ADD
|
||||
swigexample.SUB
|
||||
swigexample.MUL
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
|
||||
check: build
|
||||
|
|
@ -11,9 +11,5 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
|
|
|
|||
|
|
@ -6,4 +6,3 @@ extern int sub(int,int);
|
|||
extern int mul(int,int);
|
||||
|
||||
extern int (*funcvar)(int,int);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%module swigexample
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
|
@ -15,4 +15,3 @@ int mul(int, int);
|
|||
%nocallback;
|
||||
|
||||
extern int (*funcvar)(int,int);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# file: runme.m
|
||||
|
||||
example
|
||||
swigexample
|
||||
|
||||
a = 37
|
||||
b = 42
|
||||
|
|
@ -10,15 +10,15 @@ b = 42
|
|||
printf("Trying some C callback functions\n");
|
||||
printf(" a = %i\n", a);
|
||||
printf(" b = %i\n", b);
|
||||
printf(" ADD(a,b) = %i\n", example.do_op(a,b,example.ADD));
|
||||
printf(" SUB(a,b) = %i\n", example.do_op(a,b,example.SUB));
|
||||
printf(" MUL(a,b) = %i\n", example.do_op(a,b,example.MUL));
|
||||
printf(" ADD(a,b) = %i\n", swigexample.do_op(a,b,swigexample.ADD));
|
||||
printf(" SUB(a,b) = %i\n", swigexample.do_op(a,b,swigexample.SUB));
|
||||
printf(" MUL(a,b) = %i\n", swigexample.do_op(a,b,swigexample.MUL));
|
||||
|
||||
printf("Here is what the C callback function objects look like in Octave\n");
|
||||
example.ADD
|
||||
example.SUB
|
||||
example.MUL
|
||||
swigexample.ADD
|
||||
swigexample.SUB
|
||||
swigexample.MUL
|
||||
|
||||
printf("Call the functions directly...\n");
|
||||
printf(" add(a,b) = %i\n", example.add(a,b));
|
||||
printf(" sub(a,b) = %i\n", example.sub(a,b));
|
||||
printf(" add(a,b) = %i\n", swigexample.add(a,b));
|
||||
printf(" sub(a,b) = %i\n", swigexample.sub(a,b));
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS =
|
||||
TARGET = example
|
||||
CXXSRCS =
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile octave_run
|
||||
|
|
@ -13,9 +13,5 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%module swigexample
|
||||
|
||||
|
||||
%inline %{
|
||||
|
|
@ -23,7 +23,3 @@ public:
|
|||
// Instantiate a few versions
|
||||
%template(intSum) Sum<int>;
|
||||
%template(doubleSum) Sum<double>;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# Operator overloading example
|
||||
example
|
||||
swigexample
|
||||
|
||||
a = example.intSum(0);
|
||||
b = example.doubleSum(100.0);
|
||||
a = swigexample.intSum(0);
|
||||
b = swigexample.doubleSum(100.0);
|
||||
|
||||
# Use the objects. They should be callable just like a normal
|
||||
# python function.
|
||||
|
|
@ -14,5 +14,3 @@ endfor
|
|||
|
||||
a.result()
|
||||
b.result()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
|
||||
check: build
|
||||
|
|
@ -13,10 +13,6 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)2' SWIGOPT='-module $$(TARGET) -globals .' INTERFACE='$(INTERFACE)' octave
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
rm -f $(TARGET).m
|
||||
|
|
|
|||
|
|
@ -2,60 +2,60 @@
|
|||
|
||||
# load module
|
||||
clear all;
|
||||
example;
|
||||
swigexample;
|
||||
assert(cvar.ivar == ifunc);
|
||||
assert(exist("example","var"));
|
||||
assert(exist("swigexample","var"));
|
||||
clear all
|
||||
example;
|
||||
swigexample;
|
||||
assert(cvar.ivar == ifunc);
|
||||
assert(exist("example","var"));
|
||||
assert(exist("swigexample","var"));
|
||||
clear all
|
||||
|
||||
# load module in a function globally before base context
|
||||
clear all;
|
||||
function testme
|
||||
example;
|
||||
swigexample;
|
||||
assert(cvar.ivar == ifunc);
|
||||
assert(exist("example","var"));
|
||||
assert(exist("swigexample","var"));
|
||||
endfunction
|
||||
testme
|
||||
testme
|
||||
example;
|
||||
swigexample;
|
||||
assert(cvar.ivar == ifunc);
|
||||
assert(exist("example","var"));
|
||||
assert(exist("swigexample","var"));
|
||||
clear all
|
||||
function testme
|
||||
example;
|
||||
swigexample;
|
||||
assert(cvar.ivar == ifunc);
|
||||
assert(exist("example","var"));
|
||||
assert(exist("swigexample","var"));
|
||||
endfunction
|
||||
testme
|
||||
testme
|
||||
example;
|
||||
swigexample;
|
||||
assert(cvar.ivar == ifunc);
|
||||
assert(exist("example","var"));
|
||||
assert(exist("swigexample","var"));
|
||||
clear all
|
||||
|
||||
# load module in a function globally after base context
|
||||
clear all;
|
||||
example;
|
||||
swigexample;
|
||||
assert(cvar.ivar == ifunc);
|
||||
assert(exist("example","var"));
|
||||
assert(exist("swigexample","var"));
|
||||
function testme
|
||||
example;
|
||||
swigexample;
|
||||
assert(cvar.ivar == ifunc);
|
||||
assert(exist("example","var"));
|
||||
assert(exist("swigexample","var"));
|
||||
endfunction
|
||||
testme
|
||||
testme
|
||||
clear all
|
||||
example;
|
||||
swigexample;
|
||||
assert(cvar.ivar == ifunc);
|
||||
assert(exist("example","var"));
|
||||
assert(exist("swigexample","var"));
|
||||
function testme
|
||||
example;
|
||||
swigexample;
|
||||
assert(cvar.ivar == ifunc);
|
||||
assert(exist("example","var"));
|
||||
assert(exist("swigexample","var"));
|
||||
endfunction
|
||||
testme
|
||||
testme
|
||||
|
|
@ -69,13 +69,13 @@ endif
|
|||
|
||||
# load module with no cvar
|
||||
clear all;
|
||||
example2;
|
||||
assert(example2.ivar == ifunc);
|
||||
assert(exist("example2","var"));
|
||||
swigexample2;
|
||||
assert(swigexample2.ivar == ifunc);
|
||||
assert(exist("swigexample2","var"));
|
||||
assert(!isglobal("cvar"))
|
||||
clear all
|
||||
example2;
|
||||
assert(example2.ivar == ifunc);
|
||||
assert(exist("example2","var"));
|
||||
swigexample2;
|
||||
assert(swigexample2.ivar == ifunc);
|
||||
assert(exist("swigexample2","var"));
|
||||
assert(!isglobal("cvar"))
|
||||
clear all
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS =
|
||||
TARGET = example
|
||||
CXXSRCS =
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile octave_run
|
||||
|
|
@ -13,9 +13,5 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public:
|
|||
ComplexVal operator-() const {
|
||||
return ComplexVal(-rpart, -ipart);
|
||||
}
|
||||
|
||||
|
||||
double re() const { return rpart; }
|
||||
double im() const { return ipart; }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%module swigexample
|
||||
#pragma SWIG nowarn=SWIGWARN_IGNORE_OPERATOR_EQ
|
||||
%{
|
||||
#include "example.h"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# Operator overloading example
|
||||
example
|
||||
swigexample
|
||||
|
||||
a = example.ComplexVal(2,3);
|
||||
b = example.ComplexVal(-5,10);
|
||||
a = swigexample.ComplexVal(2,3);
|
||||
b = swigexample.ComplexVal(-5,10);
|
||||
|
||||
printf("a = %s\n",disp(a));
|
||||
printf("b = %s\n",disp(b));
|
||||
|
|
@ -12,7 +12,7 @@ printf("c = %s\n",disp(c));
|
|||
printf("a*b = %s\n",disp(a*b));
|
||||
printf("a-c = %s\n",disp(a-c));
|
||||
|
||||
e = example.ComplexVal(a-c);
|
||||
e = swigexample.ComplexVal(a-c);
|
||||
printf("e = %s\n",disp(e));
|
||||
|
||||
# Big expression
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
|
||||
check: build
|
||||
|
|
@ -11,9 +11,5 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%module swigexample
|
||||
|
||||
%{
|
||||
extern void add(int *, int *, int *);
|
||||
|
|
@ -24,7 +24,3 @@ extern void sub(int *INPUT, int *INPUT, int *OUTPUT);
|
|||
|
||||
%apply int *OUTPUT { int *r };
|
||||
extern int divide(int n, int d, int *r);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,42 +1,39 @@
|
|||
# file: runme.m
|
||||
|
||||
example;
|
||||
swigexample;
|
||||
|
||||
# First create some objects using the pointer library.
|
||||
printf("Testing the pointer library\n");
|
||||
a = example.new_intp();
|
||||
b = example.new_intp();
|
||||
c = example.new_intp();
|
||||
example.intp_assign(a,37);
|
||||
example.intp_assign(b,42);
|
||||
a = swigexample.new_intp();
|
||||
b = swigexample.new_intp();
|
||||
c = swigexample.new_intp();
|
||||
swigexample.intp_assign(a,37);
|
||||
swigexample.intp_assign(b,42);
|
||||
|
||||
a,b,c
|
||||
|
||||
# Call the add() function with some pointers
|
||||
example.add(a,b,c);
|
||||
swigexample.add(a,b,c);
|
||||
|
||||
# Now get the result
|
||||
r = example.intp_value(c);
|
||||
r = swigexample.intp_value(c);
|
||||
printf(" 37 + 42 = %i\n",r);
|
||||
|
||||
# Clean up the pointers
|
||||
example.delete_intp(a);
|
||||
example.delete_intp(b);
|
||||
example.delete_intp(c);
|
||||
swigexample.delete_intp(a);
|
||||
swigexample.delete_intp(b);
|
||||
swigexample.delete_intp(c);
|
||||
|
||||
# Now try the typemap library
|
||||
# This should be much easier. Now how it is no longer
|
||||
# necessary to manufacture pointers.
|
||||
|
||||
printf("Trying the typemap library\n");
|
||||
r = example.sub(37,42);
|
||||
r = swigexample.sub(37,42);
|
||||
printf(" 37 - 42 = %i\n",r);
|
||||
|
||||
# Now try the version with multiple return values
|
||||
|
||||
printf("Testing multiple return values\n");
|
||||
[q,r] = example.divide(42,37);
|
||||
[q,r] = swigexample.divide(42,37);
|
||||
printf(" 42/37 = %d remainder %d\n",q,r);
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile octave_run
|
||||
|
|
@ -13,9 +13,5 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
|
|
|
|||
|
|
@ -43,4 +43,3 @@ Vector &VectorArray::operator[](int index) {
|
|||
int VectorArray::size() {
|
||||
return maxsize;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,3 @@ public:
|
|||
Vector &operator[](int);
|
||||
int size();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/* This file has a few "typical" uses of C++ references. */
|
||||
|
||||
%module example
|
||||
%module swigexample
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
|
|
@ -31,7 +31,7 @@ public:
|
|||
VectorArray(int maxsize);
|
||||
~VectorArray();
|
||||
int size();
|
||||
|
||||
|
||||
/* This wrapper provides an alternative to the [] operator */
|
||||
%extend {
|
||||
Vector &get(int index) {
|
||||
|
|
@ -42,7 +42,3 @@ public:
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
# This file illustrates the manipulation of C++ references in Octave
|
||||
|
||||
example
|
||||
swigexample
|
||||
|
||||
# ----- Object creation -----
|
||||
|
||||
printf("Creating some objects:\n");
|
||||
a = example.Vector(3,4,5)
|
||||
b = example.Vector(10,11,12)
|
||||
a = swigexample.Vector(3,4,5)
|
||||
b = swigexample.Vector(10,11,12)
|
||||
|
||||
printf(" Created %s\n",a.cprint());
|
||||
printf(" Created %s\n",b.cprint());
|
||||
|
|
@ -17,12 +17,12 @@ printf(" Created %s\n",b.cprint());
|
|||
|
||||
# This calls the wrapper we placed around
|
||||
#
|
||||
# operator+(const Vector &a, const Vector &)
|
||||
# operator+(const Vector &a, const Vector &)
|
||||
#
|
||||
# It returns a new allocated object.
|
||||
|
||||
printf("Adding a+b\n");
|
||||
c = example.addv(a,b);
|
||||
c = swigexample.addv(a,b);
|
||||
printf(" a+b = %s\n", c.cprint());
|
||||
|
||||
clear c
|
||||
|
|
@ -31,7 +31,7 @@ clear c
|
|||
|
||||
# Note: Using the high-level interface here
|
||||
printf("Creating an array of vectors\n");
|
||||
va = example.VectorArray(10)
|
||||
va = swigexample.VectorArray(10)
|
||||
|
||||
# ----- Set some values in the array -----
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ va = example.VectorArray(10)
|
|||
va.set(0,a);
|
||||
va.set(1,b);
|
||||
|
||||
va.set(2,example.addv(a,b))
|
||||
va.set(2,swigexample.addv(a,b))
|
||||
|
||||
# Get some values from the array
|
||||
|
||||
|
|
@ -60,4 +60,3 @@ printf("Cleaning up\n");
|
|||
clear va
|
||||
clear a
|
||||
clear b
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
|
||||
check: build
|
||||
|
|
@ -11,9 +11,5 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
|
|
|
|||
|
|
@ -14,5 +14,3 @@ int gcd(int x, int y) {
|
|||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%module swigexample
|
||||
|
||||
%inline %{
|
||||
extern int gcd(int x, int y);
|
||||
|
|
|
|||
|
|
@ -1,22 +1,21 @@
|
|||
# file: runme.m
|
||||
|
||||
example
|
||||
swigexample
|
||||
|
||||
# Call our gcd() function
|
||||
|
||||
x = 42
|
||||
y = 105
|
||||
g = example.gcd(x,y)
|
||||
g = swigexample.gcd(x,y)
|
||||
printf("The gcd of %d and %d is %d\n",x,y,g);
|
||||
|
||||
# Manipulate the Foo global variable
|
||||
|
||||
# Output its current value
|
||||
example.cvar.Foo
|
||||
swigexample.cvar.Foo
|
||||
|
||||
# Change its value
|
||||
example.cvar.Foo = 3.1415926
|
||||
swigexample.cvar.Foo = 3.1415926
|
||||
|
||||
# See if the change took effect
|
||||
printf("Foo = %f\n", example.cvar.Foo);
|
||||
|
||||
printf("Foo = %f\n", swigexample.cvar.Foo);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS =
|
||||
TARGET = example
|
||||
CXXSRCS =
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile octave_run
|
||||
|
|
@ -13,9 +13,5 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
|
|
|
|||
|
|
@ -29,4 +29,3 @@ template<class T> class vector {
|
|||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%module swigexample
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
|
|
@ -14,4 +14,3 @@
|
|||
%template(maxdouble) max<double>;
|
||||
%template(vecint) vector<int>;
|
||||
%template(vecdouble) vector<double>;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
# file: runme.m
|
||||
|
||||
example
|
||||
swigexample
|
||||
|
||||
# Call some templated functions
|
||||
example.maxint(3,7)
|
||||
example.maxdouble(3.14,2.18)
|
||||
swigexample.maxint(3,7)
|
||||
swigexample.maxdouble(3.14,2.18)
|
||||
|
||||
# Create some class
|
||||
|
||||
iv = example.vecint(100)
|
||||
dv = example.vecdouble(1000)
|
||||
iv = swigexample.vecint(100)
|
||||
dv = swigexample.vecdouble(1000)
|
||||
|
||||
for i=0:99,
|
||||
iv.setitem(i,2*i);
|
||||
|
|
@ -33,5 +33,3 @@ sum
|
|||
|
||||
clear iv
|
||||
clear dv
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
TARGET = swigexample
|
||||
INTERFACE = example.i
|
||||
|
||||
check: build
|
||||
|
|
@ -11,9 +11,5 @@ build:
|
|||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
#include <stdlib.h>
|
||||
#include "example.h"
|
||||
|
||||
int ivar = 0;
|
||||
int ivar = 0;
|
||||
short svar = 0;
|
||||
long lvar = 0;
|
||||
unsigned int uivar = 0;
|
||||
|
|
|
|||
|
|
@ -3,4 +3,3 @@
|
|||
typedef struct {
|
||||
int x,y;
|
||||
} Point;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%module swigexample
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
|
@ -50,4 +50,3 @@ extern Point *new_Point(int x, int y);
|
|||
extern char *Point_print(Point *p);
|
||||
extern void pt_print();
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,56 +1,56 @@
|
|||
# file: runme.m
|
||||
|
||||
example
|
||||
swigexample
|
||||
|
||||
# Try to set the values of some global variables
|
||||
|
||||
example.cvar.ivar = 42;
|
||||
example.cvar.svar = -31000;
|
||||
example.cvar.lvar = 65537;
|
||||
example.cvar.uivar = 123456;
|
||||
example.cvar.usvar = 61000;
|
||||
example.cvar.ulvar = 654321;
|
||||
example.cvar.scvar = -13;
|
||||
example.cvar.ucvar = 251;
|
||||
example.cvar.cvar = "S";
|
||||
example.cvar.fvar = 3.14159;
|
||||
example.cvar.dvar = 2.1828;
|
||||
example.cvar.strvar = "Hello World";
|
||||
example.cvar.iptrvar= example.new_int(37);
|
||||
example.cvar.ptptr = example.new_Point(37,42);
|
||||
example.cvar.name = "Bill";
|
||||
swigexample.cvar.ivar = 42;
|
||||
swigexample.cvar.svar = -31000;
|
||||
swigexample.cvar.lvar = 65537;
|
||||
swigexample.cvar.uivar = 123456;
|
||||
swigexample.cvar.usvar = 61000;
|
||||
swigexample.cvar.ulvar = 654321;
|
||||
swigexample.cvar.scvar = -13;
|
||||
swigexample.cvar.ucvar = 251;
|
||||
swigexample.cvar.cvar = "S";
|
||||
swigexample.cvar.fvar = 3.14159;
|
||||
swigexample.cvar.dvar = 2.1828;
|
||||
swigexample.cvar.strvar = "Hello World";
|
||||
swigexample.cvar.iptrvar= swigexample.new_int(37);
|
||||
swigexample.cvar.ptptr = swigexample.new_Point(37,42);
|
||||
swigexample.cvar.name = "Bill";
|
||||
|
||||
# Now print out the values of the variables
|
||||
|
||||
printf("Variables (values printed from Octave)\n");
|
||||
|
||||
printf("ivar = %i\n", example.cvar.ivar);
|
||||
printf("svar = %i\n", example.cvar.svar);
|
||||
printf("lvar = %i\n", example.cvar.lvar);
|
||||
printf("uivar = %i\n", example.cvar.uivar);
|
||||
printf("usvar = %i\n", example.cvar.usvar);
|
||||
printf("ulvar = %i\n", example.cvar.ulvar);
|
||||
printf("scvar = %i\n", example.cvar.scvar);
|
||||
printf("ucvar = %i\n", example.cvar.ucvar);
|
||||
printf("fvar = %i\n", example.cvar.fvar);
|
||||
printf("dvar = %i\n", example.cvar.dvar);
|
||||
printf("cvar = %s\n", example.cvar.cvar);
|
||||
printf("strvar = %s\n", example.cvar.strvar);
|
||||
#printf("cstrvar = %s\n", example.cvar.cstrvar);
|
||||
example.cvar.iptrvar
|
||||
printf("name = %i\n", example.cvar.name);
|
||||
printf("ptptr = %s\n", example.Point_print(example.cvar.ptptr));
|
||||
#printf("pt = %s\n", example.cvar.Point_print(example.cvar.pt));
|
||||
printf("ivar = %i\n", swigexample.cvar.ivar);
|
||||
printf("svar = %i\n", swigexample.cvar.svar);
|
||||
printf("lvar = %i\n", swigexample.cvar.lvar);
|
||||
printf("uivar = %i\n", swigexample.cvar.uivar);
|
||||
printf("usvar = %i\n", swigexample.cvar.usvar);
|
||||
printf("ulvar = %i\n", swigexample.cvar.ulvar);
|
||||
printf("scvar = %i\n", swigexample.cvar.scvar);
|
||||
printf("ucvar = %i\n", swigexample.cvar.ucvar);
|
||||
printf("fvar = %i\n", swigexample.cvar.fvar);
|
||||
printf("dvar = %i\n", swigexample.cvar.dvar);
|
||||
printf("cvar = %s\n", swigexample.cvar.cvar);
|
||||
printf("strvar = %s\n", swigexample.cvar.strvar);
|
||||
#printf("cstrvar = %s\n", swigexample.cvar.cstrvar);
|
||||
swigexample.cvar.iptrvar
|
||||
printf("name = %i\n", swigexample.cvar.name);
|
||||
printf("ptptr = %s\n", swigexample.Point_print(swigexample.cvar.ptptr));
|
||||
#printf("pt = %s\n", swigexample.cvar.Point_print(swigexample.cvar.pt));
|
||||
|
||||
printf("\nVariables (values printed from C)\n");
|
||||
|
||||
example.print_vars();
|
||||
swigexample.print_vars();
|
||||
|
||||
printf("\nNow I'm going to try and modify some read only variables\n");
|
||||
|
||||
printf(" Tring to set 'path'\n");
|
||||
try
|
||||
example.cvar.path = "Whoa!";
|
||||
swigexample.cvar.path = "Whoa!";
|
||||
printf("Hey, what's going on?!?! This shouldn't work\n");
|
||||
catch
|
||||
printf("Good.\n");
|
||||
|
|
@ -58,7 +58,7 @@ end_try_catch
|
|||
|
||||
printf(" Trying to set 'status'\n");
|
||||
try
|
||||
example.cvar.status = 0;
|
||||
swigexample.cvar.status = 0;
|
||||
printf("Hey, what's going on?!?! This shouldn't work\n");
|
||||
catch
|
||||
printf("Good.\n");
|
||||
|
|
@ -67,9 +67,6 @@ end_try_catch
|
|||
|
||||
printf("\nI'm going to try and update a structure variable.\n");
|
||||
|
||||
example.cvar.pt = example.cvar.ptptr;
|
||||
|
||||
printf("The new value is %s\n", example.Point_print(example.cvar.pt));
|
||||
|
||||
|
||||
swigexample.cvar.pt = swigexample.cvar.ptptr;
|
||||
|
||||
printf("The new value is %s\n", swigexample.Point_print(swigexample.cvar.pt));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue