Mike Wong <[EMAIL PROTECTED]> writes:
>Hi all,
>
>I have a data structure that is a linked list. In my XSUB, I'd like to
>traverse that linked list and return the list as an array of objects.

FWIW you are returning a "list of objects" in the perl sense,
that is you are pushing them on the stack, not putting them in an AV.

>Here's some of my code so far:
>
>void
>tracks( self )
>       llist_node *self
>       PREINIT:
>       llist_node *node;
>       PPCODE:
>       node = self;
>       while( node != NULL ) {
>               EXTEND(SP, 1);
>               PUSHs( ???? ); <-- What goes here?
>               node = node->next;
>       }
>
>I hope you can see the part where I have no clue as to what to do :^)>.
>
>llist_node * is defined in my typemap as an O_OBJECT and returns a
>blessed scalar.

O_OBJECT seems to be a custom typemap entry - which is fine.

What does your typemap do with a list_node * to convert it to an SV ?

presumably it does something like:

      sv_setref_iv(sv, "YourClass", node);

So the loop should look like:

        while( node != NULL ) {
                SV *sv = sv_newmortal();
                sv_setref_iv(sv, "YourClass", node);
                XPUSHs(sv);
                node = node->next;
        }


Replace sv_setref_iv with whatever the OUTPUT section of your typemap
entry does.


>I've tried:
>
>PUSHs( sv_2mortal( node ));
>
>to no great success. I've run about a dozen Google searches in addition
>to the half-dozen or so searches on the archives of this list. Couldn't
>find this kind of information. Can someone please help?
>
>Thanks in advance!
>
>- m.
--
Nick Ing-Simmons
http://www.ni-s.u-net.com/


Reply via email to