Code: Select all
script.validate_filters(event: defines.events, event_data: EventData, filters: EventFilter...) -> boolean
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:
- Factorio built-in filtering logic is written in C, which is way faster
- Factorio built-in filtering logic is already written, so no need in duplicate work, and all corner-cases are already covered
- Factorio build-in filtering logic would be kept up-to-date, thus all future events & filters would be automatically present
Example of such event with multiple joint filters: GH: ILLISIS / Construction Continued - entity_processor.lua