Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I know of two ways to do it.

First, you can go through the Perl interface using the callback API from perlcall. That would definitely not qualify as "easy", though.

Alternatively, you can get the source library to export its C functions somehow. There are numerous ways to accomplish this, some of which are discussed in Dynaloader/XS: sharing C symbols across shared objects. Cross-platform exporting is difficult. I ultimately adopted the technique from Time::HiRes described by salva.

Here's code from Snowball.xs which makes 4 symbols from the Snowball stemming library available (sb_stemmer_list, etc):

MODULE = Lingua::Stem::Snowball PACKAGE = Lingua::Stem::Snowball PROTOTYPES: disable BOOT: { SV *sb_stemmer_list_sv = newSViv(PTR2IV(sb_stemmer_list)); SV *sb_stemmer_new_sv = newSViv(PTR2IV(sb_stemmer_new)); SV *sb_stemmer_delete_sv = newSViv(PTR2IV(sb_stemmer_delete)); SV *sb_stemmer_stem_sv = newSViv(PTR2IV(sb_stemmer_stem)); SV *sb_stemmer_length_sv = newSViv(PTR2IV(sb_stemmer_length)); hv_store(PL_modglobal, "Lingua::Stem::Snowball::sb_stemmer_list", +39, sb_stemmer_list_sv, 0); hv_store(PL_modglobal, "Lingua::Stem::Snowball::sb_stemmer_new", 3 +8, sb_stemmer_new_sv, 0); hv_store(PL_modglobal, "Lingua::Stem::Snowball::sb_stemmer_delete" +, 41, sb_stemmer_delete_sv, 0); hv_store(PL_modglobal, "Lingua::Stem::Snowball::sb_stemmer_stem", +39, sb_stemmer_stem_sv, 0); hv_store(PL_modglobal, "Lingua::Stem::Snowball::sb_stemmer_length" +, 41, sb_stemmer_length_sv, 0); }

That works for a small list of functions. It would be cumbersome and impractical for a large export list.

In reply to Re: XS from XS? by creamygoodness
in thread XS from XS? by BrowserUk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (5)
    As of 2020-12-04 20:58 GMT
    Find Nodes?
      Voting Booth?
      How often do you use taint mode?

      Results (62 votes). Check out past polls.