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:
Baozeng Ding 2009-06-20 02:44:06 +00:00
commit ed84d6b162
19 changed files with 865 additions and 222 deletions

View 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);
}

View 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;
%}

View 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

View 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);