This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Quick integration of mainline changes to date
[perl5.git] / pod / perlembed.pod
index 2aadeff..3ea1736 100644 (file)
@@ -35,6 +35,8 @@ Read on...
 
 =head2 ROADMAP
 
+=over 5
+
 L<Compiling your C program>
 
 L<Adding a Perl interpreter to your C program>
@@ -139,7 +141,7 @@ you:
 
 If the B<ExtUtils::Embed> module isn't part of your Perl distribution,
 you can retrieve it from
-http://www.perl.com/perl/CPAN/modules/by-module/ExtUtils::Embed.  (If
+http://www.perl.com/perl/CPAN/modules/by-module/ExtUtils/.  (If
 this documentation came from your Perl distribution, then you're
 running 5.004 or better and you already have it.)
 
@@ -283,6 +285,7 @@ the first, a C<float> from the second, and a C<char *> from the third.
    
    main (int argc, char **argv, char **env)
    {
+       STRLEN n_a;
        char *embedding[] = { "", "-e", "0" };
    
        my_perl = perl_alloc();
@@ -301,7 +304,7 @@ the first, a C<float> from the second, and a C<char *> from the third.
    
        /** Treat $a as a string **/
        perl_eval_pv("$a = 'rekcaH lreP rehtonA tsuJ'; $a = reverse($a);", TRUE);
-       printf("a = %s\n", SvPV(perl_get_sv("a", FALSE), na));
+       printf("a = %s\n", SvPV(perl_get_sv("a", FALSE), n_a));
    
        perl_destruct(my_perl);
        perl_free(my_perl);
@@ -323,8 +326,9 @@ possible and in most cases a better strategy to fetch the return value
 from I<perl_eval_pv()> instead.  Example:
 
    ...
+   STRLEN n_a;
    SV *val = perl_eval_pv("reverse 'rekcaH lreP rehtonA tsuJ'", TRUE);
-   printf("%s\n", SvPV(val,na));
+   printf("%s\n", SvPV(val,n_a));
    ...
 
 This way, we avoid namespace pollution by not creating global
@@ -369,6 +373,7 @@ been wrapped here):
  {
      dSP;
      SV* retval;
+     STRLEN n_a;
  
      PUSHMARK(SP);
      perl_eval_sv(sv, G_SCALAR);
@@ -377,8 +382,8 @@ been wrapped here):
      retval = POPs;
      PUTBACK;
  
-     if (croak_on_error && SvTRUE(GvSV(errgv)))
-       croak(SvPVx(GvSV(errgv), na));
+     if (croak_on_error && SvTRUE(ERRSV))
+       croak(SvPVx(ERRSV, n_a));
  
      return retval;
  }
@@ -393,9 +398,10 @@ been wrapped here):
  I32 match(SV *string, char *pattern)
  {
      SV *command = NEWSV(1099, 0), *retval;
+     STRLEN n_a;
  
      sv_setpvf(command, "my $string = '%s'; $string =~ %s",
-             SvPV(string,na), pattern);
+             SvPV(string,n_a), pattern);
  
      retval = my_perl_eval_sv(command, TRUE);
      SvREFCNT_dec(command);
@@ -414,9 +420,10 @@ been wrapped here):
  I32 substitute(SV **string, char *pattern)
  {
      SV *command = NEWSV(1099, 0), *retval;
+     STRLEN n_a;
  
      sv_setpvf(command, "$string = '%s'; ($string =~ %s)",
-             SvPV(*string,na), pattern);
+             SvPV(*string,n_a), pattern);
  
      retval = my_perl_eval_sv(command, TRUE);
      SvREFCNT_dec(command);
@@ -437,9 +444,10 @@ been wrapped here):
  {
      SV *command = NEWSV(1099, 0);
      I32 num_matches;
+     STRLEN n_a;
  
      sv_setpvf(command, "my $string = '%s'; @array = ($string =~ %s)",
-             SvPV(string,na), pattern);
+             SvPV(string,n_a), pattern);
  
      my_perl_eval_sv(command, TRUE);
      SvREFCNT_dec(command);
@@ -457,6 +465,7 @@ been wrapped here):
      AV *match_list;
      I32 num_matches, i;
      SV *text = NEWSV(1099,0);
+     STRLEN n_a;
  
      perl_construct(my_perl);
      perl_parse(my_perl, NULL, 3, embedding, NULL);
@@ -478,7 +487,7 @@ been wrapped here):
      printf("matches: m/(wi..)/g found %d matches...\n", num_matches);
  
      for (i = 0; i < num_matches; i++)
-       printf("match: %s\n", SvPV(*av_fetch(match_list, i, FALSE),na));
+       printf("match: %s\n", SvPV(*av_fetch(match_list, i, FALSE),n_a));
      printf("\n");
  
      /** Remove all vowels from text **/
@@ -486,7 +495,7 @@ been wrapped here):
      if (num_matches) {
        printf("substitute: s/[aeiou]//gi...%d substitutions made.\n",
               num_matches);
-       printf("Now text is: %s\n\n", SvPV(text,na));
+       printf("Now text is: %s\n\n", SvPV(text,n_a));
      }
  
      /** Attempt a substitution **/
@@ -495,7 +504,7 @@ been wrapped here):
      }
  
      SvREFCNT_dec(text);
-     perl_destruct_level = 1;
+     PL_perl_destruct_level = 1;
      perl_destruct(my_perl);
      perl_free(my_perl);
  }
@@ -647,7 +656,7 @@ with L<perlfunc/my> whenever possible.
  #persistent.pl
 
  use strict;
use vars '%Cache';
our %Cache;
  use Symbol qw(delete_package);
 
  sub valid_package_name {
@@ -724,6 +733,7 @@ with L<perlfunc/my> whenever possible.
      char *args[] = { "", DO_CLEAN, NULL };
      char filename [1024];
      int exitstatus = 0;
+     STRLEN n_a;
 
      if((perl = perl_alloc()) == NULL) {
         fprintf(stderr, "no memory!");
@@ -744,12 +754,12 @@ with L<perlfunc/my> whenever possible.
                            G_DISCARD | G_EVAL, args);
 
             /* check $@ */
-            if(SvTRUE(GvSV(errgv)))
-                fprintf(stderr, "eval error: %s\n", SvPV(GvSV(errgv),na));
+            if(SvTRUE(ERRSV))
+                fprintf(stderr, "eval error: %s\n", SvPV(ERRSV,n_a));
         }
      }
 
-     perl_destruct_level = 0;
+     PL_perl_destruct_level = 0;
      perl_destruct(perl);
      perl_free(perl);
      exit(exitstatus);
@@ -787,16 +797,16 @@ release any resources associated with the interpreter.
 
 The program must take care to ensure that this takes place I<before>
 the next interpreter is constructed.  By default, the global variable
-C<perl_destruct_level> is set to C<0>, since extra cleaning isn't
+C<PL_perl_destruct_level> is set to C<0>, since extra cleaning isn't
 needed when a program has only one interpreter.
 
-Setting C<perl_destruct_level> to C<1> makes everything squeaky clean:
+Setting C<PL_perl_destruct_level> to C<1> makes everything squeaky clean:
 
- perl_destruct_level = 1;
PL_perl_destruct_level = 1;
 
  while(1) {
      ...
-     /* reset global variables here with perl_destruct_level = 1 */
+     /* reset global variables here with PL_perl_destruct_level = 1 */
      perl_construct(my_perl);
      ...
      /* clean and reset _everything_ during perl_destruct */
@@ -812,7 +822,7 @@ and symbol tables are cleaned up, and global variables are reset.
 Now suppose we have more than one interpreter instance running at the
 same time.  This is feasible, but only if you used the
 C<-DMULTIPLICITY> flag when building Perl.  By default, that sets
-C<perl_destruct_level> to C<1>.
+C<PL_perl_destruct_level> to C<1>.
 
 Let's give it a try:
 
@@ -891,10 +901,10 @@ to see how Perl does this:
  #  define EXTERN_C extern
  #endif
 
- static void xs_init _((void));
+ static void xs_init (void);
 
- EXTERN_C void boot_DynaLoader _((CV* cv));
- EXTERN_C void boot_Socket _((CV* cv));
+ EXTERN_C void boot_DynaLoader (CV* cv);
+ EXTERN_C void boot_Socket (CV* cv);
 
 
  EXTERN_C void
@@ -953,7 +963,7 @@ Interfacing to ActiveState's Perl library is quite different from the
 examples in this documentation, as significant changes were made to
 the internal Perl API.  However, it is possible to embed ActiveState's
 Perl runtime.  For details, see the Perl for Win32 FAQ at
-http://www.perl.com/perl/faq/win32/Perl_for_Win32_FAQ.html.
+http://www.perl.com/CPAN/doc/FAQs/win32/perlwin32faq.html.
 
 With the "official" Perl version 5.004 or higher, all the examples
 within this documentation will compile and run untouched, although