Creating a 'package' of plugins in a folder

Posted by Xinefus on Fri 28 Aug 2020 06:44 PM — 5 posts, 21,196 views.

#0
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
Australia Forum Administrator #1

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).

#2
Thank you Nick, that was exactly what I needed to find.


Cheers,
#3
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
#4
Thank you Bast! I'm looking into this and this helps a lot.


Cheers,