what do you want to do exactly?

Attaching overload magic to an object is atomatically done by sv_bless when an %OVERLOAD hash exist on the package (stash). That %OVERLOAD hash is initiallized by the overload module.

Initializing overloading in a module from XS can be done, but it is not a good idea as the implementation details for overloading modules could change. You should stick to using the overload module for that.

If what you want is to do some operation with perl data that could have overloaded methods, for operations that exist on the API, just look for the versions supporting magic. For the rest, for instance addition, you can use several aproaches:

The simplest and most compatible is probably to define some helper methods in Perl as...

sub add { $_[0] + $_[1] }
and call them back from XS.

Other way is to do as perl does internally. Look in its source for the tryAMAGIC set of macros (in pp.h) and emulate them in your XS code.


In reply to Re: XS and overload by salva
in thread XS and overload by BrowserUk

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.