Skip to main content

Stack

A Stack is a LIFO (Last In First Out) data structure.

Properties

Length

Stack.Length: int

The length of the Stack.

Functions

new

Stack.new() → Stack<T>

Creates an empty Stack.

Is

Stack.Is(
Value: any--

The value to check.

) → boolean--

Whether or not the passed value is a Stack.

Determines whether the passed value is a Stack.

Push

Stack:Push(
Value: T--

The value you are pushing.

) → int--

The passed value's location.

Pushes the passed value to the end of the Stack.

Errors

TypeDescription
"InvalidValue"Thrown when the value is nil.

Pop

Stack:Pop() → T?--

The last value from the Stack, if it exists.

Removes the last value from the Stack.

GetTop

Stack:GetTop() → T?--

The last value.

Gets the last value of the Stack.

GetBottom

Stack:GetBottom() → T?--

The first value.

Gets the first value of the Stack.

IsEmpty

Stack:IsEmpty() → boolean--

Whether or not the Stack is empty.

Determines if the Stack is empty.

Iterator

Stack:Iterator() → StackIterator--

The iterator, which is used in a for loop.

Returns an iterator that can be used to iterate through the Stack. This is just an alias for ipairs, which you can use instead. This only exists for consistency reasons.

Performance

If you care about performance, do not use this function. Just do for Index, Value in ipairs(Stack) do directly.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Creates an empty `Stack`.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Stack<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 25,
                "path": "src/DataStructures/Stack/init.lua"
            }
        },
        {
            "name": "Is",
            "desc": "Determines whether the passed value is a Stack.",
            "params": [
                {
                    "name": "Value",
                    "desc": "The value to check.",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "Whether or not the passed value is a Stack.",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 34,
                "path": "src/DataStructures/Stack/init.lua"
            }
        },
        {
            "name": "Push",
            "desc": "Pushes the passed value to the end of the Stack.",
            "params": [
                {
                    "name": "Value",
                    "desc": "The value you are pushing.",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "The passed value's location.",
                    "lua_type": "int"
                }
            ],
            "function_type": "method",
            "errors": [
                {
                    "lua_type": "\"InvalidValue\"",
                    "desc": "Thrown when the value is nil."
                }
            ],
            "source": {
                "line": 45,
                "path": "src/DataStructures/Stack/init.lua"
            }
        },
        {
            "name": "Pop",
            "desc": "Removes the last value from the Stack.",
            "params": [],
            "returns": [
                {
                    "desc": "The last value from the Stack, if it exists.",
                    "lua_type": "T?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 60,
                "path": "src/DataStructures/Stack/init.lua"
            }
        },
        {
            "name": "GetTop",
            "desc": "Gets the last value of the Stack.",
            "params": [],
            "returns": [
                {
                    "desc": "The last value.",
                    "lua_type": "T?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 76,
                "path": "src/DataStructures/Stack/init.lua"
            }
        },
        {
            "name": "GetBottom",
            "desc": "Gets the first value of the Stack.",
            "params": [],
            "returns": [
                {
                    "desc": "The first value.",
                    "lua_type": "T?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 84,
                "path": "src/DataStructures/Stack/init.lua"
            }
        },
        {
            "name": "IsEmpty",
            "desc": "Determines if the Stack is empty.",
            "params": [],
            "returns": [
                {
                    "desc": "Whether or not the Stack is empty.",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 95,
                "path": "src/DataStructures/Stack/init.lua"
            }
        },
        {
            "name": "Iterator",
            "desc": "Returns an iterator that can be used to iterate through the Stack. This is just an alias for `ipairs`, which you can use instead. This only exists for consistency reasons.\n\n:::warning Performance\nIf you care about performance, do not use this function. Just do `for Index, Value in ipairs(Stack) do` directly.\n:::",
            "params": [],
            "returns": [
                {
                    "desc": "The iterator, which is used in a for loop.",
                    "lua_type": "StackIterator"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 108,
                "path": "src/DataStructures/Stack/init.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "Length",
            "desc": "The length of the Stack.",
            "lua_type": "int",
            "source": {
                "line": 20,
                "path": "src/DataStructures/Stack/init.lua"
            }
        }
    ],
    "types": [],
    "name": "Stack",
    "desc": "A Stack is a LIFO (Last In First Out) data structure.",
    "source": {
        "line": 7,
        "path": "src/DataStructures/Stack/init.lua"
    }
}