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