-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpond.lua
More file actions
42 lines (36 loc) · 731 Bytes
/
pond.lua
File metadata and controls
42 lines (36 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
local Pond = {}
Pond.__index = Pond
function Pond.new(build, size)
local self = setmetatable({}, Pond)
self.build = build
self.items = {}
self.total = 0
if size then
self:fill(size)
end
return self
end
function Pond:fill(n)
for i = 1, n do
self:give(self.build())
end
end
function Pond:take()
if self.total > 0 then
local item = self.items[self.total]
self.items[self.total] = nil
self.total = self.total - 1
return item
else
return build()
end
end
function Pond:give(item)
self.total = self.total + 1
self.items[self.total] = item
end
function pond:drain()
self.items = {}
self.total = 0
end
return Pond