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
- download this mod
- add it as a dependency to your mod (can be optional, up to you)
- at the top of your
control.lua
file addrequire("__RaiseEventProtection__/protection.lua")
(when optionalif 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)