Quoth
:
> <> wrote in comp.lang.perl.misc:
> > Hello,
> >
> > I'm looking for some resources (books, web-sites, docs ...) on how to
> > write complex perl extensions in C. I've read the perlxstut, but still
> > don't understand how to convert complex types.
> >
> > Specificly, my C-routine needs a pointer to a structure, some members
> > of this structure are pointers to type double arrays. On the perl side
> > this structure is an object. The return value of the C function is a
> > different type of structure, but again containing pointers to array (on
> > the perl side this is an object).
>
> So you want to translate Perl objects (which presumably contain lists of
> numbers) into C structs for consumption by XS routines. The basic
> method is to use pack() to build the struct in a string. You pass the
> string to the XS routine as such and cast it to a (pointer to) the type
> of struct you have built. If you have got it right (which will be
> non-trivial), you'll find a workable struct in your XS program.
>
> You'll have to use the cumbersome "p" template to create pointers
> from one part of the string to another.
Note that there are nontrivial issues regarding struct packing and the
like (you will likely need a little C program to construct the pack
template for you using offsetof). You can also pass a hash to an XS
routine that then builds the struct by pulling the members out of the
hash in C.
It may be easier to make the Perl side properly OO, or implement a tied
hash/array, and keep the data in 'C format' all the time.
Ben
--
The cosmos, at best, is like a rubbish heap scattered at random.
Heraclitus