The Perl API is the list of public functions that can be called from your own C code, into the Perl interpreter implementation.
The exact documentation perlapi is generated from the source code itself, and varies from one version to another. By and large, the core developers take care to ensure that an existing public function will continue to exist in all future implementation. This is often achieved by a using a macro as a shim over a new-style function.
Your C code will always need to include two header files:
The first header file is rather small, and is used to set up how to access the global interepreter variables in a cross-platform compiler-independent manner, when you're outside the interpreter.
The second header is good reading. It gives you a clear insight into what's available and how things are laid out.
The C-level calling convention of Perl functions is really quite horrific, and not something you want to do with your bare hands. To that end, a lot of the details are swept under the rug by using what is known as XS, which is a sort of meta-C language. To use this, you want to include a third file:
If you're just starting out, XS is the way to go. One thing that helps as much as reading books, or man pages such as perlxs or perlxstut (both, sadly, beginning to show their age) is to read some source code. Have a look at some source code to modules that contain XS components, and see how they work.
Tip o' the hat to fenLisesi for spotting a typo.
• another intruder with the mooring in the heart of the Perl
|