> ## 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.

# getstack

> Reads stack slot values from a Lua stack frame. level is required and must be a number; it is converted to an integer and must be between 0 and the current call stack depth minus one. Invalid levels raise "Level out of range". The selected frame is L->ci - level, so level 0 refers to the current frame in this function. If the selected frame is a C closure, the function raises "Lua function expected". index is optional and is only used when the second argument is a number; it is converted to an integer and must be between 1 and the frame stack size. Without a numeric index, the function returns a one-based array table containing values from frame->base[0] with frame->base[top - 1]. With a numeric index, it returns the single value at frame->base[index - 1]. Collectable values trigger luaC_threadbarrier before being pushed. debug.getstack is exposed with the debug table alias.

Reads stack slot values from a Lua stack frame. level is required and must be a number; it is converted to an integer and must be between 0 and the current call stack depth minus one. Invalid levels raise "Level out of range". The selected frame is L->ci - level, so level 0 refers to the current frame in this function. If the selected frame is a C closure, the function raises "Lua function expected". index is optional and is only used when the second argument is a number; it is converted to an integer and must be between 1 and the frame stack size. Without a numeric index, the function returns a one-based array table containing values from frame->base\[0] with frame->base\[top - 1]. With a numeric index, it returns the single value at frame->base\[index - 1]. Collectable values trigger luaC\_threadbarrier before being pushed. debug.getstack is exposed with the debug table alias.

## Syntax

```lua theme={null}
getstack(level: number, index?: number): table | any
```

## Aliases

* `debug.getstack`

## Arguments

| Name    | Type     | Required | Description                                                                                           |
| ------- | -------- | -------- | ----------------------------------------------------------------------------------------------------- |
| `level` | `number` | Yes      | Stack level number converted to an integer. Must be in range 0 \<= level \< current call stack depth. |
| `index` | `number` | No       | Optional one-based stack slot index. It is used only when the second argument is a number.            |

## Returns

| Name    | Type           | Description                                                                                                                        |
| ------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `stack` | `table \| any` | A one-based table of stack slot values when index is omitted or not numeric, or the single stack slot value when index is numeric. |

## Example

Read stack slot values from a Lua stack frame.

```lua theme={null}
local function inspect(value)
    local stack = getstack(1)
    local first = getstack(1, 1)

    print(type(stack))
    print(type(first))
    print(debug.getstack(1, 1) == first)
end

inspect("ready")
```
