Whoa!
Fiendish said:
But now I have a strict dependency and I need to make sure that this monitor plugin is always loaded first, before any other plugin tries to register with it, for obvious reasons.
Right, you have created a strict dependency, and now it is tripping you up. Why not have a design that doesn't require an exact loading order?
Back into the mists of time for a moment, I thought this sounded familiar. For one thing, my ATCP mapper needed the ATCP plugin before it would work. And, closer to what you are attempting, when I did a proof-of-concept of a MUD caching system, I wanted to have multiple plugins access a single lot of shared data (in-memory cache <-- from disk cache <-- server cache).
So, how did I do that without getting bogged down in arguments about OOP methods?
Well it hinges on one of Twisol's ideas - that is that the plugin needs to know when all the plugins have been loaded (eg. at world startup), or when the plugins list has changed (eg. the user adds/deletes/reloads stuff).
So in ATCP_Mapper.xml we have this:
function OnPluginListChanged ()
do_plugin_check_now ("85f72d0e263d75df7bde6f00", "ATCP_NJG") -- check we have ATCP plugin
end -- OnPluginListChanged
So once all plugins have been loaded, and the order doesn't matter, we now check that we have all the plugins we want.
This particular function, in checkplugin.lua does this:
function do_plugin_check_now (id, name)
if IsPluginInstalled (id) then
return -- all is well
end -- plugin is installed
ColourNote ("white", "green", "Plugin '" .. name .. "' not installed. Attempting to install it...")
LoadPlugin (GetPluginInfo(GetPluginID (), 20) .. name .. ".xml")
if IsPluginInstalled (id) then
ColourNote ("white", "green", "Success!")
return -- all is well ... now
end -- plugin is installed
ColourNote ("white", "red", string.rep ("-", 80))
ColourNote ("white", "red", "Plugin '" .. name .. "' not installed. Please download and install it.")
ColourNote ("white", "red", "It is required for the correct operation of the " ..
GetPluginName () .. " plugin.")
ColourNote ("white", "red", string.rep ("-", 80))
end -- do_plugin_check_now
So it tries to load the required plugin, and if that fails, then it gives up and notifies the user.
Similarly my (original) mapper does this:
function OnPluginListChanged ()
item_ppi = load_ppi ("928dc37b201539cd14239ff0", "Item_Cache_Helper")
end -- OnPluginListChanged
This "item cache helper" is effectively your "global variables" plugin, except that they are just the variables needed for this subsystem.
If you can see a major flaw, please let me know. But basically instead of expecting to be able to do everything in the "install" part you wait for the "plugin list changed" part, with a couple of flags to let you know whether this is the first time through or not. |