add support for Enums
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11288 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
4e9cbd8a7c
commit
ed84d6b162
19 changed files with 865 additions and 222 deletions
|
|
@ -24,6 +24,7 @@
|
|||
<li><a href="#Scilab_nn9">Functions</a>
|
||||
<li><a href="#scilab_nn10">Global variables</a>
|
||||
<li><a href="#Scilab_nn11">Constants</a>
|
||||
<li><a href="#Scilab_nn12">Enums</a>
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
@ -215,34 +216,85 @@ ans = 4</pre></div>
|
|||
</p>
|
||||
|
||||
<div class="code"><pre>%module example
|
||||
%constant int ICONST=42;
|
||||
#define ICONST 42
|
||||
#define FCONST 2.1828
|
||||
#define CCONST 'x'
|
||||
#define CCONST2 '\n'
|
||||
#define SCONST "Hello World"
|
||||
#define SCONST2 "\"Hello World\""
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
This is 'effectively' converted into the following code in the wrapper file:
|
||||
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>....
|
||||
const int ICONST=42;
|
||||
const char * SCONST="Hello World";
|
||||
....
|
||||
int ICONST_get (char *fname,unsigned long fname_len) {..}
|
||||
int SCONST_get (char *fname,unsigned long fname_len) {..}
|
||||
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 as global variables:</p>
|
||||
<p>It is easy to use the C constants after run the command "exec example.sce":</p>
|
||||
|
||||
<div class="targetlang"><pre>
|
||||
scilab:1> ICONST
|
||||
ant = 42
|
||||
scilab:1> exec example.sce;
|
||||
scilab:2> example.ICONST
|
||||
ans= 42
|
||||
scilab:3> example.FCONST
|
||||
ans= 2.1828
|
||||
scilab:4> example.CCONST
|
||||
ans=x
|
||||
scilab:5> example.CCONST2
|
||||
ans=
|
||||
|
||||
scilab:2> SCONST
|
||||
ant= Hello world
|
||||
scilab:6> example.SCONST
|
||||
ans= Hello World
|
||||
scilab:7> example.SCONST2
|
||||
ans= "Hello World"
|
||||
scilab:8> example.EXPR
|
||||
ans= 48.5484
|
||||
scilab:9> example.iconst
|
||||
ans= 37
|
||||
scilab:10> example.fconst
|
||||
ans= 3.14
|
||||
</pre></div>
|
||||
|
||||
scilab:3> c=SCONST()
|
||||
c = Hello World
|
||||
<H3><a name="Scilab_nn12"></a>27.3.5 Enums</H3>
|
||||
|
||||
<p> The way that deals with the enums is similar to the constants. For example:
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>%module example
|
||||
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:
|
||||
</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);
|
||||
RED = 0
|
||||
|
||||
scilab:3> printf(" BLUE = %i\n", color.BLUE);
|
||||
BLUE = 1
|
||||
|
||||
scilab:4> printf(" GREEN = %i\n", color.GREEN);
|
||||
GREEN = 2
|
||||
</pre></div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue