From ca3bee92b28c8cea80877a6b8afbcdb1e346bb93 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Fri, 14 Mar 2014 16:28:07 +0100 Subject: [PATCH] scilab: improve doc on structs + small fixes on classes --- Doc/Manual/Scilab.html | 90 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 13 deletions(-) diff --git a/Doc/Manual/Scilab.html b/Doc/Manual/Scilab.html index 01d104e0d..001fe8b71 100644 --- a/Doc/Manual/Scilab.html +++ b/Doc/Manual/Scilab.html @@ -27,9 +27,9 @@
  • Identifiers
  • Functions
  • Global variables -
  • Constants and enums +
  • Constants and enumerations
  • Pointers -
  • Structs +
  • Structures
  • Arrays
  • Matrices
  • C++ classes @@ -407,7 +407,7 @@ ans = -

    37.3.5 Constants and enums

    +

    37.3.5 Constants and enumerations

    Constants

    @@ -498,7 +498,7 @@ ans= 37 ans= 3.14 -

    Enums

    +

    Enumerations

    The wrapping of enums is quite the same as for constants. @@ -593,42 +593,100 @@ extern int divide(int n, int d, int *r); we only need a real value instead.

    -

    37.3.7 Structs

    +

    37.3.7 Structures

    - SWIG creates a set of accessor functions when encountering a structure or union. For example: +A C structure is wrapped through a pointer and getter and setter functions for access to the member variables. +For example of a struct with two members:

    -
    %module example
    +
    +%module example
    +
     %inline %{
    +
     typedef struct {
         int x;
    +    int y;
     } Foo;
     
     %}
     
    -

    When wrapped, it would generate two main function: Foo_x_set(), which set the data value of the structure and Foo_x_get() which could obtain the value of the structure. Run it in Scilab: +

    +Several functions are generated: +

      +
    • a creation function new_Foo() which returns a pointer to a new created struct Foo.
    • +
    • the two getter functions Foo_x_get(), Foo_y_get(), to get the values of x and y for the struct pointer given in parameter
    • +
    • the two setter functions Foo_x_set(), Foo_y_set(), to set the values of x and y for the struct pointer given in parameter.
    • +
    • a destruction function delete_Foo() to release the struct pointer.
    • +
    +

    + +

    +Following is an example of use:

    ---> a=new_Foo();
    ---> Foo_x_set(a,100);
    +--> a = new_Foo();
    +--> Foo_x_set(a, 100);
     --> Foo_x_get(a)
     ans  =
     
    -  100
    +  100.
    +
    +--> delete_Foo(a);
     
    +

    +Members of a structure that itself are a structure are also accepted and wrapped as a pointer:

    +

    + +
    +%module example
    +
    +%inline %{
    +
    +typedef struct {
    +  int x;
    +} Bar;
    +
    +typedef struct {
    +  Bar b;
    +} Foo;
    +
    +%}
    +
    + +

    +

    +--> b = new_Bar();
    +--> Bar_x_set(b, 20.);
    +
    +--> f = new_Foo();
    +--> Foo_b_set(f, b);
    +
    +--> b2 = Foo_b_get(f);
    +--> Bar_x_get(b2);
    +ans  =
    +
    +  20.
    +
    +

    +

    37.3.8 C++ Classes

    -The classes are wrapped in the same manner as structs, through functions. For example, the following class: +The classes are wrapped the way as structs, through functions. For example, the following class:

    +%module example
    +
    +%inline %{
    +
     class Point {
     public:
       int x,y;
    @@ -637,9 +695,12 @@ public:
         return sqrt(pow(x-rhs.x,2)+pow(y-rhs.y,2));
       }
       void set(int _x,int _y) {
    -    x=_x; y=_y;
    +    x=_x;
    +    y=_y;
       }
     };
    +
    +%}
     

    @@ -652,6 +713,9 @@ can be used from Scilab like this: --> p1.distance(p2) ans = 3.6056 + +--> delete_Point(p1); +--> delete_Point(p2);