The following Inline::CPP script seems to do what you need on perl-5.8.8 (but not on perl-5.10.0):
use warnings;
use Inline CPP => Config =>
BUILD_NOISY => 1;
use Inline CPP => <<'EOC';
void add_nir(int x, int y, AV * perlList) {
SV* perlItem=newSViv(2);
av_push(perlList, perlItem);
}
EOC
my @test = (1, 2);
print "@test\n";
my $reftest = \@test;
add_nir(1, 4, $reftest);
print "@test\n";
On perl-5.8.8 that correctly outputs:
1 2
1 2 2
and you can see that the "2" was, in fact, pushed onto the array. But, on perl-5.10.0 I get
Can't locate auto/main/add_nir.al in @INC ... which is similar to what you are getting. Apparently, one can't supply an AV* arg to an Inline::CPP function on perl-5.10.0, though there's no such problem with perl-5.8.8. I don't know whether this is an Inline::CPP bug or a perl bug - probably Inline::CPP.
The above script also works fine on perl-5.10.0 as an Inline::C script - do you really need to use Inline::CPP ? (There's a useful example of doing object-oriented inline using Inline::C in 'perldoc Inline::C-Cookbook'. Look for "Soldier".)
If you really do need Inline::CPP, you're in luck - there's a simple rewrite of the above script that has add_nir() take an SV instead of an AV, and it works fine with Inline::CPP on perl-5.10.0:
use warnings;
use Inline CPP => Config =>
BUILD_NOISY => 1;
use Inline CPP => <<'EOC';
void add_nir(int x, int y, SV * perlList) {
SV* perlItem=newSViv(2);
av_push((AV*)SvRV(perlList), perlItem);
}
EOC
my @test = (1, 2);
print "@test\n";
my $reftest = \@test;
add_nir(1, 4, $reftest);
print "@test\n";
At least that works fine for me on perl-5.10.0. Note that the perl code is exactly the same as in the first script. The only difference is in the way the add_nir() function has been constructed.
Cheers,
Rob
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.