Dealing with lists with SWIG.

Discussion in 'Perl Misc' started by Motti Lanzkron, Jun 23, 2004.

  1. 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?
    Motti Lanzkron, Jun 23, 2004
    #1
    1. Advertising

  2. 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{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
    $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
    Tassilo v. Parseval, Jun 23, 2004
    #2
    1. Advertising

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

    ....
    >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).
    Motti Lanzkron, Jun 24, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JustSomeGuy

    Sorting lists of lists...

    JustSomeGuy, Jun 17, 2004, in forum: C++
    Replies:
    0
    Views:
    318
    JustSomeGuy
    Jun 17, 2004
  2. Jon Slaughter

    lists of lists

    Jon Slaughter, Dec 13, 2004, in forum: C++
    Replies:
    4
    Views:
    419
    Buster
    Dec 13, 2004
  3. Charlotte Henkle

    Counter for items in lists in lists?

    Charlotte Henkle, Sep 25, 2004, in forum: Python
    Replies:
    8
    Views:
    398
    Charlotte Henkle
    Sep 26, 2004
  4. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    401
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  5. stas poritskiy

    Dealing with Lists

    stas poritskiy, Sep 10, 2013, in forum: Python
    Replies:
    14
    Views:
    191
    Peter Otten
    Sep 11, 2013
Loading...

Share This Page