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 ➜ Creating a 'package' of plugins in a folder

Creating a 'package' of plugins in a folder

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


Posted by Xinefus   (106 posts)  Bio
Date Fri 28 Aug 2020 06:44 PM (UTC)
Message
Hello folks,

I'm wondering how I can make a folder within ./plugins and be able to load all my custom plugins from there.

With that said, I an not sure how/if I need to use
  • dofile()
  • GetPluginInfo()
  • GetPluginID()
to first refer to dependent files within that folder (or a folder in there as well) or refer to different directories for the already built-in files in MUSHclient.

I would think that using 'require' won't work anymore?

My intention here is to have something very similar to how RoD has done theirs, but I don't think I want to write all my plugins in one long file, that sounds a bit disastrous.

RoD ref: http://realmsofdespair.com/plugins
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 28 Aug 2020 09:18 PM (UTC)
Message

See this post.

In particular, you can “dofile” to load in the Lua code, which also has the advantage that the plugin is now not a mixture of Lua code and XML. That way syntax colouring in your editor works much better.

You could conceivably “dofile” more than one file, to make it modular.

And you could always use a subdirectory, which I think Aardwolf does, to keep things separated from plugins that are not relevant to your system.

I used this technique for my Learning Mapper which made code development much easier (it was a large project).


- Nick Gammon

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

Posted by Xinefus   (106 posts)  Bio
Date Reply #2 on Sat 29 Aug 2020 01:50 AM (UTC)
Message
Thank you Nick, that was exactly what I needed to find.


Cheers,
Top

Posted by Bast   (78 posts)  Bio
Date Reply #3 on Sat 29 Aug 2020 03:27 PM (UTC)
Message
you can check out my plugins at https://github.com/endavis/bastmush

If you want to be able to use "require" to load libraries inside your folder or a subfolder then you can update the lua path. Here's how I do it.

In each plugin I have


dofile (GetPluginInfo (GetPluginID (), 20) .. "luapath.lua")


luapath.lua looks like this:

plugin_path = string.match(GetPluginInfo(GetPluginID(), 6), "(.*)\.*$") .. "\lua\"
package.path = plugin_path .. "?;" .. plugin_path .. "?.lua;" .. package.path


This adds a lua folder under the directory the plugins are in to the lua package path so that I can have libraries in the lua folder and use require to load them.

Then, any of my lua code goes into the lua folder.

Bast

Bast

Scripts: http://github.com/endavis
Top

Posted by Xinefus   (106 posts)  Bio
Date Reply #4 on Sun 30 Aug 2020 01:01 PM (UTC)
Message
Thank you Bast! I'm looking into this and this helps a lot.


Cheers,
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.


14,550 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.