Chapter 19. Embedding Perl:The Easy Way
A rock pile ceases to be a rock pile the moment a single man contemplates it, bearing within him the image of a cathedral.
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 book), 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 [1] 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:
- Power through scripted extensions
Applications such as Emacs, Microsoft Office, and Autocad provide scripting language frontends. Although they work reasonably well on their own, their real power comes from the large community ...
Get Advanced Perl Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.