If you wish to multiplex (overload) by number of arguments, I highly recommend having a simple subroutine written in Perl that does the multiplexing.
You can either have several XS methods named things like method_2, method_3, method_4, or (usually better) have the Perl subroutine fill in defaults when too few arguments are given and just have one (or maybe two) XS routines that expect lots of arguments.
The less code in the *.xs file and the more in the *.pm file, the happier you and your module users will be. Although it is possible to do lots of fancy argument validation and processing in the *.xs file, it is hard to learn, hard to get right, hard to debug, hard to understand after you've (or someone else has) written it, hard to upgrade later, leads to sub-standard interfaces, and is more likely to break with new versions of Perl.
Better still, is to make the API better than it was in C++ by using (at least some) named arguments, which is quite easy to do in a Perl subroutine. See createFile() in Win32API::File for an example.
-
tye
(but my friends call me "Tye")
| [reply] |
A little experimentation reveals "No."
(Though, I would have hoped you had
already done that.)
However you can use (...),
to specify your parameters to one xsub and have
that xsub look at how many arguments it has,
and maybe their types, and
call what should be called.
(Of course, see perlxs.)
Alternately, of course, you could
have multiple xsubs and have a perl function
that would call the right one in the same way.
And, by the way, C does not support overloaded functions.
C++ does, however.
| [reply] [d/l] |
Of course. How do you think perl himself handles the select-function?
If you need to declare two XS with one paramset each or one XS with
varying args I don't know. I don't deal in XS but one method works for
sure. | [reply] |