diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2024-03-06 09:56:45 -0500 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2024-03-06 09:56:45 -0500 |
commit | c621fc39fc4ac25482fbc1090b8067c4187de176 (patch) | |
tree | ad04aa2f0658cbf1b2ee0cce1b7aede826e7d2ed /indra/newview/scripts/lua/Queue.lua | |
parent | b4bef56b20fbeaaea60b20bd84d1569ed76cf29b (diff) |
WIP: Unfinished Queue.lua, WaitQueue.lua, ErrorQueue.lua, leap.lua.
Also qtest.lua to exercise the queue classes and inspect.lua (from
https://github.com/kikito/inspect.lua) for debugging.
Diffstat (limited to 'indra/newview/scripts/lua/Queue.lua')
-rw-r--r-- | indra/newview/scripts/lua/Queue.lua | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/indra/newview/scripts/lua/Queue.lua b/indra/newview/scripts/lua/Queue.lua index e178ad9969..b0a5a87f87 100644 --- a/indra/newview/scripts/lua/Queue.lua +++ b/indra/newview/scripts/lua/Queue.lua @@ -1,40 +1,41 @@ --- from https://create.roblox.com/docs/luau/queues#implementing-queues +-- from https://create.roblox.com/docs/luau/queues#implementing-queues, +-- amended per https://www.lua.org/pil/16.1.html local Queue = {} -Queue.__index = Queue -function Queue.new() - local self = setmetatable({}, Queue) +function Queue:new() + local obj = setmetatable({}, self) + self.__index = self - self._first = 0 - self._last = -1 - self._queue = {} + obj._first = 0 + obj._last = -1 + obj._queue = {} - return self + return obj end -- Check if the queue is empty function Queue:IsEmpty() - return self._first > self._last + return self._first > self._last end -- Add a value to the queue function Queue:Enqueue(value) - local last = self._last + 1 - self._last = last - self._queue[last] = value + local last = self._last + 1 + self._last = last + self._queue[last] = value end -- Remove a value from the queue function Queue:Dequeue() - local first = self._first - if self:IsEmpty() then - return nil - end - local value = self._queue[first] - self._queue[first] = nil - self._first = first + 1 - return value + if self:IsEmpty() then + return nil + end + local first = self._first + local value = self._queue[first] + self._queue[first] = nil + self._first = first + 1 + return value end return Queue |