Esteemed Monks,
I have been playing with Inline::C and the Perl API recently. What a fun way to program!!

Here is my question:

Simply put, I'm accessing an external C-Library with Inline::C, and I want the C constructor wrapper to bless a hashref, not a scalar. The object, then, could call other wrappers as well as storing some other data in its slots. Let me illustrate this with some code:

package Foo; ## Inline part skipped. __C__ SV* new() { HV* hv = newHV(); Foo* foo = newFoo(); //C constructor. // Now, do something with hv and foo, then return blessed_hashref; } void setName(SV* obj, char* name) { Foo* foo = get_foo_from(obj); // and call the Foo-C method: Foo_set_name(foo); } package main; my $foo = Foo->new(); $foo->setName("Lorelai"); $foo->{shortname} = "Rory";

Does this make sense? Or should I not bother the blessed scalar and simply create a hash based Perl class to wrap it?

Thanks!

In reply to Perl API,external C library and blessing a hashref by bakunin

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.