in reply to XS and overload
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...
and call them back from XS.sub add { $_[0] + $_[1] }
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XS and overload
by BrowserUk (Patriarch) on Apr 22, 2006 at 19:16 UTC | |
by salva (Canon) on Apr 22, 2006 at 20:21 UTC | |
by BrowserUk (Patriarch) on Apr 22, 2006 at 22:05 UTC |