On Thu, 31 Jan 2002, Mike Wong wrote:
> 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.
Stop right there.. Have you defined what these objects should look like
to Perl? That's the first step.
A Perl object is a blessed reference. Period. It's up to you to define
the form of the object (i.e. blessed scalar, array, hash?)
The (somewhat dated) XS Cookbook Part A has a number of examples of how
one might construct and return an object from C.
> 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. 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.
>