From 1eeb729487786ed64bef8a3059f3b91f88cbf764 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Fri, 14 Feb 2014 14:13:00 +0100 Subject: [PATCH] scilab: add help on primitive type mappings --- Doc/Manual/Scilab.html | 115 ++++++++++++++++++++++++++++++----------- 1 file changed, 84 insertions(+), 31 deletions(-) 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 @@
  • Identifiers
  • Modules
  • Functions +
  • Default primitive type mappings
  • Global variables
  • Constants
  • Enums @@ -55,11 +56,11 @@

    -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 -

    37.3.4 Global variables

    +

    37.3.4 Default primitive type mappings

    + +

    +The following table give for each C/C++ primitive type the equivalent Scilab type. +

    + +
    + + + + + + + + + + + + + + + + + + + + +
    C/C++ typeScilab type
    boolboolean
    charstring
    signed chardouble or int8
    unsigned charuint8
    shortdouble or int16
    unsigned shortuint16
    intdouble or int32
    unsigned intuint32
    longdouble or int32
    unsigned longuint32
    signed long longnot supported with Scilab 5.x
    unsigned long longnot supported with Scilab 5.x
    floatdouble
    doubledouble
    char* or char[]string
    +
    + +

    +Notes: +

    +

    + +

    37.3.5 Default type mappings for non-primitive types

    + +

    +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. +

    + +

    37.3.6 Global variables

    - 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
     
    -

    37.3.5 Constants

    +

    37.3.7 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: + 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
     
    -

    37.3.6 Enums

    +

    37.3.8 Enums

    -

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

    37.3.7 Pointers

    +

    37.3.9 Pointers

    - 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.

    -

    37.3.8 Structs

    +

    37.3.10 Structs

    @@ -495,11 +548,11 @@ typedef struct { --> Foo_x_set(a,100); --> Foo_x_get(a) ans = - - 100 + + 100 -

    37.3.9 Arrays

    +

    37.3.11 Arrays

    @@ -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 -

    37.3.10 Matrices

    +

    37.3.12 Matrices

    @@ -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) { -

    37.4.11 Classes

    +

    37.4.13 Classes

    The classes are wrapped in the same manner as structs, through functions. For example, the following class: @@ -694,14 +747,14 @@ ans = -

    37.4.12 Templates

    +

    37.4.14 Templates

    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.

    -

    37.4.13 STL

    +

    37.4.15 STL

    Standard Template Library (STL) is partially supported.