Dear Monks!

I'm now trying to call perl functions from c code. I've already built perl with MSVS2013 Professional on Windows 7 64 bit. I'm now testing perlembed code, and I've run into problem.

Let's look at Calling a Perl subroutine from your C program.

#include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { char *args[] = { NULL }; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, argc, argv, NULL); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; /*** skipping perl_run() ***/ call_argv("showtime", G_DISCARD | G_NOARGS, args); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
My trouble is if I call some sub, it only actually executes on perl_destruct(my_perl);. I did not found what causes such behaviour in perlembed. And I don't quite understand what is happening, so I tried place perl_run(my_perl), or GL_EVAL in different places.

Okay,- I've thought,- let's try Maintaining a persistent interpreter example. I don't want to bloat my question so here is link Maintaining-a-persistent-interpreter-example
This example crashes here:

if(SvTRUE(ERRSV)) fprintf(stderr, "eval error: %s\n", SvPV_nolen(ERRSV));
When I comment this out, it still does nothing, even on perl_destruct();

So my first question: is there any manual for me to understand, what happens when call_argv() is called? I'm now reading perlguts, perlcall, however, I cannot find it. If you can, please specify me right way.:)

And second question: when call_argv(); actually executes function? Or can I force somehow to do it? Thank you!


EDIT
Okay, function is called with call_argv(). It is problem with output. Print in function, does not show up until perl_destruct()
If print STDERR is used, output appears immediatly.
/EDIT

In reply to When call_argv() actualy executes function by DrMoisha

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.