add support for Enums
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11288 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
4e9cbd8a7c
commit
ed84d6b162
19 changed files with 865 additions and 222 deletions
23
Examples/scilab/contract/example.c
Normal file
23
Examples/scilab/contract/example.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* File : example.c */
|
||||
|
||||
/* A global variable */
|
||||
double Foo = 3.0;
|
||||
|
||||
/* 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 fact(int n) {
|
||||
if (n <= 0) return 1;
|
||||
return n*fact(n-1);
|
||||
}
|
||||
|
||||
|
||||
21
Examples/scilab/contract/example.i
Normal file
21
Examples/scilab/contract/example.i
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%contract gcd(int x, int y) {
|
||||
require:
|
||||
x >= 0;
|
||||
y >= 0;
|
||||
}
|
||||
|
||||
%contract fact(int n) {
|
||||
require:
|
||||
n >= 0;
|
||||
ensure:
|
||||
fact >= 1;
|
||||
}
|
||||
|
||||
%inline %{
|
||||
extern int gcd(int x, int y);
|
||||
extern int fact(int n);
|
||||
extern double Foo;
|
||||
%}
|
||||
15
Examples/scilab/contract/makefile
Normal file
15
Examples/scilab/contract/makefile
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile scilab_clean
|
||||
rm -f *.sce *.so lib*lib.c
|
||||
|
||||
check: all
|
||||
34
Examples/scilab/contract/runme.sci
Normal file
34
Examples/scilab/contract/runme.sci
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// builder the *.so
|
||||
exec builder.sce;
|
||||
|
||||
// loader the *.so
|
||||
exec loader.sce;
|
||||
|
||||
// Call our gcd() function
|
||||
x = 42;
|
||||
y = 105;
|
||||
g = gcd(x,y);
|
||||
printf("The gcd of %d and %d is %d\n",x,y,g);
|
||||
|
||||
// Call our fact() function
|
||||
x=5;
|
||||
g=fact(x);
|
||||
printf("The fact of %d is %d",x,g);
|
||||
|
||||
// Manipulate the Foo global variable
|
||||
|
||||
// Output its current value
|
||||
printf("Foo = %f\n",Foo_get());
|
||||
|
||||
// Change its value
|
||||
Foo_set (3.1415926);
|
||||
|
||||
// See if the change took effect
|
||||
printf("Foo = %f\n", Foo_get());
|
||||
|
||||
//Call our gcd() function to test the contract conditon
|
||||
x=-42;
|
||||
y=105;
|
||||
g=gcd(x,y);
|
||||
printf("The gcd of %d and %d is %d\n",x,y,g);
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue