---
title: "hookfunction"
description: "Installs a replacement and returns the original callable for delegation."
---

```lua
hookfunction(target: function, replacement: function): function
```

---

## Aliases

- `hookfunc`
- `replaceclosure`

---

## Arguments

<ParamField body="target" type="function" required>
  The function whose hook is installed, restored, or queried.
</ParamField>

<ParamField body="replacement" type="function" required>
  The replacement callback. Keep the returned original function when delegating calls.
</ParamField>

---

## Returns

<ResponseField name="original" type="function">
  The original callable for delegation or restoration.
</ResponseField>

Keep the returned original; calling target from its replacement can recurse. Hooks affect the target closure and references to it, not just a variable.

---

## Example

```lua
local function value() return "original" end
local original
original = hookfunction(value, function() return original() .. " + hook" end)
print(value())
restorefunction(value)
```
