Skip to content

Data Stack

scripts/vscripts/alyxlib/data/stack.lua

Methods

Push

Pushes values to the stack.

Stack:Push(...)

Parameters

  • ...

Pop

Pops values from the stack.

Stack:Pop(count)

Parameters

  • count (optional)
    number
    Number of items to pop

Returns - ...

Top

Peeks at a number of items on the top of the stack without removing them.

Stack:Top(count)

Parameters

  • count (optional)
    number
    Number of items to peek

Returns - ...

Bottom

Peeks at a number of items on the bottom of the stack without removing them.

Stack:Bottom(count)

Parameters

  • count (optional)
    number
    Number of items to peek

Returns - ...

Remove

Removes a value from the stack regardless of its position.

Stack:Remove(value)

Parameters

  • value
    any
    The value to remove

MoveToTop

Moves an existing value to the top of the stack.

Only the first occurance will be moved.

Stack:MoveToTop(value)

Parameters

  • value
    any
    The value to move

Returns - boolean True if value was found and moved

MoveToBottom

Moves an existing value to the bottom of the stack.

Only the first occurance will be moved.

Stack:MoveToBottom(value)

Parameters

  • value
    any
    The value to move

Returns - boolean True if value was found and moved

Contains

Gets if this stack contains a value.

Stack:Contains(value)

Parameters

  • value
    any
    The value to search for

Returns - boolean True if the value is in the stack

Length

Returns the number of items in the stack.

Stack:Length()

Returns - integer The number of items

IsEmpty

Gets if the stack is empty.

Stack:IsEmpty()

Returns - boolean True if the stack is empty

pairs

Helper method for looping.

Stack:pairs()

Returns

  • function

  • any[]

  • number
    i

Functions

Stack

Creates a new Stack object.

First value is at the top.

E.g.

Example
local stack = Stack(
    "Top",
    "Middle",
    "Bottom"
)
Stack(...)

Parameters

  • ...

Returns - Stack

Types

Stack

Stack data structure.