New example
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@743 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
59d16fffd4
commit
250ec82b74
7 changed files with 285 additions and 0 deletions
65
SWIG/Examples/perl5/variables/index.html
Normal file
65
SWIG/Examples/perl5/variables/index.html
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>SWIG:Examples:perl5:variables</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
|
||||
<tt>SWIG/Examples/perl5/variables/</tt>
|
||||
<hr>
|
||||
|
||||
<H2>Wrapping C Global Variables</H2>
|
||||
|
||||
<tt>$Header$</tt><br>
|
||||
|
||||
<p>
|
||||
When a C global variable appears in an interface file, SWIG tries to
|
||||
wrap it using a technique known as "variable linking." The idea is
|
||||
pretty simple---we try to create a Perl variable that magically
|
||||
retrieves or updates the value of the underlying C variable when it is
|
||||
accessed. Click <a href="example.i">here</a> to see a SWIG interface with some variable
|
||||
declarations in it.
|
||||
|
||||
<h2>Manipulating Variables from Perl</h2>
|
||||
|
||||
Accessing a C global variable from Perl is easy---just reference it like a normal Perl variable.
|
||||
Click <a href="example.pl">here</a> to see a script that updates and prints some global variables.
|
||||
|
||||
<h2>Creating read-only variables</h2>
|
||||
|
||||
The <tt>%readonly</tt> and <tt>%readwrite</tt> directives can be used to
|
||||
specify a collection of read-only variables. For example:
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
%readonly
|
||||
int status;
|
||||
double blah;
|
||||
...
|
||||
%readwrite
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
The <tt>%readonly</tt> directive remains in effect until it is explicitly disabled
|
||||
using the <tt>%readwrite</tt> directive.
|
||||
|
||||
|
||||
<h2>Notes:</h2>
|
||||
|
||||
<ul>
|
||||
<li>When a global variable has the type "<tt>char *</tt>", SWIG manages it as a character
|
||||
string. However, whenever the value of such a variable is set from Perl, the old
|
||||
value is destroyed using <tt>free()</tt> or <tt>delete</tt> (the choice of which depends
|
||||
on whether or not SWIG was run with the -c++ option).
|
||||
<li><tt>signed char</tt> and <tt>unsigned char</tt> are handled as small 8-bit integers.
|
||||
<li>String array variables such as '<tt>char name[256]</tt>' are managed as Perl strings, but
|
||||
when setting the value, the result is truncated to the maximum length of the array. Furthermore, the string is assumed to be null-terminated.
|
||||
<li>When structures and classes are used as global variables, they are mapped into pointers.
|
||||
Getting the "value" returns a pointer to the global variable. Setting the value of a structure results in a memory copy from a pointer to the global.
|
||||
<li>Variables are linked using Perl's magic mechanism. Take a look at the Advanced Perl Programming book to
|
||||
find out more about this feature.
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
<hr>
|
||||
Loading…
Add table
Add a link
Reference in a new issue