$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:
parent
0cccd3cabe
commit
1a439a9e19
8 changed files with 62 additions and 30 deletions
|
|
@ -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->x*self->x+self->y*self->y+self->z*self->z);
|
||||
return sqrt($self->x*$self->x+$self->y*$self->y+$self->z*$self->z);
|
||||
}
|
||||
void print() {
|
||||
printf("Vector [%g, %g, %g]\n", self->x,self->y,self->z);
|
||||
printf("Vector [%g, %g, %g]\n", $self->x,$self->y,$self->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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue