forked from Sidoine/Ovale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoolGC.lua
54 lines (44 loc) · 1.35 KB
/
PoolGC.lua
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
43
44
45
46
47
48
49
50
51
52
53
54
--[[--------------------------------------------------------------------
Copyright (C) 2013 Johnny C. Lam.
See the file LICENSE.txt for copying permission.
--]]--------------------------------------------------------------------
-- This module wraps the standard Lua garbage collector using the Pool interface.
local OVALE, Ovale = ...
local OvalePoolGC = {}
Ovale.OvalePoolGC = OvalePoolGC
--<private-static-properties>
local setmetatable = setmetatable
local tostring = tostring
--</private-static-properties>
--<public-static-properties>
OvalePoolGC.name = "OvalePoolGC"
OvalePoolGC.size = 0
OvalePoolGC.__index = OvalePoolGC
--</public-static-properties>
--<public-static-methods>
do
-- Class constructor
setmetatable(OvalePoolGC, { __call = function(self, ...) return self:NewPool(...) end })
end
function OvalePoolGC:NewPool(name)
name = name or self.name
return setmetatable({ name = name }, self)
end
function OvalePoolGC:Get()
-- Keep running count of total number of tables allocated.
self.size = self.size + 1
return {}
end
function OvalePoolGC:Release(item)
self:Clean(item)
end
function OvalePoolGC:Clean(item)
-- virtual function; override as needed.
end
function OvalePoolGC:Drain()
self.size = 0
end
function OvalePoolGC:DebuggingInfo()
Ovale:Print("Pool %s has size %d.", tostring(self.name), self.size)
end
--</public-static-methods>