10.3 Hooks programming interface

Preprocessor Macro: mbfl_hook_declare (HOOK_NAME)

Declare a hook’s variables using declare, making all of them local or global depending on the context of the macro use. This macro is a wrapper for mbfl_declare_varref().

Preprocessor Macro: mbfl_hook_global_declare (HOOK_NAME)

Declare a global hook variable using declare -g, but define HOOK_NAME using declare making it local or global depending on the context of the macro use. This macro is a wrapper for mbfl_declare_varref().

Function: mbfl_hook_define HOOK

Initialise a new already declared HOOK. If HOOK has been previously used: this function removes all the old registered commands.

Function: mbfl_hook_undefine HOOK

Finalise the existent HOOK; all the registered commands are removed. To use again this variable we have to apply mbfl_hook_define() to it.

Function: mbfl_hook_add HOOK HOOK_COMMAND
Function: mbfl_hook_add HOOK HOOK_COMMAND IDVAR

Add to HOOK the command HOOK_COMMAND. When we run the hook: HOOK_COMMAND is executed with:

eval HOOK_COMMAND

If the optional parameter IDVAR is present: it must be the name of a variable in the scope of the caller, which will be set to a unique identifier associated to the added command; later we can use such identifier to remove the command with mbfl_hook_remove().

Function: mbfl_hook_remove HOOK COMMAND_ID

Remove from the HOOK the command associated to COMMAND_ID, which must have been obtained with a previous call to mbfl_hook_remove(). When successful: return true. If COMMAND_ID is not a command’s identifier: return false, but nothing else happens.

Function: mbfl_hook_has_commands HOOK

Return true if HOOK has commands registered for execution; otherwise return false.

Function: mbfl_hook_remove_commands HOOK

Remove all the registered commands in HOOK.

Function: mbfl_hook_run HOOK

Run all the commands in HOOK, from the first added to the last added.

Function: mbfl_hook_reverse_run HOOK

Run all the commands in HOOK in reverse order, from the last added to the first added.


This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.