Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Plugins ➜ Structuring a complex plugin

Structuring a complex plugin

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


Posted by Twisol   USA  (2,257 posts)  Bio
Date Sun 17 Jan 2010 12:30 AM (UTC)
Message
Some plugins are a lot easier to develop and maintain when they're broken up into multiple files, and I recently came up with a simple structuring paradigm to help achieve this. It's similar in concept to World of Warcraft's addons.

First, an example:
Gauges.plugin/
  plugin.xml
  resources/
    endurance.bmp
    exp.bmp
    gauges.bmp
    health.bmp
    mana.bmp
    willpower.bmp


Under this structural paradigm, every plugin is contained within its own folder (which itself should be under plugins/). The main plugin XML is contained within plugin.xml, which you might relate to a .toc file in World of Warcraft. And the resources are contained in a further subfolder, named resources/ in this case.

The plugin's folder is suffixed with '.plugin' to differentiate it from normal folders. 'plugin.xml' is thusly named so that an automated tool could be told to "install Gauges", and it would look for Gauges.plugin and install its plugin.xml. 'resources' is an arbitrary name that simply explains its content decently, containing plugin-specific, non-script-file resources.

A plugin can access anything within its folder simply by using GetPluginInfo(GetPluginID(), 20), and concatenating the desired file/resource.


This isn't really a question nor a suggestion, but I like the structure this gives me, and I figured I may as well let everyone else know, in case they want to use it.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 18 Jan 2010 08:53 PM (UTC)
Message
This is a good idea, and I should point out that a while ago I did a "plugin-loading plugin". This simply scanned a directory and loaded every plugin it could find (in fact, which is what WoW does when you add a plugin to the Addons directory).

This means installing a plugin simply requires putting it there (in the directory). You don't have to go into the program and "install" it like you do in MUSHclient.

Your proposed structure is more complex, but ultimately a lot more flexible. The directory scanning plugin could be changed to locate directories (one for each plugin) rather than simply .xml files.

The other thing that MUSHclient does not totally address now is the issue of dependent plugins (of course, the PPI stuff is heading in that direction).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #2 on Tue 09 Feb 2010 06:19 AM (UTC)
Message
As a follow-up on this recommendation, I propose two additional standard subfolders: scripts/ and libraries/. For example:

Gauges.plugin/
  plugin.xml
  scripts/
    -
  libraries/
    PPI.lua
  resources/
    endurance.bmp
    exp.bmp
    gauges.bmp
    health.bmp
    mana.bmp
    willpower.bmp


The scripts/ folder, while unused in the example, is simply a standard location to put the broken-up parts of the plugin, so the top-level directory contains only plugin.xml. The libraries/ folder is somewhat more important, as it provides a standard location to place third-party libraries that your script uses, such as the PPI module.


I am also considering authoring a small 'structured plugin' base library to include in the libraries/ folder, to abstract out the issues of dealing with dofile() rather than require() to load scripts and libraries. It would likely be an XML-wrapped file, so you could <include> it within your plugin.xml. I think it would be rather useful, personally. What are your thoughts?

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
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.


10,505 views.

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

Go to topic:           Search the forum


[Go to top] top

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