[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Suggestions
. . -> [Subject]  Plugin load/install order

Plugin load/install order

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Tue 13 Oct 2009 04:14 AM (UTC)
Message
I recall that a while back we were discussing plugin dependencies, and hacks like my LoadPPI script to circumvent that. I have a small suggestion to make it much easier to deal with plugin dependencies.

Currently, each plugin is loaded, and OnPluginInstall called, at the same time. Changing it so that all plugins are loaded, then OnPluginInstall is called on all of them, would guarantee that any code in OnPluginInstall is executed after the plugin files have been loaded (including variables). Checking for a dependency would be reduced to checking IsPluginInstalled().

I (was|still am) trying to patch this into my custom build, but it's a little more difficult than I expected - perhaps because I'm not completely familiar with the source.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #1 on Tue 13 Oct 2009 04:56 AM (UTC)
Message
Nick said that Plugins load in alphabetical order. Give dependencies an early name in the sort order. 'aaDependof_LoadPPI.xml" It'll look like crap in the plugin dialog's list, but who looks at the list? Just give a good description in the xml for the purpose column...
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #2 on Tue 13 Oct 2009 04:58 AM (UTC)

Amended on Tue 13 Oct 2009 05:00 AM (UTC) by Twisol

Message
Sorry - what? That seems... a bit overhanded. The situation currently is that the order is:

p1 parse/run, p1 OnPluginInstall,
p2 parse/run, p2 OnPluginInstall,
p3 parse/run, p3 OnPluginInstall.

What I'm suggesting is changing it to:

p1 parse/run, p2 parse/run, p3 parse/run,
p1 OnPluginInstall, p2 OnPluginInstall, p3 OnPluginInstall.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #3 on Tue 13 Oct 2009 05:11 AM (UTC)
Message
Also, I just stepped through the plugin load order, and I can pretty much guarantee that it doesn't load in alphabetical order. In fact, if anything, it loads in the order that the <include> XML tags in the world file are in.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Tue 13 Oct 2009 06:03 AM (UTC)
Message
I think it is the order in the world file, which is probably the order they were loaded. As this is not easily defined, I would not rely on the load order.

As I previously suggested, I would resolve dependencies at world connect time, when all the plugins will have been loaded already.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #5 on Tue 13 Oct 2009 06:49 AM (UTC)
Message
I'm not sure there needs to be a hard-coded dependency feature, personally. A script might have hard dependencies, where they'll fail if they don't see their prerequisite loaded, or soft dependencies, where it degrades gracefully. Both could easily be controlled from within the script itself; a dependency feature (at least in the way I see it; you might have a better idea) would either control only hard dependencies, leaving the script to manage soft dependencies under the same iffy conditions as now, or be complex/unwieldy, which speaks for itself.

All that said, I'm not exactly having much luck myself, so if it would be too hard to implement, it's not a big deal.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #6 on Tue 13 Oct 2009 08:22 AM (UTC)
Message
Nick: Rereading your post for the tenth time, I finally understood "I would resolve dependencies at world connect time" the way you meant it. *laughs* To respond to that: it's hardly going to be a steadfast rule that plugins will only need to communicate after the world has connected. I can think of plenty of cases where they would need to acknowledge each-other before the MUD has connected, and it's hardly fair to limit plugins that much.

I'm halfway finished writing an IRC plugin, for example, and I want it to be possible to communicate with it, such as allowing other plugins to respond to IRC data (likely sent by BroadcastPlugin), and do other kinds of things. The world need never actually connect to the MUD, so using OnPluginConnect does no good at all.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Tue 13 Oct 2009 08:43 PM (UTC)
Message
Twisol said:

it's hardly going to be a steadfast rule that plugins will only need to communicate after the world has connected.


Well, perhaps. But after all, the client is basically communicating with a MUD, it isn't doing much before that.


Twisol said:

What I'm suggesting is changing it to:

p1 parse/run, p2 parse/run, p3 parse/run,
p1 OnPluginInstall, p2 OnPluginInstall, p3 OnPluginInstall.


This is probably a sensible suggestion, I'm not sure if it will break existing plugins, but I can see the use for it. Then, in OnPluginInstall, you can assume all plugins are loaded (except those that get loaded manually later on, of course).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #8 on Tue 13 Oct 2009 10:28 PM (UTC)
Message
Nick Gammon said:

Twisol said:

What I'm suggesting is changing it to:

p1 parse/run, p2 parse/run, p3 parse/run,
p1 OnPluginInstall, p2 OnPluginInstall, p3 OnPluginInstall.


This is probably a sensible suggestion, I'm not sure if it will break existing plugins, but I can see the use for it. Then, in OnPluginInstall, you can assume all plugins are loaded (except those that get loaded manually later on, of course).


Precisely! :)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #9 on Wed 14 Oct 2009 05:49 AM (UTC)

Amended on Wed 14 Oct 2009 07:22 AM (UTC) by Twisol

Message
I've made the appropriate changes to my local source to implement this; would you like the diffs? I'm moderately less sure of my technique for this one, but testing seems to be working.

Oh, and I may have fixed an obscure bug: when using 'Add' in the Plugins dialog to load multiple files at once, if one of the files doesn't load properly, it skips all the rest. 'Reinstall' doesn't have this problem. I didn't test this fix - I really only noticed it because I was working in that function - but it seems like it was just a matter of putting the try-catch within the loop instead of outside it, as OnReinstall() already was doing.

EDIT: Oh, and about it potentially breaking current plugins, I've given it some thought, and I don't see any obvious way it could do harm. OnPluginInstall currently is no more useful than putting code outside the function altogether; changing the load/install process wouldn't change its mechanics, only guarantee something that wasn't guaranteed before. If something happens to use, for example, the LoadPPI proxy script I wrote, it would still be fully compatible.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Wed 14 Oct 2009 07:57 PM (UTC)
Message
Yes, send it to me please.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Fri 11 Dec 2009 04:07 AM (UTC)

Amended on Fri 11 Dec 2009 04:10 AM (UTC) by Nick Gammon

Message
After thinking about this at some length, it seems to me that we need more than re-ordering when the OnPluginInstall function is called.

I have added a new callback to version 4.45, namely OnPluginListChanged. This will be called when:


  • All plugins have been loaded at world load time (called once, after all the plugins are loaded)

  • The list of plugins changes (because of adding or removing plugins from the Plugins dialog box) - called once if multiple plugins are loaded or removed at the same time.

  • A plugin is reloaded via the Plugins dialog box, or the ReloadPlugin script function is called.

  • A plugin is added via the LoadPlugin script function.


Making a new function resolves any issues that calling an existing function (like OnPluginInstall) at a different time, or more times than expected, may break existing plugins.

It also is a bit clearer - the plugin receiving the OnPluginListChanged function call, is not necessarily the one that has changed. It really notifies *all* plugins that *something* has changed. The something might be that the list of plugins has grown smaller, for example.

A logical test to put into OnPluginListChanged would be to see if a required plugin (that is, one that this plugin has a dependency on) is there. Since it is called at world load time, after all plugins are loaded, then the plugin will not just magically appear without user intervention. A warning could then be displayed to the player that they need to fetch the required extra plugin. This warning would also be displayed if the player removed the required plugin for some reason.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #12 on Fri 11 Dec 2009 05:31 AM (UTC)
Message
Sounds good! ^_^

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


26,081 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]