in reply to XSUBs with variable input types
But even if it doesn't, you could always build your own polymorphic GetName by simply saying the argument is an SV * and determining the exact type by yourself with something like (untested):
... GetName(SV *thingy) PREINIT: IV tmp; CODE: if (sv_derived_from(thingy, "Foo")) { fooRef foo; tmp = SvIV((SV*) SvRV(thingy)); foo = INT2PTR(fooRef, tmp); getName(foo); } else if (sv_derived_from(thingy, "Bar")) { barRef bar; tmp = SvIV((SV*) SvRV(thingy)); bar = INT2PTR(barRef, tmp); getName(bar); } else if (sv_derived_from(thingy, "Baz")) { bazRef baz; tmp = SvIV((SV*) SvRV(thingy)); baz = INT2PTR(bazRef, tmp); getName(baz); } else croak("Some unhandled argument type message"); ...
Doing it like that is not necessarily a good idea though. If Foo, Bar and Baz form the basis of separate object hierarchies at the perl level, it probably makes more sense to have a GetName for each object type in your XS code. No need to pollute the accessor name with the type though, just have them all in a different MODULE/PACKAGE section.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XSUBs with variable input types
by crenz (Priest) on Oct 25, 2004 at 09:01 UTC | |
by thospel (Hermit) on Oct 25, 2004 at 09:40 UTC | |
by crenz (Priest) on Oct 26, 2004 at 02:00 UTC |