fix extern declarations documentation
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7323 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
be192ba08b
commit
3a1bdbed1f
8 changed files with 89 additions and 4 deletions
|
|
@ -83,7 +83,9 @@ One way to deal with this is to use the
|
|||
%include "typemaps.i"
|
||||
|
||||
%apply double *OUTPUT { double *result };
|
||||
%inlne %{
|
||||
extern void add(double a, double b, double *result);
|
||||
%}
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
|
|
@ -123,10 +125,13 @@ of the type and name. For example, you could write the following:
|
|||
%include "typemaps.i"
|
||||
|
||||
%apply double *OUTPUT { double *result };
|
||||
|
||||
%inline %{
|
||||
extern void add(double a, double b, double *result);
|
||||
extern void sub(double a, double b, double *result);
|
||||
extern void mul(double a, double b, double *result);
|
||||
extern void div(double a, double b, double *result);
|
||||
%}
|
||||
...
|
||||
</pre></div>
|
||||
|
||||
|
|
@ -174,6 +179,9 @@ rule names directly in arguments. For example, you could write this:
|
|||
%module example
|
||||
%include "typemaps.i"
|
||||
|
||||
%{
|
||||
extern void add(double a, double b, double *OUTPUT);
|
||||
%}
|
||||
extern void add(double a, double b, double *OUTPUT);
|
||||
</pre></div>
|
||||
|
||||
|
|
@ -226,6 +234,9 @@ Now, consider this SWIG interface:
|
|||
%module example
|
||||
%include "typemaps.i"
|
||||
...
|
||||
%{
|
||||
extern double add(double *, double *);
|
||||
%}
|
||||
extern double add(double *INPUT, double *INPUT);
|
||||
|
||||
</pre></div>
|
||||
|
|
@ -274,7 +285,9 @@ A SWIG interface file might look like this :</p>
|
|||
%module example
|
||||
%include "typemaps.i"
|
||||
...
|
||||
%inline %{
|
||||
extern void add(double a, double b, double *OUTPUT);
|
||||
%}
|
||||
|
||||
</pre></div>
|
||||
|
||||
|
|
@ -340,6 +353,9 @@ function like this in an interface file :</p>
|
|||
%module example
|
||||
%include typemaps.i
|
||||
...
|
||||
%{
|
||||
extern void negate(double *);
|
||||
%}
|
||||
extern void negate(double *INOUT);
|
||||
|
||||
</pre></div>
|
||||
|
|
|
|||
|
|
@ -181,6 +181,9 @@ suffix) :
|
|||
%module example
|
||||
%{
|
||||
/* Put headers and other declarations here */
|
||||
extern double My_variable;
|
||||
extern int fact(int);
|
||||
extern int my_mod(int n, int m);
|
||||
%}
|
||||
|
||||
extern double My_variable;
|
||||
|
|
|
|||
|
|
@ -679,8 +679,10 @@ Java global variable, access to C/C++ global variables is done through static ge
|
|||
// SWIG interface file with global variables
|
||||
%module example
|
||||
...
|
||||
%inline %{
|
||||
extern int My_variable;
|
||||
extern double density;
|
||||
%}
|
||||
...
|
||||
</pre></div>
|
||||
|
||||
|
|
@ -719,6 +721,9 @@ To make ordinary variables read-only, you can use the <tt>%immutable</tt> direct
|
|||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%{
|
||||
extern char *path;
|
||||
%}
|
||||
%immutable;
|
||||
extern char *path;
|
||||
%mutable;
|
||||
|
|
@ -736,6 +741,9 @@ If you just want to make a specific variable immutable, supply a declaration nam
|
|||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%{
|
||||
extern char *path;
|
||||
%}
|
||||
%immutable path;
|
||||
...
|
||||
extern char *path; // Read-only (due to %immutable)
|
||||
|
|
@ -3671,7 +3679,10 @@ If you must work with simple pointers such as <tt>int *</tt> or <tt>double *</tt
|
|||
%module example
|
||||
%include "cpointer.i"
|
||||
|
||||
%inline %{
|
||||
extern void add(int x, int y, int *result);
|
||||
%}
|
||||
|
||||
%pointer_functions(int, intp);
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -4134,7 +4145,9 @@ you might define a typemap like this:
|
|||
$1 = $input;
|
||||
printf("Received an integer : %d\n", $1);
|
||||
}
|
||||
%inline %{
|
||||
extern int fact(int nonnegative);
|
||||
%}
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
|
|
@ -4177,7 +4190,9 @@ You can refine this by supplying an optional parameter name. For example:
|
|||
printf("Received an integer : %d\n", $1);
|
||||
}
|
||||
|
||||
%inline %{
|
||||
extern int fact(int nonnegative);
|
||||
%}
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
|
|
@ -4198,8 +4213,10 @@ the typemap system follows <tt>typedef</tt> declarations. For example:
|
|||
$1 = $input;
|
||||
printf("Received an integer : %d\n", $1);
|
||||
}
|
||||
%inline %{
|
||||
typedef int Integer;
|
||||
extern int fact(Integer nonnegative); // Above typemap is applied
|
||||
%}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -257,8 +257,10 @@ follows :</p>
|
|||
<div class="code"><pre>
|
||||
%module example
|
||||
|
||||
%inline %{
|
||||
extern double My_variable;
|
||||
extern int fact(int);
|
||||
%}
|
||||
|
||||
// Include code for rebuilding Perl
|
||||
%include perlmain.i
|
||||
|
|
@ -777,6 +779,9 @@ To make ordinary variables read-only, you can also use the <tt>%immutable</tt> d
|
|||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%{
|
||||
extern char *path;
|
||||
%}
|
||||
%immutable;
|
||||
extern char *path;
|
||||
%mutable;
|
||||
|
|
@ -790,6 +795,9 @@ The <tt>%immutable</tt> directive stays in effect until it is explicitly disable
|
|||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%{
|
||||
extern char *path;
|
||||
%}
|
||||
%immutable path;
|
||||
...
|
||||
...
|
||||
|
|
@ -1730,7 +1738,9 @@ you might define a typemap like this:
|
|||
printf("Received an integer : %d\n", $1);
|
||||
}
|
||||
...
|
||||
%inline %{
|
||||
extern int fact(int n);
|
||||
%}
|
||||
|
||||
</pre></div>
|
||||
|
||||
|
|
@ -1773,8 +1783,10 @@ the typemap system follows <tt>typedef</tt> declarations. For example:
|
|||
$1 = (int) SvIV($input);
|
||||
printf("n = %d\n",$1);
|
||||
}
|
||||
%inline %{
|
||||
typedef int Integer;
|
||||
extern int fact(Integer n); // Above typemap is applied
|
||||
%}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -313,9 +313,11 @@ rebuild the interpreter. For example:
|
|||
<div class="code"><pre>
|
||||
%module example
|
||||
|
||||
%inline %{
|
||||
extern int fact(int);
|
||||
extern int mod(int, int);
|
||||
extern double My_variable;
|
||||
%}
|
||||
|
||||
%include embed.i // Include code for a static version of Python
|
||||
|
||||
|
|
@ -830,8 +832,10 @@ For example, consider this interface
|
|||
// SWIG interface file with global variables
|
||||
%module example
|
||||
...
|
||||
%inline %{
|
||||
extern int My_variable;
|
||||
extern double density;
|
||||
%}
|
||||
...
|
||||
</pre></div>
|
||||
<p>
|
||||
|
|
@ -874,6 +878,9 @@ To make ordinary variables read-only, you can use the <tt>%immutable</tt> direct
|
|||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%{
|
||||
extern char *path;
|
||||
%}
|
||||
%immutable;
|
||||
extern char *path;
|
||||
%mutable;
|
||||
|
|
@ -891,6 +898,9 @@ If you just want to make a specific variable immutable, supply a declaration nam
|
|||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%{
|
||||
extern char *path;
|
||||
%}
|
||||
%immutable path;
|
||||
...
|
||||
extern char *path; // Read-only (due to %immutable)
|
||||
|
|
@ -3406,7 +3416,10 @@ If you must work with simple pointers such as <tt>int *</tt> or <tt>double *</tt
|
|||
%module example
|
||||
%include "cpointer.i"
|
||||
|
||||
%inline %{
|
||||
extern void add(int x, int y, int *result);
|
||||
%}
|
||||
|
||||
%pointer_functions(int, intp);
|
||||
</pre>
|
||||
</div>
|
||||
|
|
@ -3632,7 +3645,9 @@ you might define a typemap like this:
|
|||
$1 = (int) PyLong_AsLong($input);
|
||||
printf("Received an integer : %d\n",$1);
|
||||
}
|
||||
%inline %{
|
||||
extern int fact(int n);
|
||||
%}
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
|
|
@ -3671,7 +3686,9 @@ You can refine this by supplying an optional parameter name. For example:
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
%inline %{
|
||||
extern int fact(int nonnegative);
|
||||
%}
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
|
|
@ -3692,8 +3709,10 @@ the typemap system follows <tt>typedef</tt> declarations. For example:
|
|||
$1 = (int) PyLong_AsLong($input);
|
||||
printf("n = %d\n",$1);
|
||||
}
|
||||
%inline %{
|
||||
typedef int Integer;
|
||||
extern int fact(Integer n); // Above typemap is applied
|
||||
%}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -589,7 +589,7 @@ variables:
|
|||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>// SWIG interface file with global variables<br>%module example<br>...<br>extern int variable1;<br>extern double Variable2;<br>...<br></pre>
|
||||
<pre>// SWIG interface file with global variables<br>%module example<br>...<br>%inline %{<br>extern int variable1;<br>extern double Variable2;<br>%}<br>...<br></pre>
|
||||
</div>
|
||||
<p>
|
||||
Now look at the Ruby interface:</p>
|
||||
|
|
@ -626,7 +626,7 @@ error.
|
|||
directive. For example:
|
||||
</p>
|
||||
<div class="code">
|
||||
<pre>%immutable;<br>extern char *path;<br>%mutable;<br></pre>
|
||||
<pre>%immutable;<br>%inline %{<br>extern char *path;<br>%}<br>%mutable;<br></pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
|
|
@ -1511,7 +1511,7 @@ you might define a typemap like this:
|
|||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>%module example<br><br>%typemap(in) int {<br> $1 = (int) NUM2INT($input);<br> printf("Received an integer : %d\n",$1);<br>}<br><br>extern int fact(int n);<br></pre>
|
||||
<pre>%module example<br><br>%typemap(in) int {<br> $1 = (int) NUM2INT($input);<br> printf("Received an integer : %d\n",$1);<br>}<br><br>%inline %{<br>extern int fact(int n);<br>%}<br></pre>
|
||||
</div>
|
||||
<p>
|
||||
Typemaps are always associated with some specific aspect of code
|
||||
|
|
@ -1544,7 +1544,7 @@ For
|
|||
example:
|
||||
</p>
|
||||
<div class="code">
|
||||
<pre>%module example<br><br>%typemap(in) int n {<br> $1 = (int) NUM2INT($input);<br> printf("n = %d\n",$1);<br>}<br><br>extern int fact(int n);<br></pre>
|
||||
<pre>%module example<br><br>%typemap(in) int n {<br> $1 = (int) NUM2INT($input);<br> printf("n = %d\n",$1);<br>}<br><br>%inline %{<br>extern int fact(int n);<br>%}<br></pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -400,9 +400,11 @@ For example, consider the following interface file:
|
|||
<div class="code"><pre>
|
||||
%module example
|
||||
|
||||
%inline %{
|
||||
extern double sin(double x);
|
||||
extern int strcmp(const char *, const char *);
|
||||
extern int Foo;
|
||||
%}
|
||||
#define STATUS 50
|
||||
#define VERSION "1.1"
|
||||
</pre></div>
|
||||
|
|
|
|||
|
|
@ -184,9 +184,11 @@ For example:
|
|||
<div class="code"><pre>
|
||||
%module example
|
||||
|
||||
%inline %{
|
||||
extern int fact(int);
|
||||
extern int mod(int, int);
|
||||
extern double My_variable;
|
||||
%}
|
||||
|
||||
%include tclsh.i // Include code for rebuilding tclsh
|
||||
|
||||
|
|
@ -717,7 +719,9 @@ C/C++ global variables are wrapped by Tcl global variables. For example:
|
|||
// SWIG interface file with global variables
|
||||
%module example
|
||||
...
|
||||
%inline %{
|
||||
extern double density;
|
||||
%}
|
||||
...
|
||||
</pre></div>
|
||||
|
||||
|
|
@ -754,6 +758,9 @@ To make ordinary variables read-only, you can use the <tt>%immutable</tt> direct
|
|||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%{
|
||||
extern char *path;
|
||||
%}
|
||||
%immutable;
|
||||
extern char *path;
|
||||
%mutable;
|
||||
|
|
@ -771,6 +778,9 @@ If you just want to make a specific variable immutable, supply a declaration nam
|
|||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%{
|
||||
extern char *path;
|
||||
%}
|
||||
%immutable path;
|
||||
...
|
||||
extern char *path; // Read-only (due to %immutable)
|
||||
|
|
@ -2455,7 +2465,9 @@ you might define a typemap like this:
|
|||
if (Tcl_GetIntFromObj(interp,$input,&$1) == TCL_ERROR) return TCL_ERROR;
|
||||
printf("Received an integer : %d\n",$1);
|
||||
}
|
||||
%inline %{
|
||||
extern int fact(int n);
|
||||
%}
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
|
|
@ -2491,7 +2503,9 @@ You can refine this by supplying an optional parameter name. For example:
|
|||
if (Tcl_GetIntFromObj(interp,$input,&$1) == TCL_ERROR) return TCL_ERROR;
|
||||
printf("n = %d\n",$1);
|
||||
}
|
||||
%inline %{
|
||||
extern int fact(int n);
|
||||
%}
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
|
|
@ -2512,8 +2526,10 @@ the typemap system follows <tt>typedef</tt> declarations. For example:
|
|||
if (Tcl_GetIntFromObj(interp,$input,&$1) == TCL_ERROR) return TCL_ERROR;
|
||||
printf("n = %d\n",$1);
|
||||
}
|
||||
%inline %{
|
||||
typedef int Integer;
|
||||
extern int fact(Integer n); // Above typemap is applied
|
||||
%}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue