---
title: "hookmetamethod"
description: "Hooks an existing function-valued metamethod and returns the original callable."
---

```lua
hookmetamethod(value: any, method: string, replacement: function): function
```

---

## Aliases

None.

---

## Arguments

<ParamField body="value" type="any" required>
  The value used by this operation.
</ParamField>

<ParamField body="method" type="string" required>
  The case-sensitive metamethod or namecall method name.
</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 metamethod callable.
</ResponseField>

Missing metatable or non-function metamethod raises. Keep the original for delegation.

---

## Example

```lua
local t = setmetatable({}, {__index = function() return "original" end})
local original
original = hookmetamethod(t, "__index", function(self, key) return original(self, key) end)
print(t.example)
restorefunction(getrawmetatable(t).__index)
```
