Greetings programs,

I am attempting to write a complete perl interface to an existing library and SDK. The library is centered around processing of a data stream and is written in C; it has a few simple interface functions, and uses a user specified callback function to do all the work.

I've read (okay, somewhere btw. skimmed and read) perlcall, perlapi and perlguts. I've managed to write C code, and a special C wrapper for a user specified perl callback function. This part works. I can currently compile my C code, start it, and it will run the callback function which is written in perl. (every invocation of the C callback does a sv_setpvn, ..., call_pv, POPpx, memcpy, &c)

I've also written XS code to successfully let me access the other functions in the library (other than the register_callback function) successfully.

My question is this: What do I write in my XS code to let me ... run code in the calling interpreter's instance? When I try to call newSVpv in a c file being linked against my XS file I get errors about *my_perl not existing. Is there some XS function or keyword to get a pointer to the calling perl instance? My goal is to have a 'registercb' function in the XS file (which takes SV *name), and have the c-language callback function use call_sv (name ..).

Any help? Has anyone written a perl interface to a callback based library before that can offer advice?


In reply to perl->c->perl by jpollack

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.