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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  Reload plugin alias

Reload plugin alias

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


Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Thu 23 Jul 2009 08:01 AM (UTC)

Amended on Wed 31 Aug 2011 06:48 AM (UTC) by Nick Gammon

Message
I was just browsing some other forums with references to MUSHclient, and I was very impressed with the level of support provided for MUSHclient there. :-)

Anyway, a question was asked about how to quickly reload a plugin after testing. I know I had an alias to do just that, but can't find it myself on this forum, so probably no-one else can either. :(

This is what I use when testing a new plugin:



<aliases>
  <alias
   match="rl"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

local plugin_id = "0abe0dab0170ede5f1ea0650"
local plugin_file = "/Program Files/MUSHclient/worlds/plugins/PLUGIN_NAME_HERE.xml"

local status = ReloadPlugin (plugin_id)

if status == error_code.eBadParameter then
  Note ("Cannot reload ourself.")
elseif status == error_code.eNoSuchPlugin then
  check (LoadPlugin (plugin_file))
end

if GetPluginInfo (plugin_id, 1) then
  Note (GetPluginInfo (plugin_id, 1) .. " reloaded.")
end -- if have it now

</send>
  </alias>
</aliases>



Basically this tries to reload the plugin (with ReloadPlugin) - this reloads an existing plugin, thus letting you test changes. However if the reason you are reloading is a syntax error in the plugin, then it won't exist in the first place, so as a fallback it calls LoadPlugin to load the plugin back in from disk.

So, for your own plugins you need to change two things:


  • The plugin ID (this is from the line id="0abe0dab0170ede5f1ea0650" in the plugin header)

  • The actual file name of the plugin, whatever that is.


Once you have done this, just type "rl" to reload the plugin and test your changes.

Thanks to Zarquan, Isuka, Esano and everyone else who is working hard to support MUSHclient on other forums. :)

[EDIT] Modified 31 August 2011 to test for a plugin attempting to reload itself.


- Nick Gammon

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

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #1 on Thu 23 Jul 2009 08:21 AM (UTC)
Message
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=9216

My google-fu is strong, grasshopper.
:)

It's buried in a thread with a very descriptive title of "Someone help me please"

[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #2 on Thu 23 Jul 2009 09:56 AM (UTC)
Message
I can see a few ways to improve it - making the plugin ID an alias parameter, for instance, or even looking up the ID based on a plugin's name - but this is definitely a very useful alias for development :)

'Soludra' on Achaea

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

Posted by Talryk   (3 posts)  [Biography] bio
Date Reply #3 on Wed 31 Aug 2011 06:24 AM (UTC)
Message
Heya, sorry to necromance such an old topic.

I took a close look at this alias as well as the other one cited by WillFa, and they both work just fine as world aliases. However, is there any way to call the Reload/LoadPlugin() functions from -within- the function being reloaded? I included an alias to define one's own file path, but it seems that the function completes (it gives me a '<plugin> reloaded' note), but changes are never reflected.

The goal is to give the people I hand this plugin out to a way to easily update it when I commit changes to it via SVN, so if anyone has better ideas I'm also open to suggestions.
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #4 on Wed 31 Aug 2011 06:33 AM (UTC)
Message
I think in order to use them from within the plugin, you should use DoAfterSpecial.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Wed 31 Aug 2011 06:48 AM (UTC)
Message
I modified the original post to check for a plugin reloading itself, which isn't allowed.

Meanwhile, as Fiendish says, doing the reload on a timer should work.

- Nick Gammon

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

Posted by Talryk   (3 posts)  [Biography] bio
Date Reply #6 on Wed 31 Aug 2011 07:38 AM (UTC)
Message
Bah... Now I can't figure out where to implement DoAfterSpecial, and whether to match it to the plugin id or the file path, or both. My alias is as follows:


  <alias
   match="overgrowth:install"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

local plugin_id = "a8f9186fe987788ee0e94168"
local plugin_file = GetVariable("filepath").."/OvergrowthA.xml"

local status = ReloadPlugin (plugin_id)

if status == error_code.eBadParameter then
  Note ("Cannot reload ourself.")
elseif status == error_code.eNoSuchPlugin then
  check (LoadPlugin (plugin_file))
end

if GetPluginInfo (plugin_id, 1) then
  Note (GetPluginInfo (plugin_id, 1) .. " reloaded.")
end -- if have it now

DoAfterSpecial(1, 'ReloadPlugin("a8f9186fe987788ee0e94168")', sendto.script)

</send>
</alias>


I put it at the end since I couldn't decide where to place it, and I -do- see TRACE: Fired unlabelled timer after 1 second, but I'm still not seeing changes reflected. In my particular case, the "filepath" variable is "/Users/Joe" and the xml is located there.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Wed 31 Aug 2011 11:00 AM (UTC)
Message
Hmm. Perhaps our advice was a bit wrong.

DoAfterSpecial adds a timer *in the context of the current plugin*.

So you have only moved the same problem forwards a second.

There will be ways around it ... the trick is to find the simplest.

You could make a second plugin, whose only job is to reload your "main" one. Then put the reload alias in that (ie. plugin #2 reloads plugin #1). Then you don't even need the timer.

I think another way could be to use the Execute function. That shrugs off the current plugin, I think. So if the alias called Execute "alias2" and alias2 did the DoAfterSpecial, that might work, although I haven't tested it. Make sure you use the timer in this case though, or you remove the script from underneath the executing plugin.

- Nick Gammon

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

Posted by Talryk   (3 posts)  [Biography] bio
Date Reply #8 on Thu 01 Sep 2011 02:54 AM (UTC)
Message
While not my most preferred option, creating a separate plugin performs the task perfectly and is easy enough to implement. Thanks for the suggestion, Nick!
[Go to top] top

Posted by Ada   (20 posts)  [Biography] bio
Date Reply #9 on Sat 03 Sep 2011 01:20 PM (UTC)
Message
Hi! I just read this post and figured I'd chip in too! Here's the alias I use to reload plugins. Just hit 'replug <pluginname>' and it shall be done! It is case insensitive as well.



<aliases>
  <alias
   name="RePlug"
   match="^replug (.+)$"
   enabled="y"
   group="Plugins"
   regexp="y"
   send_to="12"
   ignore_case="y"
   sequence="100"
  >
  <send>local pluginname = string.lower("%1")
local plugins = GetPluginList()
for k, v in ipairs(plugins) do
  if string.lower(GetPluginInfo(v, 1)) == pluginname then
    ReloadPlugin(v)
  end
end</send>
  </alias>
</aliases>
[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.


31,411 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]