---
title: "debug.setmetatable"
description: "Sets/removes the raw metatable."
---

```lua
debug.setmetatable(value: any, mt: table?): any
```

---

## Aliases

None.

---

## Arguments

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

<ParamField body="mt" type="table">
  The metatable to assign.
</ParamField>

---

## Returns

<ResponseField name="metatable" type="any">
  The supplied metatable argument, including nil when removing it.
</ResponseField>

Accepts nil unlike setrawmetatable. Returns one existing stack value (the mt argument in this implementation); do not assume it returns the object.

**Related types:** [Debug types & behavior](/reference/debug/types).

---

## Example

```lua
local t = {}
debug.setmetatable(t, {__index = {answer = 42}})
print(t.answer)
debug.setmetatable(t, nil)
```
