From 081647ea1ffaf7bf932e727c9311e765b642da5b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 16 Dec 2021 12:16:45 +0100 Subject: util.smqueue: Simplify compat table, fix dependent modules (thanks Martin) There was an off-by-one in the modulo calculation. Switching to a plain old array-table makes the apparent size of the queue wrong, but since some of the queue may not be available this is likely for the best. --- teal-src/util/smqueue.tl | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'teal-src/util') diff --git a/teal-src/util/smqueue.tl b/teal-src/util/smqueue.tl index 26bebe60..e149dde7 100644 --- a/teal-src/util/smqueue.tl +++ b/teal-src/util/smqueue.tl @@ -70,22 +70,13 @@ function smqueue:consume() : queue.queue.consume_iter return self._queue:consume() end --- Compatibility wrapper, meant to look like a plain ol' array -local record compat_mt - _queue : smqueue -end - -function compat_mt:__index(i : integer) : any - if i < self._queue._tail then return nil end - return self._queue._queue._items[(i + self._queue._tail) % self._queue._queue.size]; -end - -function compat_mt:__len() : integer - return self._queue:count_unacked() -end - +-- Compatibility layer, plain ol' table function smqueue:table() : { any } - return setmetatable({ _queue = self }, compat_mt); + local t : { any } = {}; + for i, v in self:resume() do + t[i] = v; + end + return t; end local function freeze(q : smqueue) : { string:integer } -- cgit v1.2.3