The great merge
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6fcc22a1f8
commit
516036631c
5 changed files with 125431 additions and 43485 deletions
9
SWIG/Examples/python/variables/.cvsignore
Normal file
9
SWIG/Examples/python/variables/.cvsignore
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
*.dll
|
||||
*.dsw
|
||||
*.ncb
|
||||
*.opt
|
||||
*.plg
|
||||
Release
|
||||
Debug
|
||||
|
|
@ -13,6 +13,7 @@ static::
|
|||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_static
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.o *~ *.so mypython *.pyc .~* core
|
||||
$(MAKE) -f $(TOP)/Makefile python_clean
|
||||
rm -f $(TARGET).py
|
||||
|
||||
check: all
|
||||
|
|
|
|||
|
|
@ -27,10 +27,10 @@ extern Point pt;
|
|||
|
||||
/* Some read-only variables */
|
||||
|
||||
%readonly {
|
||||
%immutable;
|
||||
extern int status;
|
||||
extern char path[256];
|
||||
}
|
||||
%mutable;
|
||||
|
||||
/* Some helper functions to make it easier to test */
|
||||
extern void print_vars();
|
||||
|
|
|
|||
|
|
@ -69,21 +69,21 @@ Getting the "value" returns a pointer to the global variable. Setting the value
|
|||
|
||||
<h2>Creating read-only variables</h2>
|
||||
|
||||
The <tt>%readonly</tt> and <tt>%readwrite</tt> directives can be used to
|
||||
The <tt>%immutable</tt> and <tt>%mutable</tt> directives can be used to
|
||||
specify a collection of read-only variables. For example:
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
%readonly
|
||||
%immutable;
|
||||
int status;
|
||||
double blah;
|
||||
...
|
||||
%readwrite
|
||||
%mutable;
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
The <tt>%readonly</tt> directive remains in effect until it is explicitly disabled
|
||||
using the <tt>%readwrite</tt> directive.
|
||||
The <tt>%immutable</tt> directive remains in effect until it is explicitly disabled
|
||||
using the <tt>%mutable</tt> directive.
|
||||
|
||||
<h2>Comments</h2>
|
||||
<ul>
|
||||
|
|
|
|||
76
SWIG/Examples/python/variables/runme.py
Normal file
76
SWIG/Examples/python/variables/runme.py
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
# file: example.py
|
||||
|
||||
import example
|
||||
|
||||
# Try to set the values of some global variables
|
||||
|
||||
example.cvar.ivar = 42
|
||||
example.cvar.svar = -31000
|
||||
example.cvar.lvar = 65537
|
||||
example.cvar.uivar = 123456
|
||||
example.cvar.usvar = 61000
|
||||
example.cvar.ulvar = 654321
|
||||
example.cvar.scvar = -13
|
||||
example.cvar.ucvar = 251
|
||||
example.cvar.cvar = "S"
|
||||
example.cvar.fvar = 3.14159
|
||||
example.cvar.dvar = 2.1828
|
||||
example.cvar.strvar = "Hello World"
|
||||
example.cvar.cstrvar = "Goodbye"
|
||||
example.cvar.iptrvar= example.new_int(37)
|
||||
example.cvar.ptptr = example.new_Point(37,42)
|
||||
example.cvar.name = "Bill"
|
||||
|
||||
# Now print out the values of the variables
|
||||
|
||||
print "Variables (values printed from Python)"
|
||||
|
||||
print "ivar =", example.cvar.ivar
|
||||
print "svar =", example.cvar.svar
|
||||
print "lvar =", example.cvar.lvar
|
||||
print "uivar =", example.cvar.uivar
|
||||
print "usvar =", example.cvar.usvar
|
||||
print "ulvar =", example.cvar.ulvar
|
||||
print "scvar =", example.cvar.scvar
|
||||
print "ucvar =", example.cvar.ucvar
|
||||
print "fvar =", example.cvar.fvar
|
||||
print "dvar =", example.cvar.dvar
|
||||
print "cvar =", example.cvar.cvar
|
||||
print "strvar =", example.cvar.strvar
|
||||
print "cstrvar =", example.cvar.cstrvar
|
||||
print "iptrvar =", example.cvar.iptrvar
|
||||
print "name =", example.cvar.name
|
||||
print "ptptr =", example.cvar.ptptr, example.Point_print(example.cvar.ptptr)
|
||||
print "pt =", example.cvar.pt, example.Point_print(example.cvar.pt)
|
||||
|
||||
print "\nVariables (values printed from C)"
|
||||
|
||||
example.print_vars()
|
||||
|
||||
print "\nNow I'm going to try and modify some read only variables";
|
||||
|
||||
print " Tring to set 'path'";
|
||||
try:
|
||||
example.cvar.path = "Whoa!"
|
||||
print "Hey, what's going on?!?! This shouldn't work"
|
||||
except:
|
||||
print "Good."
|
||||
|
||||
print " Trying to set 'status'";
|
||||
try:
|
||||
example.cvar.status = 0
|
||||
print "Hey, what's going on?!?! This shouldn't work"
|
||||
except:
|
||||
print "Good."
|
||||
|
||||
|
||||
print "\nI'm going to try and update a structure variable.\n"
|
||||
|
||||
example.cvar.pt = example.cvar.ptptr
|
||||
|
||||
print "The new value is"
|
||||
example.pt_print()
|
||||
print "You should see the value", example.Point_print(example.cvar.ptptr)
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in a new issue