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")In reply to (tye)Re: overloading functions and .XS
by tye
in thread overloading functions and .XS
by symŽ
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |