* New version for Scilab module using fragments
* A C and CPP tests generate and compile except tests using vectors (to be done) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@12698 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6db40d8378
commit
a8b8b6c5d4
41 changed files with 2679 additions and 2557 deletions
|
|
@ -5,7 +5,7 @@ contract
|
|||
enum
|
||||
funcptr
|
||||
matrix
|
||||
matrix2
|
||||
#matrix2
|
||||
pointer
|
||||
simple
|
||||
struct
|
||||
|
|
|
|||
|
|
@ -1,19 +1,42 @@
|
|||
// loader the *.so
|
||||
exec loader.sce
|
||||
|
||||
//Now try the typemap library
|
||||
//This should be much easier. Now how it is no longer
|
||||
//necessary to manufacture pointers.
|
||||
// First create some objects using the pointer library.
|
||||
printf("Testing the pointer library\n")
|
||||
a = new_intp();
|
||||
b = new_intp();
|
||||
c = new_intp(); // Memory for result
|
||||
|
||||
intp_assign(a, 37);
|
||||
intp_assign(b, 42);
|
||||
|
||||
printf(" a = %d\n", intp_value(a));
|
||||
printf(" b = %d\n", intp_value(b));
|
||||
printf(" c = %d\n", intp_value(c));
|
||||
|
||||
// Call the add() function with some pointers
|
||||
add(a, b, c);
|
||||
|
||||
// Now get the result
|
||||
r = intp_value(c);
|
||||
printf(" 37 + 42 = %d\n", r);
|
||||
|
||||
// Clean up the pointers
|
||||
delete_intp(a);
|
||||
delete_intp(b);
|
||||
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 = sub(37,42);
|
||||
printf(" 37 - 42 = %i\n",r);
|
||||
|
||||
//Now try the version with multiple return values
|
||||
r = sub(37, 42);
|
||||
printf(" 37 - 42 = %d\n", r);
|
||||
|
||||
// Now try the version with multiple return values
|
||||
printf("Testing multiple return values\n");
|
||||
[q,r] = divide(42,37);
|
||||
printf(" 42/37 = %d remainder %d\n",q,r);
|
||||
[q, r] = divide(42, 37);
|
||||
printf(" 42/37 = %d remainder %d\n", q, r);
|
||||
|
||||
exit
|
||||
|
||||
|
|
|
|||
|
|
@ -8,15 +8,11 @@ y = 105;
|
|||
g = gcd(x,y);
|
||||
printf("The gcd of %d and %d is %d\n",x,y,g);
|
||||
|
||||
x = [42 43];
|
||||
y = 105;
|
||||
g = 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
|
||||
Foo_get()
|
||||
// Get its default value (see in example.c)
|
||||
defaultValue = Foo_get()
|
||||
if defaultValue <> 3 then pause; end
|
||||
|
||||
// Change its value
|
||||
Foo_set(3.1415926)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ exec loader.sce
|
|||
//create a struct
|
||||
a=new_Bar();
|
||||
Bar_x_set(a,100);
|
||||
Bar_x_get(a)
|
||||
printf("a.x = %d (Sould be 100)\n", Bar_x_get(a));
|
||||
|
||||
exit
|
||||
|
||||
|
|
|
|||
|
|
@ -52,9 +52,9 @@ void print_vars() {
|
|||
printf("cvar = %c\n", cvar);
|
||||
printf("strvar = %s\n", strvar ? strvar : "(null)");
|
||||
printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)");
|
||||
printf("iptrvar = %p\n", iptrvar);
|
||||
printf("iptrvar = %i\n", value_int(iptrvar));
|
||||
printf("name = %c%c%c%c%c\n", name[0],name[1],name[2],name[3],name[4]);
|
||||
//printf("ptptr = %p %s\n", ptptr, Point_print( ptptr ) );
|
||||
printf("ptptr = %p (%d, %d)\n", ptptr, ptptr->x, ptptr->y);
|
||||
printf("pt = (%d, %d)\n", pt.x, pt.y);
|
||||
printf("status = %d\n", status);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
extern float fvar;
|
||||
extern double dvar;
|
||||
extern char *strvar;
|
||||
// extern const char cstrvar[];
|
||||
extern const char cstrvar[];
|
||||
extern int *iptrvar;
|
||||
extern char name[256];
|
||||
|
||||
|
|
@ -45,6 +45,7 @@ extern char path[256];
|
|||
%inline %{
|
||||
extern void print_vars();
|
||||
extern int *new_int(int value);
|
||||
extern int value_int(int *value);
|
||||
extern Point *new_Point(int x, int y);
|
||||
extern char *Point_print(Point *p);
|
||||
extern void pt_print();
|
||||
|
|
|
|||
|
|
@ -1,28 +1,27 @@
|
|||
lines(0);
|
||||
|
||||
//loader the *.so
|
||||
exec loader.sce
|
||||
|
||||
// Try to set the values of some global variables
|
||||
|
||||
ivar_set (42);
|
||||
svar_set (31000);
|
||||
lvar_set (65537);
|
||||
uivar_set (123456);
|
||||
usvar_set (61000);
|
||||
ulvar_set (654321);
|
||||
scvar_set (-13);
|
||||
ucvar_set (251);
|
||||
cvar_set ("S");
|
||||
fvar_set (3.14159);
|
||||
dvar_set (2.1828);
|
||||
ivar_set(42);
|
||||
svar_set(-31000);
|
||||
lvar_set(65537);
|
||||
uivar_set(uint32(123456));
|
||||
usvar_set(uint16(61000));
|
||||
ulvar_set(654321);
|
||||
scvar_set(int8(-13));
|
||||
ucvar_set(uint8(251));
|
||||
cvar_set("S");
|
||||
fvar_set(3.14159);
|
||||
dvar_set(2.1828);
|
||||
strvar_set("Hello World");
|
||||
iptrvar_set(new_int(37));
|
||||
ptptr_set(new_Point(37,42));
|
||||
name_set("Bill");
|
||||
|
||||
//iptrvar= new_int(37);
|
||||
ptptr = new_Point(37,42);
|
||||
name_set ("Bill");
|
||||
// Now print out the values of the variables
|
||||
|
||||
printf("Variables (values printed from Scilab)\n");
|
||||
|
||||
printf("ivar = %i\n", ivar_get());
|
||||
printf("svar = %i\n", svar_get());
|
||||
printf("lvar = %i\n", lvar_get());
|
||||
|
|
@ -35,13 +34,37 @@ printf("fvar = %f\n", fvar_get());
|
|||
printf("dvar = %f\n", dvar_get());
|
||||
printf("cvar = %s\n", cvar_get());
|
||||
printf("strvar = %s\n", strvar_get());
|
||||
|
||||
//iptrvar
|
||||
printf("cstrvar = %s\n", cstrvar_get());
|
||||
printf("iptrvar = %i\n", value_int(iptrvar_get()));
|
||||
printf("name = %s\n", name_get());
|
||||
printf("ptptr = %s\n", Point_print(ptptr));
|
||||
printf("\nVariables (values printed from C)\n");
|
||||
printf("ptptr = %s\n", Point_print(ptptr_get()));
|
||||
printf("pt = %s\n", Point_print(pt_get()));
|
||||
printf("status = %d\n", status_get());
|
||||
|
||||
printf("\nVariables (values printed from C)\n");
|
||||
print_vars()
|
||||
|
||||
// Immutable variables
|
||||
printf("\nNow I''m going to try and modify some read only variables\n");
|
||||
printf(" Tring to set ''path''\n");
|
||||
try
|
||||
path_set("Whoa!");
|
||||
printf("Hey, what''s going on?!?! This shouldn''t work\n");
|
||||
catch
|
||||
printf("Good.\n");
|
||||
end
|
||||
printf(" Trying to set ''status''\n");
|
||||
try
|
||||
status_set(0);
|
||||
printf("Hey, what''s going on?!?! This shouldn''t work\n");
|
||||
catch
|
||||
printf("Good.\n");
|
||||
end
|
||||
|
||||
// Structure
|
||||
printf("\nI''m going to try and update a structure variable.\n");
|
||||
pt_set(ptptr_get());
|
||||
printf("The new value is %s\n", Point_print(pt_get()));
|
||||
|
||||
exit
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue