# HG changeset patch # User Matthew Wild # Date 1445200953 -3600 # Node ID 56c9bc4ba24722978a93610c55ed28781f125e3f # Parent 82765a4ec799766edb78ec70c98b6acb44d0836d util.queue: Add :items() iterator diff -r 82765a4ec799 -r 56c9bc4ba247 util/queue.lua --- a/util/queue.lua Sun Oct 18 21:35:21 2015 +0100 +++ b/util/queue.lua Sun Oct 18 21:42:33 2015 +0100 @@ -18,6 +18,7 @@ local t = have_utable and utable.create(size, 0) or {}; -- Table to hold items return { + _items = t; size = size; count = function (self) return items; end; push = function (self, item) @@ -50,6 +51,18 @@ end return t[tail]; end; + items = function (self) + return function (t, pos) + if pos >= t:count() then + return nil; + end + local read_pos = tail + pos; + if read_pos > t.size then + read_pos = (read_pos%size); + end + return pos+1, t._items[read_pos]; + end, self, 0; + end; }; end