diff --git a/Doc/Manual/Scilab.html b/Doc/Manual/Scilab.html index 40f3544e2..d759786b1 100644 --- a/Doc/Manual/Scilab.html +++ b/Doc/Manual/Scilab.html @@ -27,6 +27,7 @@
-Scilab is a scientific software package for numerical computations providing a powerful open computing environment for engineering and scientific applications that is mostly compatible with MATLAB. More information can be found at www.scilab.org. +Scilab is a scientific software package for numerical computations providing a powerful open computing environment for engineering and scientific applications that is mostly compatible with MATLAB. More information can be found at www.scilab.org.
-This chapter explains how to use SWIG for Scilab. After this introduction, you should be able to generate with SWIG a Scilab external module from a C/C++ library. +This chapter explains how to use SWIG for Scilab. After this introduction, you should be able to generate with SWIG a Scilab external module from a C/C++ library.
@@ -333,11 +334,63 @@ Creates a built-in function fact(n) that works exactly like you think i ans=24 -+The following table give for each C/C++ primitive type the equivalent Scilab type. +
+ +| C/C++ type | +Scilab type | +
| bool | boolean |
| char | string |
| signed char | double or int8 |
| unsigned char | uint8 |
| short | double or int16 |
| unsigned short | uint16 |
| int | double or int32 |
| unsigned int | uint32 |
| long | double or int32 |
| unsigned long | uint32 |
| signed long long | not supported with Scilab 5.x |
| unsigned long long | not supported with Scilab 5.x |
| float | double |
| double | double |
| char* or char[] | string |
+Notes: +
+The default mapped type for C/C++ non-primitive types is the Scilab pointer. That is the case for exemple for C structs, C++ classes, ... +But there are many type mappings for non-primitive types (such as enums, arrays, STL types, etc...). Each of them is described further in this document. +
+ +- To expose variables, SWIG actually generates two functions, to get and set the value. In this case, Foo_set and Foo_get would be generated. SWIG then automatically calls these functions when you get and set the variable-- in the former case creating a local copy in the interpreter of the C variables, and in the latter case copying an interpreter variable value into the C variable. + To expose variables, SWIG actually generates two functions, to get and set the value. In this case, Foo_set and Foo_get would be generated. SWIG then automatically calls these functions when you get and set the variable-- in the former case creating a local copy in the interpreter of the C variables, and in the latter case copying an interpreter variable value into the C variable.
@@ -353,11 +406,11 @@ c = 3 ans = 4
- C constants are not really constant in Scilab. When dealing with the constants, a get function will be generated. For example given some constants: + C constants are not really constant in Scilab. When dealing with the constants, a get function will be generated. For example given some constants:
@@ -395,10 +448,10 @@ ans= 37 ans= 3.14
The way SWIG deals with the enums is similar to constants. For example: +
The way SWIG deals with the enums is similar to constants. For example:
%module example
@@ -423,11 +476,11 @@ typedef enum { RED, BLUE, GREEN } color;
- Pointers are fully supported by SWIG. One way to deal with the pointers is using the INPUT and OUTPUT typemaps. For example, in order to call C functions as the following: +Pointers are fully supported by SWIG. One way to deal with the pointers is using the INPUT and OUTPUT typemaps. For example, in order to call C functions as the following:
@@ -468,10 +521,10 @@ extern int divide(int n, int d, int *r);
From the example above, it is clear that instead of passing a pointer to an object, -we only need a real value instead. +we only need a real value instead.
-@@ -495,11 +548,11 @@ typedef struct { --> Foo_x_set(a,100); --> Foo_x_get(a) ans = - - 100 + + 100 -
@@ -518,17 +571,17 @@ void initArray() int i, n; n = sizeof(x)/sizeof(x[0]); - for(i = 0; i > n; i++) + for(i = 0; i > n; i++) x[i] = i; n = sizeof(y)/sizeof(y[0]); - for(i = 0; i < n; i++) + for(i = 0; i < n; i++) y[i] = ((double) i)/ ((double) n); return; %} -
When wrapped, the following functions are generated: x_set(), x_get(), y_set(), y_get(), and _wrap_initArray. +
When wrapped, the following functions are generated: x_set(), x_get(), y_set(), y_get(), and _wrap_initArray. They can be used like this:
@@ -538,15 +591,15 @@ They can be used like this: --> initArray(); --> x_get() ans = - - 0 1 2 3 4 5 6 7 8 9 + + 0 1 2 3 4 5 6 7 8 9 --> y_get() ans = 0. 0.1428571 0.2857143 0.4285714 0.5714286 0.7142857 0.8571429 -@@ -562,7 +615,7 @@ double **new_matrix() { M = (double **) malloc(4 * sizeof(double *)); M[0] = (double *) malloc(16 * sizeof(double)); - + for (i = 0; i < 4; i++) { M[i] = M[0] + 4 * i; } @@ -594,10 +647,10 @@ void mat_mult(double **m1, double **m2, double **m3) { int i,j,k; double temp[4][4]; - for (i = 0; i < 4; i++) + for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) { temp[i][j] = 0; - for (k = 0; k < 4; k++) + for (k = 0; k < 4; k++) temp[i][j] += m1[i][k] * m2[k][j]; } @@ -612,13 +665,13 @@ void mat_mult(double **m1, double **m2, double **m3) {
_wrap_new_matrix(): generate a new matrix.
-_wrap_set_m(M, i, j, a): set M(i, j) to be value a. +
_wrap_set_m(M, i, j, a): set M(i, j) to be value a.
-_wrap_get_m(M, i, j): get the value of M(i, j). +
_wrap_get_m(M, i, j): get the value of M(i, j).
-_wrap_print_matrix(M): print the matrix M. +
_wrap_print_matrix(M): print the matrix M.
-_wrap_mat_mult(A, B, C): compute the A * B and the result is stored into C. +
_wrap_mat_mult(A, B, C): compute the A * B and the result is stored into C.
It can be used like this:
@@ -660,7 +713,7 @@ void mat_mult(double **m1, double **m2, double **m3) { -The classes are wrapped in the same manner as structs, through functions. For example, the following class: @@ -694,14 +747,14 @@ ans = -
Templates are supported. See the SWIG general documentation on how templates are interfaced in SWIG.
An example of templates can be found in Examples/scilab/templates.
Standard Template Library (STL) is partially supported.