SGG-Modding / Hell2Modding

Mod loader for Hades 2
MIT License
12 stars 2 forks source link

Callback for when a plugin is reloaded #2

Open AndreLouisIssa opened 3 months ago

AndreLouisIssa commented 3 months ago

proposed on_reload (unsure where it would be put, perhaps a new namespace called meta?)

would make it easier for plugins that manage other plugins to clear any information would otherwise accumulate negatively over reloads.

e.g.

rom.<namespace>.on_reload(function(env)
    my_callbacks[env._PLUGIN.guid] = {}
end)

or

rom.<namespace>.on_reload(function(env)
    local callbacks = my_callbacks[env._PLUGIN.guid]
    if callbacks == nil then return end
    for k in pairs(callbacks) do
        callbacks[k] = nil
    end
end)

or it could be used to declare some features inert in preparation for a reload as they might not make sense in that context (e.g. managing external state like sockets, file handles etc.).

unsure if there's any benefit in an on_reload.post variant, I suppose it could be used for removing any flags that might have been set in on_reload.pre.

AndreLouisIssa commented 3 months ago

alternatively: on_load which functions exactly the same except it's every subsequent load of a plugin, except there's another argument to the callback, reloaded boolean that is true only if it's a reload, and false if it's an initial load.

I can only think of this variant being useful if it was specifically on_load.post, used by a plugin on itself or by another plugin on a calling plugin to basically fulfil ReLoad's job to split the initial load and reload codepaths, but in a rather limited way.

But if part of our goals is to eliminate the need for a lot of my modules by bringing them into the base loader, this could be such a way.