Plugin Description
#31
And the beautiful part is that the Info.lua file is actually used to register the commands, so when a command or subcommand is added in the code, it automatically gets documented, at least the fact that it exists.

Of course, there's still the issue of writing the real documentation, all the "sauce" around setup, each individual command etc., but in the end even that pays off because it allows us, as developers, verify that our code does what we want it to do. Especially when the command has several variations of parameters that it accepts, such as the "/gallery name" command.

Now we need to document the Info.lua file format and make other plugins' authors actually use itBig Grin That's gonna be the hardest part.
Reply
Thanks given by:
#32
Hmm, translations......
Reply
Thanks given by:
#33
X-Post from The Gallery plugin thread:

Me:
How did you init the handlers in the Info.lua? I'm now working on another plugin but I have to use dofile(PLUGIN:GetLocalFolder() .. "/Info.lua") first and then use the RegisterPluginInfoCommands() function.

Xoft:
I'm doing the registration in the Initialize() function; so that I know that all the Lua files inside the plugin folder have already been loaded and the globals are available.

Me:
I have the RegisterPluginInfoCommands() function in the Initialize function but if I don't put the dofile function before it I get these errors: [Image: 6hcsJ.png]

Code Repo:
https://github.com/STRWarrior/Paths
Reply
Thanks given by:
#34
You're right, it's dependent on the order in which the lua files are loaded for a plugin. This order is currently undefined in MCS.

There are three solutions to this:
1, Keep the order undefined and change RegisterPluginInfoCommands() to do a "dofile(Info.lua)" before registering. It would work as-is, but it loses a bit of (startup) performance because lua has to process (load and compile) the Info.lua file twice.

2, Define a strict order in which the files are loaded, and make Info.lua the last file to load. This would make all the plugins work without any change on their part, doesn't lose performance, but is somewhat non-systematic - why have one file explicitly defined to be the last one loaded? It would make programmers think that they can use the same technique as the Info.lua file (storing functions in a global table), when in fact it might not work.

3, Change g_PluginInfo not to be a table, but rather a global function that returns the info table:
function GetPluginInfo()
  return
  {
    Name = "MyPlugin",
    Commands = ...,
  };
end
It will work without changing the server code and with only minor modifications to the plugin source. However, I'm not sure about performance - I think each time the function is called, Lua will construct the info table anew.

Ha! I think I've got it. #3 can be changed to keep the performance while having the least amount of trouble:
local g_PluginInfo = nil;  -- This will contain the info table, once constructed

function GetPluginInfo()
  if (g_PluginInfo ~= nil) then
    -- The plugin info has already been constructed, return it:
    return g_PluginInfo;
  end

  -- Construct the plugin info into the cache:
  g_PluginInfo =
  {
    Name = "MyPlugin",
    Commands = ...,
  };
  return g_PluginInfo;
end
Reply
Thanks given by:
#35
xoft Wrote:Ha! I think I've got it. #3 can be changed to keep the performance while having the least amount of trouble:
:O We share the same thought Wink I did that after reading your first post (kinda) Wink
Reply
Thanks given by:
#36
I've finaly successfully managed to make the InfoDump work. Why is it using LuaRocks when it only checks if the file/folder exists? It can use cFile for that.
Reply
Thanks given by:
#37
It runs directly in Lua, not in MCServer, so it doesn't have the cFile API. And it needs a list of all subfolders, which is accessible only through LFS.
Reply
Thanks given by:
#38
Oww... then I editted it so it only works with MCServer :S. I use cFile to only document my plugin.
Reply
Thanks given by:
#39
The InfoDump.lua script is supposed to be run from the Plugins folder where it is stored, under Lua, with LuaRocks installed; then it will document all the plugins for which it can find the Info.lua file.
Reply
Thanks given by:
#40
Ahh now it makes sense Wink But still I have no idea how to install LuaRocks
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)