Guest User

Untitled

a guest
May 27th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. -- The plugin base table.
  2. PLUGIN = {};
  3.  
  4. -- A list for registered plugins.
  5. PLUGIN.list = {};
  6.  
  7. -- For storing data later on.
  8. PLUGIN.cache = {};
  9.  
  10. -- To register new plugins.
  11. function PLUGIN.register( name, data )
  12.     PLUGIN.list[ name ] = data;
  13. end
  14.  
  15. -- This return a table, of keys( by numbers ), in order, with a value that is a table, that has the names of the plugins in that priority number.
  16. -- We will do this so we can call plugins in specific order later on.
  17. function PLUGIN.ComputePriorityTable()
  18.    
  19.     print( "Computing priority table...");
  20.     local priority = {};
  21.    
  22.     for plugin,data in pairs( PLUGIN.list ) do
  23.        
  24.         -- The priority number for the current plugin.
  25.         local pn = data.priority;
  26.        
  27.         -- If there already is a plugin with this priority number, insert the plugin name.
  28.         if ( priority[pn]) then
  29.        
  30.             -- If there is no plugin in this priority list with the same name, then insert. if not, do nothing.
  31.             if ( !table.HasValue( priority[pn], plugin ) ) then
  32.                 table.insert( priority[pn], plugin );
  33.             else
  34.             end
  35.  
  36.         else
  37.        
  38.             priority[pn] = {};
  39.             table.insert( priority[pn], plugin );
  40.         end
  41.     end
  42.    
  43.     -- Put them in order from lowest to highest.
  44.     priority = table.SortByKey( priority, false );
  45.    
  46.     -- Cache things.
  47.     PLUGIN.cache.lowestpriority = table.GetFirstKey(priority);
  48.     PLUGIN.cache.highestpriority = table.maxn(priority);
  49.     PLUGIN.cache.prioritytable = priority;
  50.    
  51.     print( "Finished computing priority table!");
  52. end
  53.  
  54. -- Call all of them in order.
  55. function PLUGIN.CallPluginMainsByPriority()
  56.  
  57.     -- On the odd occassion there is no plugins.
  58.     if ( !PLUGIN.cache.prioritytable ) then return end;
  59.    
  60.     for _,v in pairs( PLUGIN.cache.prioritytable ) do
  61.        
  62.         for priority,name in pairs( v ) do
  63.            
  64.             if ( PLUGIN.list[name].main ) then
  65.                 PLUGIN.list[name].main( PLUGIN.list[name] );
  66.             end
  67.         end
  68.     end
  69. end
Add Comment
Please, Sign In to add comment