Lua queue implementation.
Based on "Queues and Double Queues" from Programming in Lua
: http://www.lua.org/pil/11.4.html
local queue = require("__flib__.queue")
new() | Create a new queue. |
load(tbl) | Set a queue's metatable to allow directly calling the module's methods. |
push_left(tbl, value) | Push an element onto the beginning of the queue. |
push_right(tbl, value) | Push an element onto the end of the queue. |
pop_left(tbl) | Retrieve an element from the beginning of the queue. |
pop_right(tbl) | Retrieve an element from the end of the queue. |
iter_left(tbl) | Iterate over a queue's elements from the beginning to the end. |
iter_right(tbl) | Iterate over a queue's elements from the end to the beginning. |
length(tbl) | Get the length of the queue. |
Create a new queue.
Returns:
Set a queue's metatable to allow directly calling the module's methods.
This will need to be re-called if the game is saved and loaded.
Parameters:local MyQueue = queue.load(queue.new())
MyQueue:push_right("My string")
local len = MyQueue:length() -- 1
Push an element onto the beginning of the queue.
Parameters:
Push an element onto the end of the queue.
Parameters:
Retrieve an element from the beginning of the queue.
Parameters:
Retrieve an element from the end of the queue.
Parameters:
Iterate over a queue's elements from the beginning to the end.
Parameters:
local my_queue = queue.new()
for i = 1, 10 do
queue.push_right(my_queue, 1)
end
-- Will print 1 through 10 in order
for num in queue.iter_left(my_queue) do
log(i)
end
Iterate over a queue's elements from the end to the beginning.
Parameters:
local my_queue = queue.new()
for i = 1, 10 do
queue.push_right(my_queue, 1)
end
-- Will print 10 through 1 in reverse order
for num in queue.iter_right(my_queue) do
log(i)
end