1*7150314eSKyle Evans.\" 2*7150314eSKyle Evans.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3*7150314eSKyle Evans.\" 4*7150314eSKyle Evans.\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org> 5*7150314eSKyle Evans.\" 6*7150314eSKyle Evans.\" Redistribution and use in source and binary forms, with or without 7*7150314eSKyle Evans.\" modification, are permitted provided that the following conditions 8*7150314eSKyle Evans.\" are met: 9*7150314eSKyle Evans.\" 1. Redistributions of source code must retain the above copyright 10*7150314eSKyle Evans.\" notice, this list of conditions and the following disclaimer. 11*7150314eSKyle Evans.\" 2. Redistributions in binary form must reproduce the above copyright 12*7150314eSKyle Evans.\" notice, this list of conditions and the following disclaimer in the 13*7150314eSKyle Evans.\" documentation and/or other materials provided with the distribution. 14*7150314eSKyle Evans.\" 15*7150314eSKyle Evans.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16*7150314eSKyle Evans.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17*7150314eSKyle Evans.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*7150314eSKyle Evans.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19*7150314eSKyle Evans.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20*7150314eSKyle Evans.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21*7150314eSKyle Evans.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22*7150314eSKyle Evans.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23*7150314eSKyle Evans.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24*7150314eSKyle Evans.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25*7150314eSKyle Evans.\" SUCH DAMAGE. 26*7150314eSKyle Evans.\" 27*7150314eSKyle Evans.\" $FreeBSD$ 28*7150314eSKyle Evans.\" 29*7150314eSKyle Evans.Dd June 9, 2018 30*7150314eSKyle Evans.Dt HOOK.LUA 8 31*7150314eSKyle Evans.Os 32*7150314eSKyle Evans.Sh NAME 33*7150314eSKyle Evans.Nm hook.lua 34*7150314eSKyle Evans.Nd FreeBSD hook module 35*7150314eSKyle Evans.Sh DESCRIPTION 36*7150314eSKyle Evans.Nm 37*7150314eSKyle Evanscontains functionality for defining hook types and attaching hooks. 38*7150314eSKyle EvansHooks are functions used to attach custom behaviors at pre-defined points in 39*7150314eSKyle Evansloader execution. 40*7150314eSKyle EvansThese pre-defined points are what we refer to as 41*7150314eSKyle Evans.Dq hook types . 42*7150314eSKyle Evans.Pp 43*7150314eSKyle EvansBefore using the functionality provided by 44*7150314eSKyle Evans.Nm , 45*7150314eSKyle Evansit must be included with a statement such as the following: 46*7150314eSKyle Evans.Pp 47*7150314eSKyle Evans.Dl local hook = require("hook") 48*7150314eSKyle Evans.Ss Exported functions 49*7150314eSKyle EvansThe following functions are exported from 50*7150314eSKyle Evans.Nm : 51*7150314eSKyle Evans.Bl -tag -width hook.registerType -offset indent 52*7150314eSKyle Evans.It Fn hook.registerType hooktype 53*7150314eSKyle EvansAdds 54*7150314eSKyle Evans.Ev hooktype 55*7150314eSKyle Evansas a recognized hook type. 56*7150314eSKyle EvansThis allows functions to be added to run when hooks of this type are invoked 57*7150314eSKyle Evansusing 58*7150314eSKyle Evans.Fn hook.runAll hooktype . 59*7150314eSKyle Evans.It Fn hook.register hooktype hookfunc 60*7150314eSKyle EvansRegister 61*7150314eSKyle Evans.Ev hookfunc 62*7150314eSKyle Evansto be run when hooks of type 63*7150314eSKyle Evans.Ev hooktype 64*7150314eSKyle Evansare invoked. 65*7150314eSKyle Evans.It Fn hook.runAll hooktype 66*7150314eSKyle EvansInvoke all hooks registered for type 67*7150314eSKyle Evans.Ev hooktype . 68*7150314eSKyle EvansHooks are invoked in the order in which they are registered. 69*7150314eSKyle Evans.El 70*7150314eSKyle Evans.Ss Hook Naming Guidelines 71*7150314eSKyle EvansHook names should consist of the name of the module they are defined in, as well 72*7150314eSKyle Evansas a verb describing when the hook is executed, separated by a period. 73*7150314eSKyle EvansFor example, 74*7150314eSKyle Evans.Dq config.reloaded 75*7150314eSKyle Evansis defined in the 76*7150314eSKyle Evans.Xr config.lua 8 77*7150314eSKyle Evansmodule and run when the configuration is reloaded. 78*7150314eSKyle Evans.Sh EXAMPLES 79*7150314eSKyle EvansTo register a hook to be run when configuration is reloaded: 80*7150314eSKyle Evans.Pp 81*7150314eSKyle Evans.Bd -literal -offset indent -compact 82*7150314eSKyle Evanslocal hook = require("hook") 83*7150314eSKyle Evans 84*7150314eSKyle Evanslocal function configuration_was_reloaded() 85*7150314eSKyle Evans print("Configuration was reloaded!") 86*7150314eSKyle Evansend 87*7150314eSKyle Evans 88*7150314eSKyle Evanshook.register("config.reloaded", configuration_was_reloaded) 89*7150314eSKyle Evans.Ed 90*7150314eSKyle Evans.Sh AUTHORS 91*7150314eSKyle EvansThe 92*7150314eSKyle Evans.Nm 93*7150314eSKyle Evansfile was originally written by 94*7150314eSKyle Evans.An Kyle Evans Aq Mt kevans@FreeBSD.org . 95