Anybody?
On 11/13/06, Jeffrey Ratcliffe <[EMAIL PROTECTED]> wrote:
On 11/13/06, Nicholas Clark <[EMAIL PROTECTED]> wrote:
> On Mon, Nov 13, 2006 at 08:56:14AM +0100, Jeffrey Ratcliffe wrote:
>
> > There are three forms of the C++ new() function, depending on whether
> > you are providing a numerator and denominator as initialisation,
> > another fraction, or nothing. Can I wrap all three with one function,
> > or do I have to create three Perl functions?
>
> Yes, but you'll have to put in explicit logic to decide which C++ new to use
> inside your XS code. I'm unaware of any way to automatically wrap overloaded
> functions.
OK. I've tried to do this and have got two problems. The first is
casting, I'm getting with the XS fragment listed below:
Fract.xs:45: error: no matching function for call to `fract::fract(fract*&)'
fract.h:17: note: candidates are: fract::fract(long int, long int)
fract.h:16: note: fract::fract(const fract&)
fract.h:15: note: fract::fract()
I've obviously got something not quite right with the
arg = (fract *)SvIV((SV*)SvRV( arg1 ));
line. Any idea what it is?
Secondly, I can't seem to make the arguments optional. Despite the
PROTOTYPE: ;$$
line, the c code produces still starts:
if (items != 3)
Perl_croak(aTHX_ "Usage: Fract::new(CLASS, arg1, arg2)");
{
I'd be grateful for any ideas.
Thanks
Jeff
XS fragment:
fract *
fract::new(arg1, arg2)
SV * arg1
SV * arg2
PROTOTYPE: ;$$
CODE:
if (items == 3) {
RETVAL = new fract(SvIV(arg1), SvIV(arg2));
}
else if (items == 2) {
fract * arg;
arg = (fract *)SvIV((SV*)SvRV( arg1 ));
RETVAL = new fract(arg);
}
else if (items == 1) {
RETVAL = new fract;
}
OUTPUT:
RETVAL