Interface JawkExtension
- All Known Implementing Classes:
AbstractExtension,CoreExtension,StdinExtension
Instances of this interface are eligible for insertion into Jawk as an extension to the language. Extensions appear within a Jawk script as function calls.
Extensions introduce native Java modules into the Jawk language. This enables special services into Jawk, such as Sockets, GUIs, databases, etc. natively into Jawk.
Extension functions can be used anywhere an AWK function, builtin or user-defined, can be used. One immediate consideration is the default Jawk input mechanism, where if action rules exist (other than BEGIN/END), Jawk requires input from stdin before processing these rules. It may be desirable to trigger action rules on an extension rather than stdin user input. To prohibit Jawk default behavior, a new command-line argument, "-ni" for "no input", disables Jawk default behavior of consuming input from stdin for action rules.
Note: By disabling Jawk's default behavior of consuming input from stdin, it can cause your script to loop through all of the action rule conditions repeatedly, consuming CPU without bounds. To guard against this, the extension should provide some sort of poll or block call to avoid out-of-control CPU resource consumption.
Extensions introduce keywords into the Jawk parser. Keywords are of type _EXTENSION_ tokens. As a result, extension keywords cannot collide with other Jawk keywords, variables, or function names. The extension mechanism also guards against keyword collision with other extensions. The Jawk lexer expects extension keywords to match as _ID_'s.
- Author:
- Danny Daglas
-
Method Summary
Modifier and TypeMethodDescriptionReturns the mapping between Awk keywords and the functions implemented by this extension.getExtensionName.voidinit(VariableManager vm, JRT jrt, AwkSettings settings) Called after the creation and before normal processing of the extension, pass in the Jawk Runtime Manager and the Variable Manager once.
-
Method Details
-
init
Called after the creation and before normal processing of the extension, pass in the Jawk Runtime Manager and the Variable Manager once.It is guaranteed init() is called before invoke() is called.
- Parameters:
vm- Reference to the Variable Managerjrt- Reference to the Runtimesettings- Reference to the settings
-
getExtensionName
String getExtensionName()getExtensionName.
- Returns:
- name of the extension package.
-
getExtensionFunctions
Map<String,ExtensionFunction> getExtensionFunctions()Returns the mapping between Awk keywords and the functions implemented by this extension. The returned map must be unmodifiable.- Returns:
- mapping from keyword to
ExtensionFunction
-