17150314eSKyle Evans.\" 2*4d846d26SWarner Losh.\" SPDX-License-Identifier: BSD-2-Clause 37150314eSKyle Evans.\" 47150314eSKyle Evans.\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org> 57150314eSKyle Evans.\" 67150314eSKyle Evans.\" Redistribution and use in source and binary forms, with or without 77150314eSKyle Evans.\" modification, are permitted provided that the following conditions 87150314eSKyle Evans.\" are met: 97150314eSKyle Evans.\" 1. Redistributions of source code must retain the above copyright 107150314eSKyle Evans.\" notice, this list of conditions and the following disclaimer. 117150314eSKyle Evans.\" 2. Redistributions in binary form must reproduce the above copyright 127150314eSKyle Evans.\" notice, this list of conditions and the following disclaimer in the 137150314eSKyle Evans.\" documentation and/or other materials provided with the distribution. 147150314eSKyle Evans.\" 157150314eSKyle Evans.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 167150314eSKyle Evans.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 177150314eSKyle Evans.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 187150314eSKyle Evans.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 197150314eSKyle Evans.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 207150314eSKyle Evans.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 217150314eSKyle Evans.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 227150314eSKyle Evans.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 237150314eSKyle Evans.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 247150314eSKyle Evans.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 257150314eSKyle Evans.\" SUCH DAMAGE. 267150314eSKyle Evans.\" 277150314eSKyle Evans.\" $FreeBSD$ 287150314eSKyle Evans.\" 293cb2f5f3SKyle Evans.Dd April 28, 2020 307150314eSKyle Evans.Dt HOOK.LUA 8 317150314eSKyle Evans.Os 327150314eSKyle Evans.Sh NAME 337150314eSKyle Evans.Nm hook.lua 347150314eSKyle Evans.Nd FreeBSD hook module 357150314eSKyle Evans.Sh DESCRIPTION 367150314eSKyle Evans.Nm 377150314eSKyle Evanscontains functionality for defining hook types and attaching hooks. 387150314eSKyle EvansHooks are functions used to attach custom behaviors at pre-defined points in 397150314eSKyle Evansloader execution. 407150314eSKyle EvansThese pre-defined points are what we refer to as 417150314eSKyle Evans.Dq hook types . 423cb2f5f3SKyle EvansHooks may also take an optional data parameter, which may or may not be 433cb2f5f3SKyle Evanspopulated by the caller. 447150314eSKyle Evans.Pp 457150314eSKyle EvansBefore using the functionality provided by 467150314eSKyle Evans.Nm , 477150314eSKyle Evansit must be included with a statement such as the following: 487150314eSKyle Evans.Pp 497150314eSKyle Evans.Dl local hook = require("hook") 507150314eSKyle Evans.Ss Exported functions 517150314eSKyle EvansThe following functions are exported from 527150314eSKyle Evans.Nm : 537150314eSKyle Evans.Bl -tag -width hook.registerType -offset indent 547150314eSKyle Evans.It Fn hook.registerType hooktype 557150314eSKyle EvansAdds 567150314eSKyle Evans.Ev hooktype 577150314eSKyle Evansas a recognized hook type. 587150314eSKyle EvansThis allows functions to be added to run when hooks of this type are invoked 597150314eSKyle Evansusing 607150314eSKyle Evans.Fn hook.runAll hooktype . 617150314eSKyle Evans.It Fn hook.register hooktype hookfunc 627150314eSKyle EvansRegister 637150314eSKyle Evans.Ev hookfunc 647150314eSKyle Evansto be run when hooks of type 657150314eSKyle Evans.Ev hooktype 667150314eSKyle Evansare invoked. 677150314eSKyle Evans.It Fn hook.runAll hooktype 687150314eSKyle EvansInvoke all hooks registered for type 697150314eSKyle Evans.Ev hooktype . 707150314eSKyle EvansHooks are invoked in the order in which they are registered. 717150314eSKyle Evans.El 727150314eSKyle Evans.Ss Hook Naming Guidelines 737150314eSKyle EvansHook names should consist of the name of the module they are defined in, as well 747150314eSKyle Evansas a verb describing when the hook is executed, separated by a period. 757150314eSKyle EvansFor example, 767150314eSKyle Evans.Dq config.reloaded 777150314eSKyle Evansis defined in the 787150314eSKyle Evans.Xr config.lua 8 797150314eSKyle Evansmodule and run when the configuration is reloaded. 807150314eSKyle Evans.Sh EXAMPLES 817150314eSKyle EvansTo register a hook to be run when configuration is reloaded: 827150314eSKyle Evans.Pp 837150314eSKyle Evans.Bd -literal -offset indent -compact 847150314eSKyle Evanslocal hook = require("hook") 857150314eSKyle Evans 867150314eSKyle Evanslocal function configuration_was_reloaded() 877150314eSKyle Evans print("Configuration was reloaded!") 887150314eSKyle Evansend 897150314eSKyle Evans 907150314eSKyle Evanshook.register("config.reloaded", configuration_was_reloaded) 917150314eSKyle Evans.Ed 927150314eSKyle Evans.Sh AUTHORS 937150314eSKyle EvansThe 947150314eSKyle Evans.Nm 957150314eSKyle Evansfile was originally written by 967150314eSKyle Evans.An Kyle Evans Aq Mt kevans@FreeBSD.org . 97