Embedding Perl:The Easy Way

Contents:
Why Embed?
Embedding Overview
Examples
Adding Extensions
Resources

rock pile ceases to be a rock pile the moment a single man contemplates it, bearing within him the image of a cathedral.

- Antoine de Saint-Exupery

Much as there are reasons for writing C extensions for Perl, there are any number of reasons to execute Perl scripts from within C/C++ applications; we refer to this activity as embedding the Perl interpreter. Embedding does not mean that we wish to conceal the interpreter; it just indicates that the application retains overall control and, when required, makes calls to the Perl internal API.

This chapter introduces a simple API for embedding the Perl interpreter in your C application. These functions are not standard (that is, they have been introduced in this tutorial), and shield you from having to know anything at all about Perl internals, reference counting, memory management, and calling conventions. Although these details will be discussed in the next chapter, you shouldn't have to know them to get useful work done. The perlembed document written by Jon Orwant and Doug MacEachern [7] provides a fine tutorial-style coverage of this subject, but expects you to be conversant with the internals.

Why Embed?

A C application can make use of a scripting language in different ways: