Reload a plugin from within a plugin.

Posted by Blainer on Fri 20 Nov 2009 06:29 AM — 8 posts, 34,561 views.

#0
I'm trying to make a function to clear all variables in a plugin then reload the plugin.

In the help file for ReloadPlugin() it mentions DoAfterSpecial(). I've tried this but it didn't work.

Any suggestions?
Australia Forum Administrator #1
In what way does it not work? And why do you want to do it?

Template:post=9615
Please see the forum thread: http://gammon.com.au/forum/?id=9615.
#2
I want the alias to be from within the plugin not on the world file.

DoAfterSpecial (1, "ReloadPlugin(GetPluginID())", 12)

It just does nothing and the error from check is Bad Parameter.

Does the plugin need to remove itself just after this DoAfter? If so how?
#3
I had a thought I could achieve this with a single variable that makes the plugin do everything as though it was a first time install. That would remove all old info. I would need a little note to the user on re-installing the plugin from the plugins dialog but it would only be when the plugin had a repeating error because it was saving and loading bad info this happens when I change the plugin a lot then load it into a world with an old state file. But it makes me want an easy way to fix up with out needing to open a file manager.

Any ideas would be welcome.
Australia Forum Administrator #4
Ah, yes, the DoAfterSpecial just defers for one second something it can't do now, to something it can't do a second later. :)

I note the help says "use something like DoAfterSpecial". Maybe some different approach? You need to somehow reload the plugin in global script space, not plugin script space. A running plugin can hardly reload itself.

However I would suggest fixing your problem a different way. For example, since Lua keeps everything in tables, just re-initialize the tables, rather than reloading the plugin.
Amended on Sat 21 Nov 2009 01:16 AM by Nick Gammon
USA #5

local action = "DoAfterSpecial(1, ReloadPlugin([[" .. GetPluginID() .. "]]), 12)"

local prefix = GetAlphaOption("script_prefix")
if prefix == "" then
  SetAlphaOption("script_prefix", "/")
  Execute("/" .. action)
  SetAlphaOption("script_prefix", "")
else
  Execute(prefix .. action)
end


I think that would work. I do think you could accomplish your goals in a better way, though, as Nick mentioned.
Amended on Tue 05 Dec 2017 07:18 PM by Fiendish
USA Global Moderator #6
Twisol said:


local action = "DoAfterSpecial(1, ReloadPlugin('" .. GetPluginID() .. "'), 12)"

local prefix = GetAlphaOption("script_prefix")
if prefix == "" then
  SetAlphaOption("script_prefix", "/")
  Execute("/" .. action)
  SetAlphaOption("script_prefix", "")
else
  Execute(prefix .. action)
end


I think that would work.


Note of warning: This crashes MUSHclient for me initiating it from the input bar with CallPlugin even if I put the Executes in their own DoAfterSpecials. I don't understand why.
Amended on Tue 05 Dec 2017 08:12 PM by Fiendish
Australia Forum Administrator #7
It is because the function call ReloadPlugin is done now, not after one second:


local action = "DoAfterSpecial(1, ReloadPlugin([[" .. GetPluginID() .. "]]), 12)"
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


You need to quote it:


local action = "DoAfterSpecial(1, 'ReloadPlugin([[" .. GetPluginID() .. "]])', sendto.script)"
                                  ^                                         ^


Now that says, after one second execute the script command (the thing in quotes).