Thompson’s rule for first-time telescope makers: “It is faster to make a four-inch mirror, then a six-inch mirror, than to make a six-inch mirror.”
Scripting is almost always a more pleasant and productive alternative to using a systems programming language. Scripting languages aren’t designed to do everything, however, and there comes a time when you need to dig down to C/C++ for speed, fine-grained data structures, type safety, and access to existing libraries. The ability of languages such as Perl, Visual Basic, Python, and Tcl to integrate well with C accords them the status of a serious development language, in contrast to awk and early versions of BASIC, which were seldom used for production applications.
In this chapter, we will examine what it takes to cement Perl and C code together and then study two tool sets that do a remarkable job of performing this binding for us. The first is a pair of tools called h2xs and xsubpp, packaged with the Perl distribution. For brevity, we will refer to this pair as XS, because it involves an intermediate language of the same name. The other tool is SWIG (Simplified Wrapper and Interface Generator), written by Dave Beazley at the University of Utah.
We’ll cover an often-used subset of these tools’ capabilities and learn that a lot can be achieved without having to know anything at all about the internal Perl API. But a number ...