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.\" 273cb2f5f3SKyle Evans.Dd April 28, 2020 287150314eSKyle Evans.Dt HOOK.LUA 8 297150314eSKyle Evans.Os 307150314eSKyle Evans.Sh NAME 317150314eSKyle Evans.Nm hook.lua 327150314eSKyle Evans.Nd FreeBSD hook module 337150314eSKyle Evans.Sh DESCRIPTION 347150314eSKyle Evans.Nm 357150314eSKyle Evanscontains functionality for defining hook types and attaching hooks. 367150314eSKyle EvansHooks are functions used to attach custom behaviors at pre-defined points in 377150314eSKyle Evansloader execution. 387150314eSKyle EvansThese pre-defined points are what we refer to as 397150314eSKyle Evans.Dq hook types . 403cb2f5f3SKyle EvansHooks may also take an optional data parameter, which may or may not be 413cb2f5f3SKyle Evanspopulated by the caller. 427150314eSKyle Evans.Pp 437150314eSKyle EvansBefore using the functionality provided by 447150314eSKyle Evans.Nm , 457150314eSKyle Evansit must be included with a statement such as the following: 467150314eSKyle Evans.Pp 477150314eSKyle Evans.Dl local hook = require("hook") 487150314eSKyle Evans.Ss Exported functions 497150314eSKyle EvansThe following functions are exported from 507150314eSKyle Evans.Nm : 517150314eSKyle Evans.Bl -tag -width hook.registerType -offset indent 527150314eSKyle Evans.It Fn hook.registerType hooktype 537150314eSKyle EvansAdds 547150314eSKyle Evans.Ev hooktype 557150314eSKyle Evansas a recognized hook type. 567150314eSKyle EvansThis allows functions to be added to run when hooks of this type are invoked 577150314eSKyle Evansusing 587150314eSKyle Evans.Fn hook.runAll hooktype . 597150314eSKyle Evans.It Fn hook.register hooktype hookfunc 607150314eSKyle EvansRegister 617150314eSKyle Evans.Ev hookfunc 627150314eSKyle Evansto be run when hooks of type 637150314eSKyle Evans.Ev hooktype 647150314eSKyle Evansare invoked. 657150314eSKyle Evans.It Fn hook.runAll hooktype 667150314eSKyle EvansInvoke all hooks registered for type 677150314eSKyle Evans.Ev hooktype . 687150314eSKyle EvansHooks are invoked in the order in which they are registered. 697150314eSKyle Evans.El 707150314eSKyle Evans.Ss Hook Naming Guidelines 717150314eSKyle EvansHook names should consist of the name of the module they are defined in, as well 727150314eSKyle Evansas a verb describing when the hook is executed, separated by a period. 737150314eSKyle EvansFor example, 747150314eSKyle Evans.Dq config.reloaded 757150314eSKyle Evansis defined in the 767150314eSKyle Evans.Xr config.lua 8 777150314eSKyle Evansmodule and run when the configuration is reloaded. 787150314eSKyle Evans.Sh EXAMPLES 797150314eSKyle EvansTo register a hook to be run when configuration is reloaded: 807150314eSKyle Evans.Pp 817150314eSKyle Evans.Bd -literal -offset indent -compact 827150314eSKyle Evanslocal hook = require("hook") 837150314eSKyle Evans 847150314eSKyle Evanslocal function configuration_was_reloaded() 857150314eSKyle Evans print("Configuration was reloaded!") 867150314eSKyle Evansend 877150314eSKyle Evans 887150314eSKyle Evanshook.register("config.reloaded", configuration_was_reloaded) 897150314eSKyle Evans.Ed 907150314eSKyle Evans.Sh AUTHORS 917150314eSKyle EvansThe 927150314eSKyle Evans.Nm 937150314eSKyle Evansfile was originally written by 947150314eSKyle Evans.An Kyle Evans Aq Mt kevans@FreeBSD.org . 95