17.9 Summary
-  You can write extensions (sometimes called plug-ins) for gawkin C or C++ using the application programming interface (API) defined
by thegawkdevelopers.
-  Extensions must have a license compatible with the GNU General Public
License (GPL), and they must assert that fact by declaring a variable
named plugin_is_GPL_compatible.
-  Communication between gawkand an extension is two-way.gawkpasses astructto the extension that contains
various data fields and function pointers.  The extension can then call
intogawkvia the supplied function pointers to accomplish
certain tasks.
-  One of these tasks is to “register” the name and implementation of
new awk-level functions withgawk.  The implementation
takes the form of a C function pointer with a defined signature.
By convention, implementation functions are nameddo_XXXX()for someawk-level functionXXXX().
-  The API is defined in a header file named gawkapi.h. You must include
a number of standard header files before including it in your source file.
-  API function pointers are provided for the following kinds of operations:
-  Allocating, reallocating, and releasing memory
-  Registration functions (you may register
extension functions,
exit callbacks,
a version string,
input parsers,
output wrappers,
and two-way processors)
-  Printing fatal, nonfatal, warning, and “lint” warning messages
-  Updating ERRNO, or unsetting it
-  Accessing parameters, including converting an undefined parameter into
an array
-  Symbol table access (retrieving a global variable, creating one,
or changing one)
-  Creating and releasing cached values; this provides an
efficient way to use values for multiple variables and
can be a big performance win
-  Manipulating arrays
(retrieving, adding, deleting, and modifying elements;
getting the count of elements in an array;
creating a new array;
clearing an array;
and
flattening an array for easy C-style looping over all its indices and elements)
 
-  The API defines a number of standard data types for representing
awkvalues, array elements, and arrays.
-  The API provides convenience functions for constructing values.
It also provides memory management functions to ensure compatibility
between memory allocated by gawkand memory allocated by an
extension.
-  All memory passed from gawkto an extension must be
treated as read-only by the extension.
-  All memory passed from an extension to gawkmust come from
the API’s memory allocation functions.gawktakes responsibility for
the memory and releases it when appropriate.
-  The API provides information about the running version of gawkso
that an extension can make sure it is compatible with thegawkthat loaded it.
-  It is easiest to start a new extension by copying the boilerplate code
described in this chapter.  Macros in the gawkapi.h header
file make this easier to do.
-  The gawkdistribution includes a number of small but useful
sample extensions. Thegawkextlibproject includes several more
(larger) extensions.  If you wish to write an extension and contribute it
to the community ofgawkusers, thegawkextlibproject
is the place to do so.