Public
Snippet $1655245 authored by Jesse

Perl interpreter in C++

Edited
perlC++interp.cpp
/*\
 * File: perlC++interp.cpp
 * Language: C++
 * Version: 0
 * Author: culb (nightfrog)
 * Contact: the01culb[at]gmail[dot]com
 *
 * Compile:
 * clang++ -Wall -std=c++11 perlC++interp.cpp -o interp `perl -MExtUtils::Embed -e ccopts -e ldopts`
 * g++ -Wall -std=c++11 perlC++interp.cpp -o interp `perl -MExtUtils::Embed -e ccopts -e ldopts`
 *
 * Note: Tested with clang 3.5 and gcc 4.9
 *
 * Reference: http://perldoc.perl.org/perlembed.html
 *
 * License:
 *  If this code is used in any way then
 *  be courteous and include all of my information and notes
\*/
 
 
/* Perl */
/* Shoud these be extern "C"? */
#include <EXTERN.h>
#include <perl.h>
 
#include <cstdlib> /* exit */
 
 
auto main
( int argc, char **argv, char **envp ) ->
int
{
  static PerlInterpreter *my_perl;
  my_perl = perl_alloc();
 
  if( my_perl )
  {
    perl_construct( my_perl );
 
    perl_parse( my_perl, nullptr, argc, argv, envp );
    perl_run( my_perl );
 
    perl_destruct( my_perl );
    perl_free( my_perl );
 
    std::exit( EXIT_SUCCESS );
  }
 
  /* Something failed */
  std::exit( EXIT_FAILURE );
}