Add a wrapper for the Lua garbage collector using the Pool interface.
Johnny C. Lam [08-10-13 - 18:38]
Add a wrapper for the Lua garbage collector using the Pool interface.
git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@993 d5049fe3-3747-40f7-a4b5-f36d6801af5f
diff --git a/Ovale.toc b/Ovale.toc
index 8a4c9eb..f5975d5 100644
--- a/Ovale.toc
+++ b/Ovale.toc
@@ -35,6 +35,7 @@ OvaleEnemies.lua
OvaleEquipement.lua
OvaleGUID.lua
OvalePool.lua
+OvalePoolGC.lua
OvaleQueue.lua
OvaleRecount.lua
OvaleSkada.lua
diff --git a/OvalePoolGC.lua b/OvalePoolGC.lua
new file mode 100644
index 0000000..b486011
--- /dev/null
+++ b/OvalePoolGC.lua
@@ -0,0 +1,42 @@
+--[[--------------------------------------------------------------------
+ Ovale Spell Priority
+ Copyright (C) 2013 Johnny C. Lam
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License in the LICENSE
+ file accompanying this program.
+--]]--------------------------------------------------------------------
+
+-- This module wraps the standard Lua garbage collector using the Pool interface.
+local _, Ovale = ...
+local OvalePoolGC = {}
+Ovale.OvalePoolGC = OvalePoolGC
+
+--<public-static-properties>
+OvalePoolGC.name = "OvalePoolGC"
+OvalePoolGC.pool = nil
+OvalePoolGC.size = 0
+OvalePoolGC.unused = 0
+--</public-static-properties>
+
+--<public-static-methods>
+function OvalePoolGC:NewPool(name)
+ obj = { name = name, size = 0, unused = 0 }
+ setmetatable(obj, { __index = self })
+ return obj
+end
+
+function OvalePoolGC:Get()
+ -- Keep running count of total number of tables allocated.
+ self.size = self.size + 1
+ return {}
+end
+
+-- The Release and Drain methods are no-ops.
+function OvalePoolGC:Release(item) end
+function OvalePoolGC:Drain() end
+
+function OvalePoolGC:Debug()
+ Ovale:FormatPrint("Pool %s has size %d.", self.name, self.size)
+end
+--</public-static-methods>
diff --git a/compiler.pl b/compiler.pl
index 0df88e7..a521919 100644
--- a/compiler.pl
+++ b/compiler.pl
@@ -94,6 +94,7 @@ $sp{Ovale}{OvaleBestAction} = true;
$sp{Ovale}{OvaleCondition} = true;
$sp{Ovale}{OvaleQueue} = true;
$sp{Ovale}{OvalePool} = true;
+$sp{Ovale}{OvalePoolGC} = true;
$sp{Ovale}{OvaleSkada} = true;
$sp{Ovale}{OvaleState} = true;
@@ -287,4 +288,3 @@ for my $class (keys %sp)
}
}
}
-