Raise Event Protection deprecated


A mod for other mods to use to protect them from bad script.raise_event calls (with game events), and applies event filters on them when defined. This mod can cause mods using it to slow down if any mod uses script.raise_event.

3 years ago
0.18
6
Owner:
JanSharp
Source:
https://github.com/JanSharp/EventData...
Homepage:
https://github.com/JanSharp/EventData...
License:
MIT
Created:
4 years ago
Latest Version:
0.18.26 (3 years ago)
Factorio version:
0.18
Downloaded by:
6 users

Deprecated

since 0.18.27 (see scripting) raise_event is now completely save, and everything this mod does is already done by the game.

This is the outcome i was hoping for anyway, this mod was meant to be a band aid until raise_event got fixed. (it was quite literally broken imo ;) )

Important

Keep in mind, the overhead for events risen by the game itself is tiny!
all it needs to do is get mod_name, check if it is nil, if yes it calls your handler (as a tail call, which is more performant than a regular call) - and that's it.

Notes

You can check the changelog on GitHub to see what things have already been changed, but not released yet. If you'd like these changes released let me know here.

Usage

  1. download this mod
  2. add it as a dependency to your mod (can be optional, up to you)
  3. at the top of your control.lua file add require("__RaiseEventProtection__/protection.lua")
    (when optional if script.active_mods["RaiseEventProtection"] then require("__RaiseEventProtection__/protection.lua") end )

Quirks / Behavior

  • If a mod calls script.raise_event where event is one of the defines.events ("game events") the data will get validated (in your mod's state). See below what exactly gets validated.
  • Also for those kinds of calls, if the event is filterable, your handler will only be called if the filters you defined say it should.
  • script.get_event_handler will return a wrapper around the function you initially registered.
  • Registering a handler with filters generates a function at runtime. this is slow - maybe I can improve that somehow.

Validation

  • Every required field must exist
  • Every field's type must be valid
  • Every player index must be a valid player index
  • Every surface index must be a valid surface index
  • Some LuaEntity, LuaEntityPrototype and LuaGuiElement types are further validated (see event-specific-definitions for more detail)