Class Stack

Stack for managing values.

The semantics of a stack is to pop the last entry to be pushed on the stack. This class follows the pattern from Lua classes.

Metamethods

Stack:__index (key) Lookup of missing class members.

Methods

Stack:create (...) Create a new instance.
Stack:_init (...) Initialize a new instance.
Stack:isEmpty () Is the stack empty.
Stack:depth () What is the depth of the internal structure.
Stack:layout () Get the layout of the stack.
Stack:bottom () Get a reference to the bottommost item in the stack.
Stack:top () Get a reference to the topmost item in the stack.
Stack:push (...) Push a value on the stack.
Stack:pop ([num=1]) Pop the last value of the stack.
Stack:drop ([num=1]) Drop the last n values of the stack.
Stack:get ([num=1]) Get the indexed entry.
Stack:export () Export a list of all the contents.
Stack:flush () Flush all the contents.


Metamethods

Stack:__index (key)
Lookup of missing class members.

Parameters:

Returns:

any

Raises:

on wrong arguments

Methods

Stack:create (...)
Create a new instance.

Parameters:

  • ... vararg forwarded to _init()

Returns:

self
Stack:_init (...)
Initialize a new instance.

Parameters:

  • ... vararg pushed on the stack

Returns:

self
Stack:isEmpty ()
Is the stack empty. Note that the internal structure is non-empty even if a nil is pushed on the stack.

Returns:

boolean whether the internal structure has length zero
Stack:depth ()
What is the depth of the internal structure. Note that the internal structure has a depth even if a nil is pushed on the stack.

Returns:

number how deep is the internal structure
Stack:layout ()
Get the layout of the stack. This method is used for testing to inspect which types of objects exists in the stack.

Returns:

table description of the stack
Stack:bottom ()
Get a reference to the bottommost item in the stack. The bottommost item can also be described as the first item. This method leaves the item on the stack.

Nicknames:

    first

Returns:

any item that can be put on the stack
Stack:top ()
Get a reference to the topmost item in the stack. The topmost item can also be described as the last item. This method leaves the item on the stack.

Nicknames:

    last

Returns:

any item that can be put on the stack
Stack:push (...)
Push a value on the stack.

Parameters:

  • ...

Returns:

self facilitate chaining
Stack:pop ([num=1])
Pop the last value of the stack. Note that this will remove the last (topmost) value.

Parameters:

  • num number items to drop (default 1)

Returns:

any item that can be put on the stack
Stack:drop ([num=1])
Drop the last n values of the stack. Note that this will remove the last (topmost) values.

Parameters:

  • num number items to drop (default 1)

Returns:

self facilitate chaining
Stack:get ([num=1])
Get the indexed entry. Accessing this will not change stored values.

Parameters:

  • num number entry, negative numbers count backwards (default 1)

Returns:

any item that can be put on the stack
Stack:export ()
Export a list of all the contents.

Returns:

table list of values
Stack:flush ()
Flush all the contents. Note that this clears the internal storage.

Returns:

table list of values
generated by LDoc 1.4.6