use strict;
use warnings;
use Inline CPP => Config =>
BUILD_NOISY => 1;
use Inline CPP => <<'EOCPP';
int add(SV * a, ...) {
dXSARGS;
int i, ret = 0;
for(i = 0; i < items; i++)
ret += SvIV(ST(i));
return ret;
}
EOCPP
print add(11, 12), "\n"; # prints 23
print add(10, 11, 12), "\n"; # prints 33
####
23
33
####
use strict;
use warnings;
use Inline CPP => Config =>
BUILD_NOISY => 1;
use Inline CPP => 'DATA';
my $foo = Foo->new();
my $bar = Bar->new();
sub add {
if( @_ == 2 ) {
return $foo->add(@_);
}
return $bar->add(@_);
}
__DATA__
__CPP__
struct Foo {
add( int a, int b ) { return a + b; }
};
struct Bar {
add( int a, int b, int c ) { return a + b + c }
};