For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > June 2004 > Dealing with lists with SWIG.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Dealing with lists with SWIG.
Motti Lanzkron

2004-06-25, 6:48 pm

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?
Tassilo v. Parseval

2004-06-25, 6:48 pm

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
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{re
htonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
Motti Lanzkron

2004-06-25, 6:48 pm

Tassilo v. Parseval wrote:
>Also sprach Motti Lanzkron:
>
....[color=darkred]
>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).
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com