perlcall - Perl calling conventions from C
The purpose of this document is to show you how to call Perl subroutines directly from C,
i.e., how to write callbacks.
Apart from discussing the C interface provided by Perl for writing callbacks the document
uses a series of examples to show how the interface actually works in practice. In addition
some techniques for coding callbacks are covered.
Examples where callbacks are necessary include
- * An Error Handler
-
You have created an XSUB interface to an application's C API.
A fairly common feature in applications is to allow you to define a C function that
will be called whenever something nasty occurs. What we would like is to be able to
specify a Perl subroutine that will be called instead.
- * An Event Driven Program
- The classic example of where callbacks are used is when writing an event driven program
like for an X windows application. In this case you register functions to be called
whenever specific events occur, e.g., a mouse button is pressed, the cursor moves into a
window or a menu item is selected.
Although the techniques described here are applicable when embedding Perl in a C program,
this is not the primary goal of this document. There are other details that must be considered
and are specific to embedding Perl. For details on embedding Perl in C refer to perlembed.
Before you launch yourself head first into the rest of this document, it would be a good
idea to have read the following two documents - perlxs and perlguts.
perlxs, perlguts, perlembed
Paul Marquess
Special thanks to the following people who assisted in the creation of the document.
Jeff Okamoto, Tim Bunce, Nick Gianniotis, Steve Kelem, Gurusamy Sarathy and Larry Wall.
Version 1.3, 14th Apr 1997
|