StdLib.Misc.Queue
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
...
- 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.
queuetable(<span class="types">@{Queue}</span>,...) @usage global.myqueue1 = Queue.new() script.on_load(function() Queue.load(global.myqueue))
- nil | table
function Queue.push_first(queue: StdLib.Misc.Queue, ...: any) -> StdLib.Misc.Queue
Push a new element to the front of the queue.
queueStdLib.Misc.Queuethe queue to push an element to
...anythe 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.
queueStdLib.Misc.Queuethe queue to push an element to
...anythe element(s) to push
function Queue.push(queue: StdLib.Misc.Queue, ...: any) -> StdLib.Misc.Queue
Shortcut for @{Queue.push_last} @function Queue.push
queueStdLib.Misc.Queuethe queue to push an element to
...anythe 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.
queueStdLib.Misc.Queuethe queue to push an element to
indexnumberthe index to push to.
valueanythe 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.
queueStdLib.Misc.Queuethe queue to retrieve the element from
valueanythe element at the front of the queue
function Queue.pop(queue: StdLib.Misc.Queue) -> value any
Shortcut for @{Queue.pop_first} @function Queue.pop
queueStdLib.Misc.Queuethe queue to retrieve the element from
valueanythe 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.
queueStdLib.Misc.Queuethe queue to push an element to
indexnumberthe index to push to.
valueanythe popped element.
function Queue.peek_at(queue: StdLib.Misc.Queue, index: number) -> any
Peek at an element in the queue without disturbing the queue.
queueStdLib.Misc.Queuethe queue to peek at
indexnumberthe index in the queue to peek at
- 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.
queueStdLib.Misc.Queuethe queue to retrieve the element from
- 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
queueStdLib.Misc.Queuethe queue to retrieve the element from
- 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.
queueStdLib.Misc.Queuethe queue to retrieve the element from
- 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.
queueStdLib.Misc.Queuethe queue to retrieve the element from
- 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.
queueStdLib.Misc.Queuethe queue @return any #the value that was popped.
- 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.
queueStdLib.Misc.Queuethe queue
- 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.
queueStdLib.Misc.Queuethe queue to check
- boolean
true if empty, false otherwise
function Queue.size(queue: StdLib.Misc.Queue) -> number
Returns the number of items in the queue.
queueStdLib.Misc.Queuethe queue to check
- number
the number of items in the queue
function Queue.count(queue: StdLib.Misc.Queue) -> number
Shortcut for @{Queue.size} @function Queue.count
queueStdLib.Misc.Queuethe queue to check
- 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
queueStdLib.Misc.Queuethe queue to check
indexnil | numberif nil return the first value, else return the next index value
popbooleanpop the value off the queue
- 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
queueStdLib.Misc.Queuethe queue to check
indexnil | numberif nil return the last value, else return the previous index value
popbooleanpop the value off the queue
- 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