From d9d9bafe923f04648cdc69e92b0a06a9802b7432 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Sat, 10 Aug 2013 18:38:38 +0000 Subject: [PATCH] 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 --- Ovale.toc | 1 + OvalePoolGC.lua | 42 ++++++++++++++++++++++++++++++++++++++++++ compiler.pl | 2 +- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 OvalePoolGC.lua 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 + +-- +OvalePoolGC.name = "OvalePoolGC" +OvalePoolGC.pool = nil +OvalePoolGC.size = 0 +OvalePoolGC.unused = 0 +-- + +-- +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 +-- 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) } } } - -- 1.7.9.5