in reply to Perl API,external C library and blessing a hashref

Either technique works. I've blessed my objects at the C level (though I use XS, not Inline::C). In addition, I've used the '~' magic to store an SV that holds the pointer to the data for the C struct that describes the object.

Something like

thv = (HV*)sv_2mortal((SV*)newHV()); sv = newSViv((IV)info); sv_magic((SV*)thv, sv, '~', "CTlib", 5); SvRMAGICAL_on((SV*)thv); rv = newRV((SV*)thv); stash = gv_stashpv("Sybase::CTlib::_attribs", TRUE); (void)sv_bless(rv, stash);
Then you can get the "info" structure from the hashref via mg_find().

Note that this code is pretty old, and there might be better ways to do this sort of things in more recent versions of perl.

Michael

Replies are listed 'Best First'.
Re: Re: Perl API,external C library and blessing a hashref
by bakunin (Scribe) on May 19, 2004 at 17:15 UTC
    Thanks Michael!! It's working like a charm. My gawd! It's beautiful...

    I need to look into the MAGIC* now. :)

    Ogla
      Go read the perlguts and perlapi docs for some information about this...

      Michael