Provide function to validate EventData on the given valid EventFilter

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
Hares
Filter Inserter
Filter Inserter
Posts: 533
Joined: Sat Oct 22, 2022 8:05 pm
Contact:

Provide function to validate EventData on the given valid EventFilter

Post 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
Post Reply

Return to “Modding interface requests”