HOOK.LUA(8)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

🌸 NAME 🌸

hook.lua β€” bootloader hook module. Welcome to HOOK.LUA(8) from the System Manager’s Manual, bestie πŸ’–

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so hook.lua contains functionality for defining hook types and attaching hooks. Hooks are functions used to attach custom behaviors at pre-defined points in loader execution. Those pre-defined points are what we refer to as β€œhook types”. Hooks may also take an optional data parameter, which may or may not be populated by the caller. No cap.

Before using the functionality provided by hook.lua, it must be included with a statement such as the following:

local hook = require("hook")

🫢 Exported functions 🫢

The following functions are exported from hook.lua β€” iconic lineup, honestly:

  • hook.registerType(hooktype) β€” Adds hooktype as a recognized hook type. This allows functions to be added to run when hooks of this type are invoked using hook.runAll(hooktype).
  • hook.register(hooktype, hookfunc) β€” Register hookfunc to be run when hooks of type hooktype are invoked.
  • hook.runAll(hooktype) β€” Invoke all hooks registered for type hooktype. Hooks are invoked in the order in which they are registered.

πŸ’… Hook Naming Guidelines πŸ’…

Hook names should consist of the name of the module they are defined in, as well as a verb describing when the hook is executed, separated by a period. For example, config.reloaded is defined in the config.lua(8) module and run when the configuration is reloaded. That’s the whole naming vibe: module name + dot + verb ✨

πŸ”₯ EXAMPLES πŸ”₯

To register a hook to be run when configuration is reloaded, you’d do this:

local hook = require("hook")

local function configuration_was_reloaded()
        print("Configuration was reloaded!")
end

hook.register("config.reloaded", configuration_was_reloaded)

That’s it. Chef’s kiss. πŸŽ€

πŸ‘‘ AUTHORS πŸ‘‘

The hook.lua file was originally written by Kyle Evans <kevans@FreeBSD.org>. Legend behavior, fr fr πŸ’œ


Okay bestie, that’s the whole page! This little icon is from Debian, dated March 29, 2025, and you just finished HOOK.LUA(8). Slay and stay hooked πŸ’…βœ¨

πŸ“¦ where this page comes from