Diff

util/queue.lua @ 6920:7596c37e0a63

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Mon, 09 Nov 2015 22:56:32 +0100
parent 6912:cb5b14c95b7b
child 9901:c8b75239846c
child 11103:73b8aaf55775
line wrap: on
line diff
--- a/util/queue.lua	Sun Oct 18 14:00:15 2015 +0200
+++ b/util/queue.lua	Mon Nov 09 22:56:32 2015 +0100
@@ -16,8 +16,9 @@
 	local head, tail = 1, 1;
 	local items = 0; -- Number of stored items
 	local t = have_utable and utable.create(size, 0) or {}; -- Table to hold items
-
+	--luacheck: ignore 212/self
 	return {
+		_items = t;
 		size = size;
 		count = function (self) return items; end;
 		push = function (self, item)
@@ -50,6 +51,19 @@
 			end
 			return t[tail];
 		end;
+		items = function (self)
+			--luacheck: ignore 431/t
+			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