This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Some typo fixes reported by Tom Christiansen
[perl5.git] / pod / perlembed.pod
index a2b76fd..1144e43 100644 (file)
@@ -196,11 +196,20 @@ version of I<miniperlmain.c> containing the essentials of embedding:
 
 Notice that we don't use the C<env> pointer.  Normally handed to
 C<perl_parse> as its final argument, C<env> here is replaced by
-C<NULL>, which means that the current environment will be used.  The macros
-PERL_SYS_INIT3() and PERL_SYS_TERM() provide system-specific tune up 
-of the C runtime environment necessary to run Perl interpreters; since
-PERL_SYS_INIT3() may change C<env>, it may be more appropriate to provide
-C<env> as an argument to perl_parse().
+C<NULL>, which means that the current environment will be used.
+
+The macros PERL_SYS_INIT3() and PERL_SYS_TERM() provide system-specific
+tune up of the C runtime environment necessary to run Perl interpreters;
+they should only be called once regardless of how many interpreters you
+create or destroy. Call PERL_SYS_INIT3() before you create your first
+interpreter, and PERL_SYS_TERM() after you free your last interpreter.
+
+Since PERL_SYS_INIT3() may change C<env>, it may be more appropriate to
+provide C<env> as an argument to perl_parse().
+
+Also notice that no matter what arguments you pass to perl_parse(),
+PERL_SYS_INIT3() must be invoked on the C main() argc, argv and env and
+only once.
 
 Now compile this program (I'll call it I<interp.c>) into an executable:
 
@@ -325,15 +334,15 @@ the first, a C<float> from the second, and a C<char *> from the third.
 
        /** Treat $a as an integer **/
        eval_pv("$a = 3; $a **= 2", TRUE);
-       printf("a = %d\n", SvIV(get_sv("a", FALSE)));
+       printf("a = %d\n", SvIV(get_sv("a", 0)));
 
        /** Treat $a as a float **/
        eval_pv("$a = 3.14; $a **= 2", TRUE);
-       printf("a = %f\n", SvNV(get_sv("a", FALSE)));
+       printf("a = %f\n", SvNV(get_sv("a", 0)));
 
        /** Treat $a as a string **/
        eval_pv("$a = 'rekcaH lreP rehtonA tsuJ'; $a = reverse($a);", TRUE);
-       printf("a = %s\n", SvPV_nolen(get_sv("a", FALSE)));
+       printf("a = %s\n", SvPV_nolen(get_sv("a", 0)));
 
        perl_destruct(my_perl);
        perl_free(my_perl);
@@ -457,7 +466,7 @@ been wrapped here):
      retval = my_eval_sv(command, TRUE);
      SvREFCNT_dec(command);
 
-     *string = get_sv("string", FALSE);
+     *string = get_sv("string", 0);
      return SvIV(retval);
  }
 
@@ -481,7 +490,7 @@ been wrapped here):
      SvREFCNT_dec(command);
 
      *match_list = get_av("array", 0);
-     num_matches = av_len(*match_list) + 1; /** assume $[ is 0 **/
+     num_matches = av_len(*match_list) + 1;
 
      return num_matches;
  }
@@ -922,7 +931,6 @@ Let's give it a try:
  #include <perl.h>
 
  /* we're going to embed two interpreters */
- /* we're going to embed two interpreters */
 
  #define SAY_HELLO "-e", "print qq(Hi, I'm $^X\n)"
 
@@ -1091,7 +1099,7 @@ Finally, select Build -> Build interp.exe and you're ready to go.
 
 =head1 Hiding Perl_
 
-If you completely hide the short forms forms of the Perl public API,
+If you completely hide the short forms of the Perl public API,
 add -DPERL_NO_SHORT_NAMES to the compilation flags.  This means that
 for example instead of writing