Concord/lib/pool.lua
Josh Perry 67d67aad5f Added docs
* Added a "nothing docstring" at the top of each file we want to generate docs for. We have to do this or ldoc just straight up refuses to generate docs otherwise.
* Fixed up a few incorrect docstrings
* config.ld is the config file for ldoc

These still need some work: a bunch of functions are still undocumented and also: type.lua & run.lua are completely undocumented.
2018-09-25 18:47:20 +01:00

41 lines
884 B
Lua

--- Pool
local PATH = (...):gsub('%.[^%.]+$', '')
local List = require(PATH..".list")
local Pool = {}
Pool.__index = Pool
--- Creates a new Pool
-- @param name Identifier for the Pool.
-- @param filter Table containing the required Components
-- @return The new Pool
function Pool.new(name, filter)
local pool = setmetatable(List(), Pool)
pool.name = name
pool.filter = filter
pool.__isPool = true
return pool
end
--- Checks if an Entity is eligible for the Pool.
-- @param e The Entity to check
-- @return True if the entity is eligible, false otherwise
function Pool:eligible(e)
for _, component in ipairs(self.filter) do
if not e.components[component] or e.removed[component] then
return false
end
end
return true
end
return setmetatable(Pool, {
__index = List,
__call = function(_, ...) return Pool.new(...) end,
})