runiaz has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I want to define class in xs file. Create it in perl and call some of it's functions.

I do like it's described in perlxsdoc:

XS file:

class color { public: color(); ~color(); }; MODULE = Mytest PACKAGE = Mytest void color::DESTROY() color * color::new()

I also create a typemap file:

1. TYPEMAP 2. color * O_OBJECT 3. 4. OUTPUT 5. # The Perl object is blessed into 'CLASS', which should be a 6. # char* having the name of the package for the blessing. 7. O_OBJECT 8. sv_setref_pv( $arg, CLASS, (void*)$var ); 9. 10. INPUT 11. O_OBJECT 12. if( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG) ) 13. $var = ($type)SvIV((SV*)SvRV( $arg )); 14. else{ 15. warn( \"${Package}::$func_name() -- $var is not a blessed SV ref +erence\" ); 16. XSRETURN_UNDEF; 17. }

Then in perl file I write:

my $x = new color();
But I get an error : Cannot locate object method "new" via package color (perhaps you forgot to load color&)

What's wrong here?

Replies are listed 'Best First'.
Re: perlxs: How to Create C++ object and call it's functions through perl
by almut (Canon) on May 11, 2010 at 14:23 UTC
    Cannot locate object method "new" via package color (perhaps you forgot to load color&)

    So did you say "use color;" ?

    P.S.: usage of code tags (i.e. <c>...</c>) around code sections would make your post easier to decipher... ;)