There needs to be a typemap that will explain to Perl how to bind a rect * to a Perl structure of some sort. There are several CPAN modules that help to simplify the process. The one I'm most familiar with is Inline::CPP. But I'm highly biased.

The gist of it is that you can create a C++ class that maps to a Perl class. The constructor becomes new(). The destructor becomes DESTROY(), and so on. The docs for Inline::C, Inline::C-Cookbook, and Inline::CPP are required reading in getting started with it. But it's fun (if you're slightly masochistic) once you get the hang of it.

Inline::Struct is compatible with C (ie, doesn't require C++), and will bind C structures to Perl objects too.

There was a time when Inline::CPP wasn't installing on the vast majority of systems out there. Over the last few months we've gotten it to the point that there's only one class of smoke testers that are still having trouble with it (NetBSD -- Any NetBSD pros get in touch with me so we can try to figure it out). Most other common platforms are able to install it and use it. There's also an email list where people can answer questions about the Inline modules: inline@perl.org. See http://lists.perl.org for details.


Dave


In reply to Re: returning an object in XS by davido
in thread returning an object in XS by bipham

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.