Improve documentation for multi-argument typemaps and overloading
This commit is contained in:
parent
bbd1b8ed05
commit
355f2623c7
2 changed files with 55 additions and 5 deletions
|
|
@ -4821,6 +4821,46 @@ to supply the argument count. This is automatically set by the typemap code. F
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
If your function is overloaded in C++, for example:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
int foo(int argc, char **argv);
|
||||||
|
int foo();
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
don't forget to also provide a suitable <a href="Typemaps.html#Typemaps_overloading">typecheck typemap for overloading</a>
|
||||||
|
such as:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
%typecheck(SWIG_TYPECHECK_STRING_ARRAY) (int argc, char **argv) {
|
||||||
|
$1 = PyList_Check($input) ? 1 : 0;
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
If you don't you'll get an error message along the lines of:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="shell">
|
||||||
|
<pre>
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "runme.py", line 3, in <module>
|
||||||
|
example.foo(["foo", "bar", "spam", "1"])
|
||||||
|
NotImplementedError: Wrong number or type of arguments for overloaded function 'foo'.
|
||||||
|
Possible C/C++ prototypes are:
|
||||||
|
foo(int,char **)
|
||||||
|
foo()
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<H3><a name="Python_nn61">36.9.3 Using typemaps to return arguments</a></H3>
|
<H3><a name="Python_nn61">36.9.3 Using typemaps to return arguments</a></H3>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3487,6 +3487,11 @@ maps perform the conversion described for the above example:
|
||||||
%typemap(freearg) (int argc, char *argv[]) {
|
%typemap(freearg) (int argc, char *argv[]) {
|
||||||
if ($2) free($2);
|
if ($2) free($2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Required for C++ method overloading */
|
||||||
|
%typecheck(SWIG_TYPECHECK_STRING_ARRAY) (int argc, char *argv[]) {
|
||||||
|
$1 = PyList_Check($input) ? 1 : 0;
|
||||||
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -3554,6 +3559,11 @@ Other directives such as <tt>%apply</tt> and <tt>%clear</tt> also work with mult
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Don't forget to also provide a suitable <a href="#Typemaps_overloading">typemap for overloaded functions</a>, such as <tt>%typecheck</tt> shown for foo above.
|
||||||
|
This is only required if the function is overloaded in C++.
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Although multi-argument typemaps may seem like an exotic, little used feature, there
|
Although multi-argument typemaps may seem like an exotic, little used feature, there
|
||||||
are several situations where they make sense. First, suppose you wanted to wrap
|
are several situations where they make sense. First, suppose you wanted to wrap
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue