---
title: "debug.getconstants"
description: "Returns a Lua prototype's constants by 1-based slot."
---

```lua
debug.getconstants(target: function | number): {any}
```

---

## Aliases

- `getconstants`

---

## Arguments

<ParamField body="target" type="function | number" required>
  The function to inspect, or a positive stack level identifying a caller.
</ParamField>

---

## Returns

<ResponseField name="constants" type="{any}">
  A 1-based constant table. Nil, function, and table slots are represented as nil and may leave holes.
</ResponseField>

C closures are rejected. Nil/function/table entries may be absent in the returned table; ipairs can stop early.

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

---

## Example

```lua
local function sample() return "docs-example" end
for index, value in pairs(debug.getconstants(sample)) do print(index, value) end
```
