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?


In reply to perlxs: How to Create C++ object and call it's functions through perl by runiaz

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.