Plugin Description
#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:


Messages In This Thread
Plugin Description - by ThuGie - 12-29-2013, 06:48 AM
RE: Plugin Description - by xoft - 12-29-2013, 06:52 AM
RE: Plugin Description - by ThuGie - 12-29-2013, 06:54 AM
RE: Plugin Description - by NiLSPACE - 12-29-2013, 07:00 AM
RE: Plugin Description - by xoft - 12-29-2013, 07:53 AM
RE: Plugin Description - by NiLSPACE - 12-29-2013, 08:44 AM
RE: Plugin Description - by SamJBarney - 12-29-2013, 08:02 AM
RE: Plugin Description - by xoft - 12-29-2013, 06:21 PM
RE: Plugin Description - by NiLSPACE - 12-29-2013, 10:48 PM
RE: Plugin Description - by xoft - 12-29-2013, 10:54 PM
RE: Plugin Description - by NiLSPACE - 12-29-2013, 10:57 PM
RE: Plugin Description - by xoft - 12-29-2013, 11:43 PM
RE: Plugin Description - by NiLSPACE - 12-29-2013, 11:51 PM
RE: Plugin Description - by NiLSPACE - 12-30-2013, 01:20 AM
RE: Plugin Description - by xoft - 12-30-2013, 03:31 AM
RE: Plugin Description - by NiLSPACE - 12-30-2013, 03:57 AM
RE: Plugin Description - by xoft - 12-30-2013, 04:33 AM
RE: Plugin Description - by NiLSPACE - 12-30-2013, 04:38 AM
RE: Plugin Description - by xoft - 12-30-2013, 05:36 AM
RE: Plugin Description - by NiLSPACE - 12-30-2013, 05:38 AM
RE: Plugin Description - by xoft - 12-30-2013, 05:42 AM
RE: Plugin Description - by NiLSPACE - 12-30-2013, 05:45 AM
RE: Plugin Description - by xoft - 12-30-2013, 06:08 AM
RE: Plugin Description - by NiLSPACE - 12-30-2013, 06:15 AM
RE: Plugin Description - by xoft - 12-30-2013, 06:19 AM
RE: Plugin Description - by ThuGie - 12-30-2013, 08:31 PM
RE: Plugin Description - by xoft - 01-05-2014, 05:33 AM
RE: Plugin Description - by ThuGie - 01-05-2014, 08:14 AM
RE: Plugin Description - by NiLSPACE - 01-05-2014, 08:41 AM
RE: Plugin Description - by ThuGie - 01-05-2014, 09:17 AM
RE: Plugin Description - by xoft - 01-05-2014, 11:55 PM
RE: Plugin Description - by xoft - 01-06-2014, 01:21 AM
RE: Plugin Description - by NiLSPACE - 01-12-2014, 01:42 AM
RE: Plugin Description - by xoft - 01-12-2014, 02:53 AM
RE: Plugin Description - by NiLSPACE - 01-12-2014, 03:05 AM
RE: Plugin Description - by NiLSPACE - 01-12-2014, 07:19 AM
RE: Plugin Description - by xoft - 01-12-2014, 08:12 AM
RE: Plugin Description - by NiLSPACE - 01-12-2014, 08:19 AM
RE: Plugin Description - by xoft - 01-12-2014, 08:23 AM
RE: Plugin Description - by NiLSPACE - 01-12-2014, 08:25 AM
RE: Plugin Description - by xoft - 01-12-2014, 08:28 AM



Users browsing this thread: 11 Guest(s)