Employing the Function Renaming Technique for Registered Handlers
We all know that every extension published has the potential in adversely interact with other extensions.
One technique many of us use to help mitigate against possible poor inter-extension operation is to rename and thereby nest functions.
(I am going to purposely being very simplistic, so that, should the neophyte extension writer, find their way to this thread, it might help them.)
Here's an example from one of my extensions, in the onInit( ) function I am "renaming" the 5E ruleset's onDeathRoll( ) function. Then I am using my extension's function to replace it.
Code:
function onInit()
ActionSave.LDT_onDeathRoll_helper = ActionSave.onDeathRoll;
ActionSave.onDeathRoll = LDT_onDeathRoll;
end
function LDT_onDeathRoll(args)
-- call the helper to utilize ruleset functionality then modify it
ActionSave.LDT_onDeathRoll_helper(args);
-- now do my extension's stuff
...
...
end
There! Now that the table has been set, here's my question: Is there a similar methodology that I can employ for the "registered" handler function?
Please note that the code given above does not work, because the 5E ruleset function is a registered handler.
What I have had to do is this:
Code:
function onInit()
ActionsManager.unregisterResultHandler("death");
ActionsManager.unregisterResultHandler("death_auto");
ActionsManager.registerResultHandler("death", LDT_onDeathRoll);
ActionsManager.registerResultHandler("death_auto", LDT_onDeathRoll);
end
And now for those who are really paying attention: "Okay Tom, you've figured it out, you have the solution. Why are you bringing this up?"
Well, the above does not solve the inter-extension operability problem.
With the renaming technique, one extension can rename the ruleset function, and drop the extension function in its stead. Then another extension can do the same, come after the first extension, rename the first extension's replacing function and substitute its own. All three functions coexist and by calling the "helpers" and a small bit of luck, interoperability can exist.
But in the registering of handlers I'm a bit obtuse, and have yet to figure out a way to ensure the extension that registers a replacing function before mine can be called by mine. I need something like a "whoIsRegistered( ) function to save that tidbit of info before my extension registers my replacing function.
(This is the first time I've run into this issue, so I have to admit my ignorance.)
Thanks to all of those who read this thread, and of course real kudos to those who can drag me and my thick head into the light!