$self special variable for %extend

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9530 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2006-11-08 00:54:28 +00:00
commit 1a439a9e19
8 changed files with 62 additions and 30 deletions

View file

@ -2356,18 +2356,23 @@ You can make a <tt>Vector</tt> look a lot like a class by writing a SWIG interfa
return v;
}
~Vector() {
free(self);
free($self);
}
double magnitude() {
return sqrt(self-&gt;x*self-&gt;x+self-&gt;y*self-&gt;y+self-&gt;z*self-&gt;z);
return sqrt($self-&gt;x*$self-&gt;x+$self-&gt;y*$self-&gt;y+$self-&gt;z*$self-&gt;z);
}
void print() {
printf("Vector [%g, %g, %g]\n", self-&gt;x,self-&gt;y,self-&gt;z);
printf("Vector [%g, %g, %g]\n", $self-&gt;x,$self-&gt;y,$self-&gt;z);
}
};
</pre></div>
<p>
Note the usage of the <tt>$self</tt> special variable.
Its usage is identical to a C++ 'this' pointer and should be used whenever access to the struct instance is required.
</p>
<p>
Now, when used with proxy classes in Python, you can do things like
this :</p>