Extension summary (The GNU Awk User’s Guide)
From Get docs
Gawk/docs/latest/Extension-summary
Next: Extension Exercises, Previous: gawkextlib, Up: Dynamic Extensions [Contents][Index]
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:
- 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.hheader 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.
Next: Extension Exercises, Previous: gawkextlib, Up: Dynamic Extensions [Contents][Index]