added some pointer support and fixed style problem

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11415 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Baozeng Ding 2009-07-17 16:21:54 +00:00
commit 93a0308e21
14 changed files with 368 additions and 244 deletions

View file

@ -1152,8 +1152,14 @@ SCILAB = @SCILAB@
scilab: $(SRCS)
$(SWIG) -scilab $(SWIGOPT) $(INTERFACEPATH)
# -----------------------------------------------------------------
# Running a Scilab example
# -----------------------------------------------------------------
scilab_run:
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH SCILABPATH=$(srcdir):$$SCILABPATH $(SCILAB) -nwni < runme.sci
# -----------------------------------------------------------------
# Cleaning the scilab examples
# -----------------------------------------------------------------

View file

@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
SRCS = example.c
SRCS = example.i
TARGET = example
INTERFACE = example.i

View file

@ -1,30 +1,6 @@
/* File : example.i */
%module example
%{
extern void add(int *, int *, int *);
extern void sub(int *, int *, int *);
extern int divide(int, int, int *);
%}
/* This example illustrates a couple of different techniques
for manipulating C pointers */
/* First we'll use the pointer library */
extern void add(int *x, int *y, int *result);
%include cpointer.i
%pointer_functions(int, intp);
/* Next we'll use some typemaps */
%include typemaps.i
extern void sub(int *INPUT, int *INPUT, int *OUTPUT);
/* Next we'll use typemaps and the %apply directive */
%apply int *OUTPUT { int *r };
extern int divide(int n, int d, int *r);
FILE *fopen(char *filename, char *mode);
int fputs(char* , FILE *);
int fclose(FILE *);

View file

@ -1,6 +1,6 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
SRCS = example.c
SRCS = example.i
TARGET = example
INTERFACE = example.i

View file

@ -20,3 +20,5 @@ try
catch
printf("FOO is not defined (good)\n");
end
exit

View file

@ -32,3 +32,7 @@ y=105;
g=gcd(x,y);
printf("The gcd of %d and %d is %d\n",x,y,g);
exit

View file

@ -20,3 +20,5 @@ enum_test(color.BLUE);
enum_test(color.GREEN);
enum_test(1234);
exit

View file

@ -18,3 +18,5 @@ printf("Testing multiple return values\n");
[q,r] = divide(42,37);
printf(" 42/37 = %d remainder %d\n",q,r);
exit

View file

@ -22,3 +22,5 @@ Foo_set(3.1415926)
// See if the change took effect
Foo_get()
exit

View file

@ -23,9 +23,12 @@ char cvar = 0;
float fvar = 0;
double dvar = 0;
char *strvar=0;
char name[5] = "Dave";
double *Foo1;
double *Foo2;
int *pivar;
short *psvar;
char **foo;
/* A debugging function to print out their values */
@ -43,6 +46,7 @@ void print_vars() {
printf("dvar = %g\n", dvar);
printf("cvar = %c\n", cvar);
printf("strvar = %s\n",strvar);
printf("name = %c%c%c%c%c\n", name[0],name[1],name[2],name[3],name[4]);
}

View file

@ -17,8 +17,12 @@
extern float fvar;
extern double dvar;
extern char *strvar;
extern char name[256];
extern double *Foo1;
extern double *Foo2;
extern int *pivar;
extern short *psvar;
extern char **foo;
%}

View file

@ -18,8 +18,16 @@ cvar_set ("S");
fvar_set (3.14159);
dvar_set (2.1828);
strvar_set("Hello World");
name_set ("Bill");
Foo1_set([1,2,3;4,5,6]);
Foo2_set([1+2*%i,2+3*%i;3+4*%i,7+8*%i]);
pivar_set(int32([ 1 2 3 4 5;
6 7 8 9 10;
11 12 13 14 15]));
psvar_set(int16([ 1 2 3 4 5;
6 7 8 9 10;
11 12 13 14 15]));
foo_set(["sample", "strings", "manipulation"; "with","gateway","API"]);
// Now print out the values of the variables
@ -37,10 +45,16 @@ printf("fvar = %f\n", fvar_get());
printf("dvar = %f\n", dvar_get());
printf("cvar = %s\n", cvar_get());
printf("strvar = %s\n", strvar_get());
printf("name = %s\n", name_get());
Foo1_get()
Foo2_get()
pivar_get()
psvar_get()
foo_get()
printf("\nVariables (values printed from C)\n");
print_vars();
print_vars()
exit