Skip to content
ConcordConcordConcord

Filter

List of component names for one filter (`!name` to reject).

If the concord folder is in the root directory of your game, you can import this module like so:

Filter = require('concord.filter')

Used to filter Entities with specific Components

A Filter has an associated Pool that can contain any amount of Entities.

Validates a Filter Definition to make sure every component is valid.

Also checks that def.constructor is callable when present, unless onComponent is provided.

Filter.validate( errorLevel, name, def, onComponent )
Name Type Description
errorLevel integer Extra stack level added to error reports
name string Name for the Filter. If omitted, errors refer to a World:query filter.
def FilterDefinition Table containing the Filter Definition
onComponent fun(component: string, reject: string|false) Called with (component, reject) when a component is valid. reject is the stripped Component name when the entry had the Reject Prefix, otherwise false.

Parses a Filter Definition into a single interleaved table.

Entries are stored as name, required pairs: {name, true, name, false, …} where true means the Component is required and false means it is rejected.

parsedFilter = Filter.parse( name, def )
Name Type Description
name string Name for the Filter.
def FilterDefinition Table containing the Filter Definition
Name Type Description
parsedFilter ParsedFilter Parsed filter

Returns true if the Entity matches a parsed Filter.

boolean = Filter.match( e, filter )
Name Type Description
e Entity Entity to check
filter ParsedFilter Parsed filter from Filter.parse
Name Type Description
boolean boolean

Checks that a custom Pool implements add, remove, has, and clear as callables.

The Pool may be a table, userdata, lightuserdata, or cdata.

Filter.isValidPool( name, pool )
Name Type Description
name string Name of the Filter / Pool
pool Pool Pool returned by a custom constructor

Creates a new Filter

If definition.constructor is set, it is called with the definition to create the Pool.

filter = Filter.new( name, def )
Name Type Description
name string Name for the Filter.
def FilterDefinition Table containing the Filter Definition
Name Type Description
filter Filter filter The new Filter
pool Pool pool The associated Pool

Checks if an Entity fulfills the Filter requirements.

boolean = filter:eligible( e )
Name Type Description
e Entity Entity to check
Name Type Description
boolean boolean

Evaluates an Entity against this Filter and updates the Pool.

Adds the Entity if it became eligible, removes it if it no longer is.

filter = filter:evaluate( e )
Name Type Description
e Entity Entity to evaluate
Name Type Description
filter Filter

Adds an Entity to the Pool, if it passes the Filter.

filter = filter:add( e, bypass )
Name Type Description
e Entity Entity to add
bypass boolean Whether to bypass the Filter or not.
Name Type Description
filter Filter
boolean boolean added Whether the entity was added or not.

Removes an Entity from the Pool associated to this Filter.

filter = filter:remove( e )
Name Type Description
e Entity Entity to remove
Name Type Description
filter Filter

Clears the Pool associated to this Filter.

Arguments are forwarded to the Pool’s clear method.

filter = filter:clear( ... )
Name Type Description
... any Forwarded to pool:clear
Name Type Description
filter Filter

Checks if the Pool associated to this Filter contains the passed Entity.

boolean = filter:has( e )
Name Type Description
e Entity Entity to check
Name Type Description
boolean boolean Whether the Entity exists.

Gets the name of the Filter

string = filter:getName()
Name Type Description
string string

List of component names for one filter (!name to reject).

Optional constructor creates a custom pool instead of the default List.

Name Type Description
[integer] string
constructor? fun(def: FilterDefinition): Pool

Entity collection backing a Filter. Default instances are List; custom constructors must implement add, remove, has, and clear.

Name Type Description
add fun(self: Pool, e: Entity): Pool
remove fun(self: Pool, e: Entity): Pool|nil
has fun(self: Pool, e: Entity): boolean
clear fun(self: Pool, …: any): Pool

Interleaved component names and required flags from Filter.parse (name, required, …).

(string|boolean)[]