Afforess / Factorio-Stdlib

Factorio Standard Library Project
ISC License
162 stars 45 forks source link

register_events() #124

Closed kumpuu closed 6 years ago

kumpuu commented 6 years ago

https://github.com/Afforess/Factorio-Stdlib/blob/32bfcf6565fd4b1e6fc96560edd76c17680bfc10/stdlib/event/changes.lua#L77

What does this function do (generally)? @Afforess @Nexela

sparr commented 6 years ago

That method uses the Events module to register the handlers in the Changes module to handle the relevant factorio events.

kumpuu commented 6 years ago

I couldn't find any caller outside spec/ which I was told is for testing purposes only. Hence the question.

sparr commented 6 years ago

You can call it yourself, or not, at your discretion. You can also manually do either half of what it does, separately.

kumpuu commented 6 years ago

The thing I want to know is why this func is there, it's only called in testing code. At first sight it looked like part of some standard module interface to put event registering in. But apparently not, well I guess it's not relevant for me.

sparr commented 6 years ago

It is there for you to call, just like every other function in this library that's "only called in testing code".

Nexela commented 6 years ago

register_events() is a helper function to register events for certain actions. Initially these modules automatically registered events, but what if someone wasn't using the Event system, or only wanted to use the functions from the module. So the decision was made that if events needed to be registered, modders would have to explicitly register them (either via the help function) or manually via Event or script.on_event()