From ab2df3caf31cb3877b5f37b2e778cf0448f0adeb Mon Sep 17 00:00:00 2001 From: binarycat Date: Tue, 19 Dec 2023 15:04:02 -0500 Subject: [PATCH] add fallback implementation for fifo_queue.add_list() in case table.move() is missing --- mesecons/fifo_queue.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mesecons/fifo_queue.lua b/mesecons/fifo_queue.lua index b1c50c27..fac81eec 100644 --- a/mesecons/fifo_queue.lua +++ b/mesecons/fifo_queue.lua @@ -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)