Dealing with lists with SWIG.

M

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++:
 
T

Tassilo v. Parseval

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
 
M

Motti Lanzkron

Tassilo said:
Also sprach Motti Lanzkron:
....
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.

Unfortunately I lack the time and patience, I'll just write the whole
thing in C++ (which will probably end up taking more time ;o).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top