Skip to content

Commit

Permalink
add fallback implementation for fifo_queue.add_list() in case table.m…
Browse files Browse the repository at this point in the history
…ove() is missing
  • Loading branch information
lolbinarycat committed Dec 19, 2023
1 parent 79214b5 commit ab2df3c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions mesecons/fifo_queue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ function fifo_queue.add(self, v)
self.buf_in[n] = v
end

-- add several elements to the queue
function fifo_queue.add_list(self, v)
table.move(v, 1, #v, self.n_in + 1, self.buf_in)
self.n_in = self.n_in + #v
-- table.move is not available in some lua versions, provide a fallback implementaion
if table.move ~= nil then
-- add several elements to the queue
function fifo_queue.add_list(self, v)
table.move(v, 1, #v, self.n_in + 1, self.buf_in)
self.n_in = self.n_in + #v
end
else
function fifo_queue.add_list(self, v)
for _, elem in ipairs(v) do
self:add(elem)
end
end
end
-- removes and returns the next element, or nil of empty
function fifo_queue.take(self)
Expand Down

0 comments on commit ab2df3c

Please sign in to comment.