a better way to deal with constants and enums and some change about the doc
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11515 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
c85685b60b
commit
b1a384dc3c
10 changed files with 223 additions and 255 deletions
|
|
@ -27,6 +27,7 @@
|
|||
<li><a href="#Scilab_nn12">Enums</a>
|
||||
<li><a href="#Scilab_nn13">Pointers</a>
|
||||
<li><a href="#Scilab_nn14">Structs</a>
|
||||
<li><a href="#Scilab_nn15">Arrays</a>
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
@ -194,7 +195,7 @@ int fact(int n); </pre></div>
|
|||
|
||||
<div class="targetlang"><pre>Scilab:1>fact(4)
|
||||
ant=24 </pre></div>
|
||||
<H3><a name="scilab_nn10"></a>27.3.3 Global variables</H3>
|
||||
<H3><a name="scilab_nn10"></a>36.3.3 Global variables</H3>
|
||||
|
||||
<p>
|
||||
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 variables onto the C variable.
|
||||
|
|
@ -210,27 +211,12 @@ c = 3
|
|||
|
||||
scilab:5> Foo_get()
|
||||
ans = 4
|
||||
|
||||
scilab:6> Foo_set([1,2,3;4,5,6]);
|
||||
|
||||
scilab:7> Foo_get()
|
||||
ans =
|
||||
|
||||
1. 2. 3.
|
||||
4. 5. 6.
|
||||
scilab:8> Foo_set([1+2*%i,2+3*%i;3+4*%i,7+8*%i]);
|
||||
|
||||
scilab:9> Foo_get()
|
||||
ans =
|
||||
|
||||
1. + 2.i 2. + 3.i
|
||||
3. + 4.i 7. + 8.i
|
||||
</pre></div>
|
||||
<H3><a name="Scilab_nn11"></a>27.3.4 Constants</H3>
|
||||
<H3><a name="Scilab_nn11"></a>36.3.4 Constants</H3>
|
||||
|
||||
|
||||
<p>
|
||||
C constants are not really constant in Scilab. They are actually just a copy of the value into the Scilab interpreter. Therefore they can be changed just as any other value. For example given some constants:
|
||||
C constants are not really constant in Scilab. When dealing with the constants, the get function will be generated. For example given some constants:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>%module example
|
||||
|
|
@ -242,47 +228,32 @@ scilab:9> Foo_get()
|
|||
#define SCONST2 "\"Hello World\""
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
A file called example.sce will be created, which could be interpreted by the scilab. The code in the file is as following:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>....
|
||||
example.ICONST = 42
|
||||
example.FCONST = 2.1828
|
||||
example.CCONST = ascii(120)
|
||||
example.CCONST2 = ascii(10)
|
||||
example.SCONST = "Hello World"
|
||||
example.SCONST2 = """Hello World"""
|
||||
example.EXPR = 42+3*(2.1828)
|
||||
example.iconst = 37
|
||||
example.fconst = 3.14
|
||||
.... </pre></div>
|
||||
<p>It is easy to use the C constants after run the command "exec example.sce":</p>
|
||||
<p>It is easy to use them in Scilab:</p>
|
||||
|
||||
<div class="targetlang"><pre>
|
||||
scilab:1> exec example.sce;
|
||||
scilab:2> example.ICONST
|
||||
scilab:1> exec loader.sce;
|
||||
scilab:2> ICONST_get();
|
||||
ans= 42
|
||||
scilab:3> example.FCONST
|
||||
scilab:3> FCONST_get();
|
||||
ans= 2.1828
|
||||
scilab:4> example.CCONST
|
||||
scilab:4> CCONST_get();
|
||||
ans=x
|
||||
scilab:5> example.CCONST2
|
||||
scilab:5> CCONST2_get();
|
||||
ans=
|
||||
|
||||
scilab:6> example.SCONST
|
||||
scilab:6> SCONST_get();
|
||||
ans= Hello World
|
||||
scilab:7> example.SCONST2
|
||||
scilab:7> SCONST2_get();
|
||||
ans= "Hello World"
|
||||
scilab:8> example.EXPR
|
||||
scilab:8> EXPR_get();
|
||||
ans= 48.5484
|
||||
scilab:9> example.iconst
|
||||
scilab:9> iconst_get();
|
||||
ans= 37
|
||||
scilab:10> example.fconst
|
||||
scilab:10> fconst_get();
|
||||
ans= 3.14
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Scilab_nn12"></a>27.3.5 Enums</H3>
|
||||
<H3><a name="Scilab_nn12"></a>36.3.5 Enums</H3>
|
||||
|
||||
<p> The way that deals with the enums is similar to the constants. For example:
|
||||
</p>
|
||||
|
|
@ -292,30 +263,24 @@ typedef enum { RED, BLUE, GREEN } color;
|
|||
</pre></div>
|
||||
|
||||
<p>
|
||||
A file called example.sce will be created, which could be interpreted by the scilab. The code in the file is as following:
|
||||
Some code like RED_get(), BLUE_get(),GREEN_get() will be generated. So it could be used as the following:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>....
|
||||
color.RED=0;
|
||||
color.BLUE=color.RED + 1;
|
||||
color.GREEN=color.BLUE + 1;
|
||||
.... </pre></div>
|
||||
<p>It is easy to use the enums after run the command "exec example.sce":</p>
|
||||
|
||||
<div class="targetlang"><pre>
|
||||
scilab:1> exec example.sce;
|
||||
scilab:2> printf(" RED = %i\n", color.RED);
|
||||
scilab:1> exec loader.sce;
|
||||
scilab:2> printf(" RED = %i\n", RED_get());
|
||||
RED = 0
|
||||
|
||||
scilab:3> printf(" BLUE = %i\n", color.BLUE);
|
||||
scilab:3> printf(" BLUE = %i\n", BLUE_get());
|
||||
BLUE = 1
|
||||
|
||||
scilab:4> printf(" GREEN = %i\n", color.GREEN);
|
||||
scilab:4> printf(" GREEN = %i\n", GREEN_get());
|
||||
GREEN = 2
|
||||
</pre></div>
|
||||
|
||||
|
||||
<H3><a name="Scilab_nn13"></a>27.3.5 Pointers</H3>
|
||||
<H3><a name="Scilab_nn13"></a>36.3.6 Pointers</H3>
|
||||
<p>
|
||||
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:
|
||||
</p>
|
||||
|
|
@ -356,7 +321,7 @@ scilab:4> printf(" 42/37 = %d remainder %d\n",q,r);
|
|||
we only need a real value instead.
|
||||
</p>
|
||||
|
||||
<H3><a name="Scilab_nn14"></a>27.3.6 Structs</H3>
|
||||
<H3><a name="Scilab_nn14"></a>36.3.7 Structs</H3>
|
||||
<p>
|
||||
SWIG creates a set of accessor functions when encountering a structure or union. For example:
|
||||
</p>
|
||||
|
|
@ -371,14 +336,53 @@ typedef struct {
|
|||
<p> When wrappered, it would generate two main function: Foo_x_set(), which set the data value of the structrure and Foo_x_get() which could obtain the value of the structrure. Run it in Scilab:
|
||||
</p>
|
||||
<div class="targetlang"><pre>
|
||||
a=new_Foo();
|
||||
Foo_x_set(a,100);
|
||||
Foo_x_get(a)
|
||||
scilab:1> a=new_Foo();
|
||||
scilab:2> Foo_x_set(a,100);
|
||||
scilab:3> Foo_x_get(a)
|
||||
ans =
|
||||
|
||||
100
|
||||
</pre></div>
|
||||
|
||||
<H3><a name="Scilab_nn15"></a>36.3.8 Arrays</H3>
|
||||
<p>
|
||||
Arrays are fully supported by SWIG and Scilab. In SWIG, they are handled as pointers. And Scilab also supports the pointer well. So it is easy to deal with the arrays. For example:
|
||||
</p>
|
||||
<div class="code"><pre>%module example
|
||||
|
||||
%inline %{
|
||||
int x[10];
|
||||
double y[7];
|
||||
void initArray()
|
||||
{
|
||||
int i, n;
|
||||
|
||||
n = sizeof(x)/sizeof(x[0]);
|
||||
for(i = 0; i < n; i++)
|
||||
x[i] = i;
|
||||
|
||||
n = sizeof(y)/sizeof(y[0]);
|
||||
for(i = 0; i < n; i++)
|
||||
y[i] = ((double) i)/ ((double) n);
|
||||
return;
|
||||
%}
|
||||
</pre></div>
|
||||
<p> When wrappered, it would generate the following funtion: x_set(), x_get(), y_set(), y_get(), and _wrap_initArray. So it could be used like this:
|
||||
</p>
|
||||
<div class="targetlang"><pre>
|
||||
scilab:1> exec loader.sce
|
||||
|
||||
scilab:2> initArray();
|
||||
scilab:3> x_get()
|
||||
ans =
|
||||
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
scilab:4>y_get()
|
||||
ans =
|
||||
|
||||
0. 0.1428571 0.2857143 0.4285714 0.5714286 0.7142857 0.8571429
|
||||
</pre></div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -24,10 +24,5 @@
|
|||
%constant int iconst = 37;
|
||||
%constant double fconst = 3.14;
|
||||
|
||||
%inline %{
|
||||
void constant_test(const int x) {
|
||||
printf("%i", x);
|
||||
}
|
||||
%}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +1,23 @@
|
|||
// loader the *.so
|
||||
exec loader.sce;
|
||||
exec example.sce;
|
||||
|
||||
printf("ICONST = %i (should be 42)\n", ICONST);
|
||||
printf("FCONST = %f (should be 2.1828)\n", FCONST);
|
||||
printf("CCONST = %c (should be ''x'')\n", CCONST);
|
||||
printf("CCONST2 = %s (this should be on a new line)\n", CCONST2);
|
||||
printf("SCONST = %s (should be ''Hello World'')\n", SCONST);
|
||||
printf("SCONST2 = %s (should be "'""Hello World"""')\n", SCONST2);
|
||||
printf("EXPR = %f (should be 48.5484)\n", EXPR);
|
||||
printf("iconst = %i (should be 37)\n", iconst);
|
||||
printf("fconst = %f (should be 3.14)\n", fconst);
|
||||
printf("ICONST = %i (should be 42)\n", ICONST_get());
|
||||
printf("FCONST = %f (should be 2.1828)\n", FCONST_get());
|
||||
printf("CCONST = %c (should be ''x'')\n", CCONST_get());
|
||||
printf("CCONST2 = %s (this should be on a new line)\n", CCONST2_get());
|
||||
printf("SCONST = %s (should be ''Hello World'')\n", SCONST_get());
|
||||
printf("SCONST2 = %s (should be "'""Hello World"""')\n", SCONST2_get());
|
||||
printf("EXPR = %f (should be 48.5484)\n", EXPR_get());
|
||||
printf("iconst = %i (should be 37)\n", iconst_get());
|
||||
printf("fconst = %f (should be 3.14)\n", fconst_get());
|
||||
|
||||
try
|
||||
printf("EXTERN = %s (Arg! This should not printf(anything)\n", EXTERN);
|
||||
printf("EXTERN = %s (Arg! This should not printf(anything)\n", EXTERN_get());
|
||||
catch
|
||||
printf("EXTERN is not defined (good)\n");
|
||||
end
|
||||
try
|
||||
printf("FOO = %i (Arg! This should not printf(anything)\n", FOO);
|
||||
printf("FOO = %i (Arg! This should not printf(anything)\n", FOO_get());
|
||||
catch
|
||||
printf("FOO is not defined (good)\n");
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@
|
|||
|
||||
void enum_test(color c) {
|
||||
if (c == RED) {
|
||||
sciprint("color = RED, ");
|
||||
printf("color = RED\n");
|
||||
} else if (c == BLUE) {
|
||||
sciprint("color = BLUE, ");
|
||||
printf("color = BLUE\n ");
|
||||
} else if (c == GREEN) {
|
||||
sciprint("color = GREEN, ");
|
||||
printf("color = GREEN\n");
|
||||
} else {
|
||||
sciprint("color = Unknown color!, ");
|
||||
printf("color = Unknown color!\n");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
// loader the *.so
|
||||
exec loader.sce;
|
||||
|
||||
exec example.sce;
|
||||
|
||||
// Print out the value of some enums
|
||||
printf("*** color ***\n");
|
||||
printf(" RED = %i\n", color.RED);
|
||||
printf(" BLUE = %i\n", color.BLUE);
|
||||
printf(" GREEN = %i\n", color.GREEN);
|
||||
printf(" RED = %i\n", RED_get());
|
||||
printf(" BLUE = %i\n", BLUE_get());
|
||||
printf(" GREEN = %i\n", GREEN_get());
|
||||
|
||||
|
||||
printf("\nTesting use of enums with functions\n");
|
||||
|
||||
enum_test(color.RED);
|
||||
enum_test(color.BLUE);
|
||||
enum_test(color.GREEN);
|
||||
enum_test(1234);
|
||||
enum_test(RED_get());
|
||||
enum_test(BLUE_get());
|
||||
enum_test(GREEN_get());
|
||||
enum_test(int32(1234));
|
||||
|
||||
exit
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
exec loader.sce
|
||||
exec enums.sce
|
||||
|
||||
bar1(foo1.CSP_ITERATION_BWD)
|
||||
bar2(foo3.ABCDE)
|
||||
bar3(foo3.FGHJI)
|
||||
bar1(CSP_ITERATION_BWD_get())
|
||||
bar2(ABCDE_get())
|
||||
bar3(FGHJI_get())
|
||||
|
||||
exit
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
exec loader.sce;
|
||||
exec li_math.sce;
|
||||
|
||||
x = fmod(M_PI, M_1_PI)
|
||||
x = fmod(M_PI_get(), M_1_PI_get())
|
||||
|
||||
exit
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
exec loader.sce
|
||||
|
||||
initArray();
|
||||
x_get()
|
||||
y_get()
|
||||
if x_get() <> int32([0,1,2,3,4,5,6,7,8,9]) then pause, end
|
||||
if y_get() <> [0/7,1/7,2/7,3/7,4/7,5/7,6/7] then pase, end
|
||||
|
||||
exit
|
||||
|
|
|
|||
|
|
@ -272,6 +272,19 @@
|
|||
}
|
||||
}
|
||||
|
||||
%typemap(in) enum SWIGTYPE (int iRows, int iCols) {
|
||||
int *piAddrVar;
|
||||
int *_piData;
|
||||
getVarAddressFromPosition($argnum, &piAddrVar);
|
||||
getVarDimension(piAddrVar, &iRows, &iCols);
|
||||
|
||||
if (getVarType(piAddrVar) != sci_ints || iRows != 1 || iCols != 1 || isVarComplex(piAddrVar)) {
|
||||
Scierror(999, _("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, $argnum);
|
||||
}
|
||||
getMatrixOfInteger32(piAddrVar, &iRows, &iCols, &_piData);
|
||||
$1 = ($1_ltype)*_piData;
|
||||
}
|
||||
|
||||
%typemap(in) SWIGTYPE * {
|
||||
int *piAddrVar;
|
||||
void *_piData = NULL;
|
||||
|
|
@ -371,6 +384,7 @@
|
|||
%typemap(out,noblock=1) void {
|
||||
}
|
||||
|
||||
|
||||
/* Pointers */
|
||||
%typemap(out) signed char *,
|
||||
short *,
|
||||
|
|
@ -397,6 +411,15 @@
|
|||
if ($1) free($1);
|
||||
}
|
||||
|
||||
%typemap(out) enum SWIGTYPE (int iRowsOut, int iColsOut) {
|
||||
int temp;
|
||||
temp = (int)($result);
|
||||
iRowsOut = 1;
|
||||
iColsOut = 1;
|
||||
createMatrixOfInteger32(iVarOut, iRowsOut, iColsOut, &temp);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
%typemap(out) SWIGTYPE * {
|
||||
createPointer(iVarOut, (void *)$result);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
|
|
@ -420,7 +443,9 @@
|
|||
long,
|
||||
unsigned long,
|
||||
float,
|
||||
double {
|
||||
double,
|
||||
long long,
|
||||
unsigned long long {
|
||||
double *_piData;
|
||||
getVarAddressFromPosition($argnum, &piAddrVar);
|
||||
getVarDimension(piAddrVar, &iRows, &iCols);
|
||||
|
|
@ -629,6 +654,17 @@
|
|||
$1 = _pstStrings;
|
||||
}
|
||||
|
||||
%typemap(varin,noblock=1) enum SWIGTYPE {
|
||||
int *_piData;
|
||||
getVarAddressFromPosition($argnum, &piAddrVar);
|
||||
getVarDimension(piAddrVar, &iRows, &iCols);
|
||||
|
||||
if (getVarType(piAddrVar) != sci_ints || iRows != 1 || iCols != 1 || isVarComplex(piAddrVar)) {
|
||||
Scierror(999, _("%s: Wrong type for input argument #%d: Real scalar expected.\n"), fname, $argnum);
|
||||
}
|
||||
getMatrixOfInteger32(piAddrVar, &iRows, &iCols, &_piData);
|
||||
$1 = ($1_ltype)*_piData;
|
||||
}
|
||||
%typemap(varin,noblock=1) SWIGTYPE * {
|
||||
void *_piData = NULL;
|
||||
getVarAddressFromPosition($argnum, &piAddrVar);
|
||||
|
|
@ -670,58 +706,79 @@
|
|||
* ----------------------------------------------------------------------------- */
|
||||
/* Basic C types */
|
||||
%typemap(varout,noblock=1) signed char {
|
||||
createMatrixOfInteger8(iVarOut, iRowsOut, iColsOut, &$result);
|
||||
signed char temp = $result;
|
||||
createMatrixOfInteger8(iVarOut, iRowsOut, iColsOut, &temp);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
%typemap(varout,noblock=1) unsigned char {
|
||||
createMatrixOfUnsignedInteger8(iVarOut, iRowsOut, iColsOut, &$result);
|
||||
unsigned char temp = $result;
|
||||
createMatrixOfUnsignedInteger8(iVarOut, iRowsOut, iColsOut, &temp);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
%typemap(varout,noblock=1) short {
|
||||
createMatrixOfInteger16(iVarOut, iRowsOut, iColsOut, &$result);
|
||||
short temp = $result;
|
||||
createMatrixOfInteger16(iVarOut, iRowsOut, iColsOut, &temp);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
%typemap(varout,noblock=1) unsigned short {
|
||||
createMatrixOfUnsignedInteger16(iVarOut, iRowsOut, iColsOut, &$result);
|
||||
unsigned short temp = $result;
|
||||
createMatrixOfUnsignedInteger16(iVarOut, iRowsOut, iColsOut, &temp);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
%typemap(varout,noblock=1) int,
|
||||
long {
|
||||
createMatrixOfInteger32(iVarOut, iRowsOut, iColsOut, &$result);
|
||||
int temp = $result;
|
||||
createMatrixOfInteger32(iVarOut, iRowsOut, iColsOut, &temp);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
%typemap(varout,noblock=1) unsigned int,
|
||||
unsigned long {
|
||||
createMatrixOfUnsignedInteger32(iVarOut, iRowsOut, iColsOut, &$result);
|
||||
unsigned int temp = $result;
|
||||
createMatrixOfUnsignedInteger32(iVarOut, iRowsOut, iColsOut, &temp);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
%typemap(varout,noblock=1) double {
|
||||
createMatrixOfDouble(iVarOut, iRowsOut, iColsOut, &$result);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
%typemap(varout,noblock=1) float {
|
||||
double temp;
|
||||
temp = (double)$result;
|
||||
double temp = $result;
|
||||
createMatrixOfDouble(iVarOut, iRowsOut, iColsOut, &temp);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
%typemap(varout,noblock=1) char {
|
||||
char *temp;
|
||||
temp = (char*)&($result);
|
||||
createMatrixOfString(iVarOut, iRowsOut, iColsOut, &temp);
|
||||
%typemap(varout,noblock=1) float {
|
||||
double temp = $result;
|
||||
createMatrixOfDouble(iVarOut, iRowsOut, iColsOut, &temp);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
%typemap(varout,noblock=1) long long {
|
||||
long long temp = $result;
|
||||
createMatrixOfInteger64(iVarOut, iRowsOut, iColsOut, &temp);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
%typemap(varout,noblock=1) unsigned long long {
|
||||
unsigned long long temp = $result;
|
||||
createMatrixOfUnsignedInteger64(iVarOut, iRowsOut, iColsOut, &temp);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
%typemap(varout,noblock=1) char {
|
||||
char *temp = (char *)malloc(sizeof($result) + 1);
|
||||
*temp = $result;
|
||||
*(temp+1) = '\0';
|
||||
createMatrixOfString(iVarOut, iRowsOut, iColsOut, &temp);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
free(temp);
|
||||
}
|
||||
|
||||
%typemap(varout,noblock=1) char * {
|
||||
createMatrixOfString(iVarOut, iRowsOut, iColsOut, &($result));
|
||||
char *temp = $result;
|
||||
createMatrixOfString(iVarOut, iRowsOut, iColsOut, &temp);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
|
|
@ -786,9 +843,7 @@
|
|||
}
|
||||
|
||||
%typemap(varout,noblock=1) float [ANY] {
|
||||
double temp;
|
||||
temp = (double)$result;
|
||||
createMatrixOfDouble(iVarOut, 1, $1_dim0, (double *)&temp);
|
||||
createMatrixOfDouble(iVarOut, 1, $1_dim0, (double *)$result);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
|
|
@ -800,6 +855,12 @@
|
|||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
%typemap(varout,noblock=1) enum SWIGTYPE {
|
||||
int temp = $result;
|
||||
createMatrixOfInteger32(iVarOut, iRowsOut, iColsOut, &temp);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
}
|
||||
|
||||
%typemap(varout,noblock=1) SWIGTYPE * {
|
||||
createPointer(iVarOut, (void *)$result);
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
|
|
@ -811,8 +872,7 @@
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Enums mapped as integer values
|
||||
* size_t mapped as int
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%apply int { enum SWIGTYPE };
|
||||
%apply int { size_t };
|
||||
|
|
|
|||
|
|
@ -26,14 +26,10 @@ private:
|
|||
File *f_init;
|
||||
|
||||
String *f_builder_code;
|
||||
String *f_example_code;
|
||||
|
||||
bool hasfunction_flag;
|
||||
bool hasconstant_flag;
|
||||
|
||||
|
||||
public:
|
||||
SCILAB():
|
||||
f_builder_code(NewString("")), f_example_code(NewString("")), hasfunction_flag(false), hasconstant_flag(false) {
|
||||
f_builder_code(NewString("")) {
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -100,7 +96,7 @@ public:
|
|||
Printf(f_runtime, "#include \"stack-c.h\"\n");
|
||||
Printf(f_runtime, "#include \"sciprint.h\"\n");
|
||||
Printf(f_runtime, "#include \"Scierror.h\"\n");
|
||||
Printf(f_runtime, "#include \"api_variable.h\"\n");
|
||||
Printf(f_runtime, "#include \"api_scilab.h\"\n");
|
||||
Printf(f_runtime, "#include \"localization.h\"\n");
|
||||
|
||||
/* Initialize the builder.sce file code */
|
||||
|
|
@ -113,31 +109,14 @@ public:
|
|||
Language::top(n);
|
||||
|
||||
/* create the file to generate the module: "builder.sce" */
|
||||
if(hasfunction_flag) {
|
||||
Printf(f_builder_code, "];\n");
|
||||
Printf(f_builder_code, "ilib_build(ilib_name,table,files,libs);\n");
|
||||
Printf(f_builder_code, "exit");
|
||||
File *f_builder=NewFile(NewStringf("%sbuilder.sce", SWIG_output_directory()), "w", SWIG_output_files());
|
||||
Printv(f_builder, f_builder_code, NIL);
|
||||
Close(f_builder);
|
||||
Delete(f_builder);
|
||||
Delete(f_builder_code);
|
||||
}
|
||||
else {
|
||||
Delete(f_builder_code);
|
||||
}
|
||||
|
||||
/* create the file for constants: "module.sce" */
|
||||
if(hasconstant_flag) {
|
||||
File *f_example = NewFile(NewStringf("%s%s.sce", SWIG_output_directory(), module), "w", SWIG_output_files());
|
||||
Printv(f_example, f_example_code, NIL);
|
||||
Close(f_example);
|
||||
Delete(f_example);
|
||||
Delete(f_example_code);
|
||||
}
|
||||
else {
|
||||
Delete(f_example_code);
|
||||
}
|
||||
Printf(f_builder_code, "];\n");
|
||||
Printf(f_builder_code, "ilib_build(ilib_name,table,files,libs);\n");
|
||||
Printf(f_builder_code, "exit");
|
||||
File *f_builder=NewFile(NewStringf("%sbuilder.sce", SWIG_output_directory()), "w", SWIG_output_files());
|
||||
Printv(f_builder, f_builder_code, NIL);
|
||||
Close(f_builder);
|
||||
Delete(f_builder);
|
||||
Delete(f_builder_code);
|
||||
|
||||
/* Dump out all the files */
|
||||
Dump(f_runtime, f_begin);
|
||||
|
|
@ -162,8 +141,6 @@ public:
|
|||
|
||||
virtual int functionWrapper(Node *n) {
|
||||
|
||||
hasfunction_flag = true;
|
||||
|
||||
/* A new wrapper function object */
|
||||
Wrapper *f = NewWrapper();
|
||||
Parm *p;
|
||||
|
|
@ -341,8 +318,6 @@ public:
|
|||
|
||||
virtual int variableWrapper(Node *n) {
|
||||
|
||||
hasfunction_flag = true;
|
||||
|
||||
/* Get the useful information from the node */
|
||||
String *name = Getattr(n, "name");
|
||||
String *iname = Getattr(n, "sym:name");
|
||||
|
|
@ -456,44 +431,46 @@ public:
|
|||
|
||||
virtual int constantWrapper(Node *n) {
|
||||
|
||||
/* set the flag so to generate the example.sce */
|
||||
hasconstant_flag = true;
|
||||
|
||||
/* Get the useful information from the node */
|
||||
String *name = Getattr(n, "name");
|
||||
String *iname = Getattr(n, "sym:name");
|
||||
SwigType *type = Getattr(n, "type");
|
||||
String *rawval = Getattr(n, "rawval");
|
||||
String *value = rawval ? rawval : Getattr(n, "value");
|
||||
String *tempvalue = NewString("");
|
||||
String *tm;
|
||||
|
||||
/* set the value format to be the scilab format */
|
||||
if (!Strcmp(type, "char")) {
|
||||
value = Getattr(n, "rawvalue");
|
||||
char *temp = (Char(value));
|
||||
tempvalue = NewString("ascii");
|
||||
Printf(tempvalue, "(%d)", (unsigned int)*temp);
|
||||
value = Copy(tempvalue);
|
||||
Delete(tempvalue);
|
||||
}
|
||||
else {
|
||||
if (!Strcmp(type, "p.char")) {
|
||||
char *temp = (Char(value));
|
||||
int len = strlen(temp);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (temp[i] == '\\') {
|
||||
temp[i] = '"';
|
||||
++i;
|
||||
}
|
||||
}
|
||||
Printf(tempvalue, "%s",temp);
|
||||
value = Copy(tempvalue);
|
||||
}
|
||||
Delete(tempvalue);
|
||||
if (!addSymbol(iname, n))
|
||||
return SWIG_ERROR;
|
||||
|
||||
/*use the get function to get the constant value */
|
||||
Wrapper *getf = NewWrapper();
|
||||
String *getname = Swig_name_get(iname);
|
||||
Setattr(n, "wrap:name", getname);
|
||||
int addfail = 0;
|
||||
Printv(getf->def, "int ", getname, " (char *fname,unsigned long fname_len){\n", NIL);
|
||||
|
||||
/* Check the number of input and output */
|
||||
Printf(getf->def, "CheckRhs(0, 0);\n");
|
||||
Printf(getf->def, "CheckLhs(1, 1);\n");
|
||||
|
||||
/* Insert the order of output parameters*/
|
||||
Printf(getf->def, "\nint iOutNum=1;\nint iVarOut=Rhs+1;");
|
||||
|
||||
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
|
||||
Replaceall(tm, "$result", value);
|
||||
Replaceall(tm, "iRowsOut", "1");
|
||||
Replaceall(tm, "iColsOut", "1");
|
||||
addfail = emit_action_code(n, getf->code, tm);
|
||||
Delete(tm);
|
||||
} else {
|
||||
Swig_warning(WARN_TYPEMAP_VAROUT_UNDEF, input_file, line_number, "Unable to read variable of type %s\n", SwigType_str(type, 0));
|
||||
}
|
||||
|
||||
/* write into the code string */
|
||||
Printf(f_example_code, "%s = %s\n", iname, value);
|
||||
|
||||
|
||||
/*Dump the wrapper function */
|
||||
Append(getf->code, "}\n");
|
||||
Wrapper_print(getf, f_wrappers);
|
||||
Printf(f_builder_code, "\"%s\",\"%s\";", getname, getname);
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
|
|
@ -502,9 +479,6 @@ public:
|
|||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int enumDeclaration(Node *n) {
|
||||
|
||||
/* set the flag so to generate the example.sce */
|
||||
hasconstant_flag = true;
|
||||
return Language::enumDeclaration(n);
|
||||
}
|
||||
|
||||
|
|
@ -513,68 +487,8 @@ public:
|
|||
* --------------------------------------------------------------------- */
|
||||
|
||||
virtual int enumvalueDeclaration(Node *n) {
|
||||
|
||||
/* get the name of the enumvalue */
|
||||
String *iname = Getattr(n, "sym:name");
|
||||
|
||||
/* get the name of the enum name */
|
||||
String *parentName = Getattr(parentNode(n), "sym:name");
|
||||
|
||||
/* set the name to be the enum.enumvalue format */
|
||||
if (parentName) {
|
||||
/*if the enum has a name*/
|
||||
if(!Getattr(parentNode(n), "unnamedinstance")) {
|
||||
String *temp = Copy(parentName);
|
||||
Printf(temp, ".%s", iname);
|
||||
Setattr(n, "sym:name", temp);
|
||||
Delete(temp);
|
||||
iname = Getattr(n, "sym:name");
|
||||
}
|
||||
}
|
||||
|
||||
/* set the value attribute to be the integer */
|
||||
String *value;
|
||||
String *enumvalue = Getattr(n, "enumvalue");
|
||||
if (enumvalue) {
|
||||
if (Len(enumvalue) == 1) {
|
||||
char *temp = (Char(enumvalue));
|
||||
/*set the value of char into the format of integer*/
|
||||
if (((*temp <= 'z') && (*temp >= 'a')) || ((*temp <= 'Z') && (*temp >= 'A'))) {
|
||||
String *tempInteger = NewString("");
|
||||
Printf(tempInteger, "%i", int(*temp));
|
||||
Setattr(n, "value", tempInteger);
|
||||
Delete(tempInteger);
|
||||
}
|
||||
else {
|
||||
Setattr(n, "value", enumvalue);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Setattr(n, "value", enumvalue);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (n != firstChild(parentNode(n))) {
|
||||
enumvalue = Getattr(n, "enumvalueex");
|
||||
if (parentName) {
|
||||
if (!Getattr(parentNode(n), "unnamedinstance")) {
|
||||
String *temp = Copy(parentName);
|
||||
Printf(temp, ".%s", enumvalue);
|
||||
enumvalue = Copy(temp);
|
||||
}
|
||||
}
|
||||
Setattr(n, "value", enumvalue);
|
||||
}
|
||||
else {
|
||||
Setattr(n, "value", Getattr(n, "enumvalueex"));
|
||||
}
|
||||
}
|
||||
value = Getattr(n, "value");
|
||||
|
||||
/* write into the code string */
|
||||
Printf(f_example_code, "%s = %s;\n", iname, value);
|
||||
return SWIG_OK;
|
||||
}
|
||||
return Language::enumvalueDeclaration(n);
|
||||
}
|
||||
};
|
||||
|
||||
extern "C" Language *swig_scilab(void) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue