Kryzeth Standard Library

StdLib.Misc.Queue

supers: StdLib.Core

A double queue. Taken from *Programming in Lua* Queues and Double Queues and modified to not allow nil values, and returns nil if @{popfirst} or @{poplast} is used when the queue is empty.

@usage local Queue = require('kry_stdlib/stdlib/misc/queue') local q = Queue() -- create a new empty queue q('my value') -- push a value onto the queue q() -- pop the last value off the queue game.print(#q) -- print the number of items in the queue

Methods27

function Queue.__call(_: any, ...: any) -> nil
function Queue.new(...) -> StdLib.Misc.Queue

Constructs a new Queue object. @param ... mixed, values to push into the queue

Parameters
...
Returns
StdLib.Misc.Queue

a new queue

function Queue.load(queue: table) -> nil | table

Load global.queue or queues during on_load, as metatables are not persisted. <p>This is only needed if you are using the queue as an object and storing it in global.

Parameters
queuetable

(<span class="types">@{Queue}</span>,...) @usage global.myqueue1 = Queue.new() script.on_load(function() Queue.load(global.myqueue))

Returns
nil | table
function Queue.push_first(queue: StdLib.Misc.Queue, ...: any) -> StdLib.Misc.Queue

Push a new element to the front of the queue.

Parameters
queueStdLib.Misc.Queue

the queue to push an element to

...any

the element to push

function Queue.push_last(queue: StdLib.Misc.Queue, ...: any) -> StdLib.Misc.Queue

Push a new element to the back of the queue.

Parameters
queueStdLib.Misc.Queue

the queue to push an element to

...any

the element(s) to push

function Queue.push(queue: StdLib.Misc.Queue, ...: any) -> StdLib.Misc.Queue

Shortcut for @{Queue.push_last} @function Queue.push

Parameters
queueStdLib.Misc.Queue

the queue to push an element to

...any

the element(s) to push

function Queue.push_at(queue: StdLib.Misc.Queue, index: number, value: any) -> StdLib.Misc.Queue

Push a new element to a specific location of the queue.

Parameters
queueStdLib.Misc.Queue

the queue to push an element to

indexnumber

the index to push to.

valueany

the element to push.

function Queue.wrapper(self, func_name, ...) -> any
function Queue.pop_first(queue: StdLib.Misc.Queue) -> value any

Retrieve the element at the front of the queue and remove it from the queue.

Parameters
queueStdLib.Misc.Queue

the queue to retrieve the element from

Returns
valueany

the element at the front of the queue

function Queue.pop(queue: StdLib.Misc.Queue) -> value any

Shortcut for @{Queue.pop_first} @function Queue.pop

Parameters
queueStdLib.Misc.Queue

the queue to retrieve the element from

Returns
valueany

the element at the front of the queue

function Queue.pop_at(queue: StdLib.Misc.Queue, index: number) -> value any

Pop an element at a specific location of the queue.

Parameters
queueStdLib.Misc.Queue

the queue to push an element to

indexnumber

the index to push to.

Returns
valueany

the popped element.

function Queue.peek_at(queue: StdLib.Misc.Queue, index: number) -> any

Peek at an element in the queue without disturbing the queue.

Parameters
queueStdLib.Misc.Queue

the queue to peek at

indexnumber

the index in the queue to peek at

Returns
any

the value of the peeked element

function Queue.peek_first(queue: StdLib.Misc.Queue) -> any

Return the element at the front of the queue and remove it from the queue.

Parameters
queueStdLib.Misc.Queue

the queue to retrieve the element from

Returns
any

the element at the front of the queue

function Queue.peek(queue: StdLib.Misc.Queue) -> any

Shortcut for @{Queue.peek_first} @function Queue.peek

Parameters
queueStdLib.Misc.Queue

the queue to retrieve the element from

Returns
any

the element at the front of the queue

function Queue.pop_last(queue: StdLib.Misc.Queue) -> any

Retrieve the element at the back of the queue and remove it from the queue.

Parameters
queueStdLib.Misc.Queue

the queue to retrieve the element from

Returns
any

the element at the back of the queue

function Queue.peek_last(queue: StdLib.Misc.Queue) -> any

Return the element at the back of the queue.

Parameters
queueStdLib.Misc.Queue

the queue to retrieve the element from

Returns
any

the element at the back of the queue

function Queue.pop_and_push(queue: StdLib.Misc.Queue) -> any

Returns the popped value and pushes back into the queue.

Parameters
queueStdLib.Misc.Queue

the queue @return any #the value that was popped.

Returns
any
function Queue.cycle(queue: StdLib.Misc.Queue) -> StdLib.Misc.Queue

Returns the queue after popping the last element and pushing it to the top.

Parameters
queueStdLib.Misc.Queue

the queue

Returns
StdLib.Misc.Queue

the queue

function Queue.find(queue, find) -> any

Gets the first index which matches the stored data. does not compare inside tables.

function Queue.sort(queue, func) -> any

sort and reorder the queue

function Queue.is_empty(queue: StdLib.Misc.Queue) -> boolean

Returns true if the given queue is empty.

Parameters
queueStdLib.Misc.Queue

the queue to check

Returns
boolean

true if empty, false otherwise

function Queue.size(queue: StdLib.Misc.Queue) -> number

Returns the number of items in the queue.

Parameters
queueStdLib.Misc.Queue

the queue to check

Returns
number

the number of items in the queue

function Queue.count(queue: StdLib.Misc.Queue) -> number

Shortcut for @{Queue.size} @function Queue.count

Parameters
queueStdLib.Misc.Queue

the queue to check

Returns
number

the number of items in the queue

function Queue.next(queue: StdLib.Misc.Queue, index: nil | number, pop: boolean) -> (nil | number, any)

Return the next element in the queue

Parameters
queueStdLib.Misc.Queue

the queue to check

indexnil | number

if nil return the first value, else return the next index value

popboolean

pop the value off the queue

Returns
nil | number

the index

any

the value at queue index

function Queue.rnext(queue: StdLib.Misc.Queue, index: nil | number, pop: boolean) -> (nil | number, any)

Return the previous element in the queue

Parameters
queueStdLib.Misc.Queue

the queue to check

indexnil | number

if nil return the last value, else return the previous index value

popboolean

pop the value off the queue

Returns
nil | number

the index

any

the value at queue index

function Queue.pairs(queue, pop) -> ...fun(queue, index) -> ...nil | number

Iterate the queue forward

function Queue.rpairs(queue, pop) -> ...fun(queue, index) -> ...nil | number

Iterate the queue backwards

Fields2

Queue.__class: string = "Queue"
Queue.__index : unknown