> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectreal.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# hookfunction

> Replaces the behavior of a target function with a replacement function and returns a callable copy of the original behavior. Both arguments must be functions.

Replaces the behavior of a target function with a replacement function and returns a callable copy of the original behavior. Both arguments must be functions.

## Syntax

```lua theme={null}
hookfunction(target: function, replacement: function): function
```

## Aliases

* `hookfunc`
* `replaceclosure`
* `detourfunction`
* `detour_function`

## Arguments

| Name          | Type       | Required | Description                                                                                                  |
| ------------- | ---------- | -------- | ------------------------------------------------------------------------------------------------------------ |
| `target`      | `function` | Yes      | Function to patch. Passing a non-function raises a type error.                                               |
| `replacement` | `function` | Yes      | Function whose function is installed into or mapped onto target. Passing a non-function raises a type error. |

## Returns

| Name       | Type       | Description                                                                  |
| ---------- | ---------- | ---------------------------------------------------------------------------- |
| `original` | `function` | Callable copy of the original target behavior before the hook was installed. |

## Example

Patch a function closure and keep a cloned original.

```lua theme={null}
local function target(value)
    return value + 1
end

local original
original = hookfunction(target, function(value)
    return original(value) * 2
end)
```
