Also sprach Motti Lanzkron:
I'm trying to write a Perl module in C++ and I've downloaded SWIG.
But I'm having trouble finding how to deal with lists. The examples I
see only deal with scalars.
Perl: C++:
------------------------------------
sub foo { 1 } => int foo() { return 1; }
sub bar { (1..10) } => ????
What code do I in C++ write if I want to return a list of integers?
I don't know much about SWIG other than that I dropped it after a few
minutes of disgust when I had a look at it a couple of years ago. Does
it help if you know how you'd do it in XS? It would look like:
void
bar ()
CODE:
{
register int i;
EXTEND(SP, 10); /* make room for ten values */
for (i = 0; i < 10; i++) {
ST(i) = sv_newmortal();
sv_setiv(ST(i), i);
}
XSRETURN(10);
}
Maybe you have the time and patience to make yourself acquainted with XS
or Inline::C. It is probably more difficult at the beginning, but it has
advantages on the long run. One advantage is that you can get help much
more easily.
Tassilo