Page 1 of 1

Provide function to validate EventData on the given valid EventFilter

Posted: Fri Aug 30, 2024 3:07 pm
by Hares
Provide the function on LuaBootstrap with the following prototype:

Code: Select all

script.validate_filters(event: defines.events, event_data: EventData, filters: EventFilter...) -> boolean
Accepts the event ID, the passed event data and a valid (i.e. registered) event filter.
Returns true if and only if that event matches that filter; false otherwise.

Use Case
Validating if the event fired matches the sub-filters (for mods with more than one filtered listener per event type). We register event with multiple filters (A or B or (C and D) or E), then we check each filter group individually (A, B, C&D, E) to detect if the associated event handler should be fired. Would work similar to `lualib.event_handler`, but with filtered events.

Justification
Nothing in the example above is impossible on the pure Lua side, but it has downsides:
  1. Factorio built-in filtering logic is written in C, which is way faster
  2. Factorio built-in filtering logic is already written, so no need in duplicate work, and all corner-cases are already covered
  3. Factorio build-in filtering logic would be kept up-to-date, thus all future events & filters would be automatically present
Example
Example of such event with multiple joint filters: GH: ILLISIS / Construction Continued - entity_processor.lua