---
title: "debug.getconstant"
description: "Returns a constant slot from a Lua prototype."
---

```lua
debug.getconstant(target: function | number, index: number): any
```

---

## Aliases

- `getconstant`

---

## Arguments

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

<ParamField body="index" type="number" required>
  A 1-based slot index.
</ParamField>

---

## Returns

<ResponseField name="constant" type="any">
  The constant in the selected slot, or nil for a function/table constant.
</ResponseField>

Indexes start at 1; out-of-bounds raises. Function/table constants are represented as nil.

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

---

## Example

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