I'm writing C code that that calls perl. The perl code is in the form of a .pm that will be installed in the usual way. The approach I have taken is to call load_module something like:
load_module(PERL_LOADMOD_NOIMPORT, newSVpvn("My::Module", 10), newSVnv(0.01));
I follow this by pushing the module name onto the stack and instantiating an object by calling call_method("new", G_SCALAR));

I then push the resulting object and some args onto the stack and invoke call_method on the method name. It seems to necessary to call perl_parse, so I do, passing in "/dev/null" as the file name.

char *theArgv[] = { "", "/dev/null" }; perl_parse(my_perl, xs_init, 2, theArgv, (char **) NULL);
All this actually seems to work pretty swell, but I've encountered one difficulty. Any diagnostics originating in the perl code, e.g. "warn"s, etc., give bogus file and line numbers presumably because, having been pulled in via the load_module call, the code was never parsed:

Bad data at /dev/null line 0

I'd like to use the load_module mechanism and yet have the perl interpretter informed of code, for diagnostic reference.

[I can post more code, if helpful. But the actual code is on an isolated host, inaccessible by network.]

Any ideas?


In reply to Embed: Using load_module by sjfloat

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.