Extension summary (The GNU Awk User’s Guide)
From Get docs
- You can write extensions (sometimes called plug-ins) for
gawkin C or C++ using the application programming interface (API) defined by the
- Extensions must have a license compatible with the GNU General Public License (GPL), and they must assert that fact by declaring a variable named
- Communication between
gawkand an extension is two-way.
structto the extension that contains various data fields and function pointers. The extension can then call into
gawkvia the supplied function pointers to accomplish certain tasks.
- One of these tasks is to “register” the name and implementation of new
awk-level functions with
gawk. The implementation takes the form of a C function pointer with a defined signature. By convention, implementation functions are named
- 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:
- 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 the
gawkthat loaded it.
- It is easiest to start a new extension by copying the boilerplate code described in this chapter. Macros in the
gawkapi.hheader file make this easier to do.
gawkdistribution includes a number of small but useful sample extensions. The
gawkextlibproject includes several more (larger) extensions. If you wish to write an extension and contribute it to the community of
gawkextlibproject is the place to do so.