Advertisement
FantasticFurries

Untitled

Aug 18th, 2022
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.54 KB | None | 0 0
  1. local InitializeFuncs = script:GetChildren()
  2. script:ClearAllChildren()
  3.  
  4. local Apollo = newproxy(true)
  5. local ApolloMeta = getmetatable(Apollo)
  6. ApolloMeta.__metatable = "Locked for security reasons."
  7.  
  8. local rawprint = print
  9. print = function(...) if _G.ApolloDebug then rawprint(unpack({...})) end end
  10.  
  11. local TableMeta = {}
  12. TableMeta.__metatable = "Locked for security reasons."
  13. TableMeta.__index = function(self,ind) local val = rawget(self,ind) print("Get:",self,ind,val) if type(val) ~= nil then return val end end
  14. TableMeta.__newindex = function(self,ind,val) print("Apollo : Set:",self,ind,val) rawset(self,ind,val) end
  15.  
  16. local ApolloIndex = {}
  17. setmetatable(ApolloIndex,TableMeta)
  18.  
  19. local Storage = {}
  20. setmetatable(Storage,TableMeta)
  21.  
  22. do
  23.     local function HandleInit(InitModule,InitData)
  24.         if InitData.Meta then
  25.             if not ApolloMeta[InitData.Meta] then
  26.                 if InitData.Function then
  27.                     rawset(ApolloMeta,InitData.Meta,function(self,...) return InitData.Function(ApolloIndex,unpack({...})) end)
  28.                 else
  29.                     warn("Apollo : Apollo meta initialization failure due to missing function:",InitData.Meta)
  30.                 end
  31.             else
  32.                 warn("Apollo : Apollo meta initialization failure due to pre-existing meta:",InitData.Meta)
  33.             end
  34.         else
  35.             if InitData.Function then
  36.                 local RunSucc,RunErr = pcall(function() return InitData.Function(Apollo,ApolloIndex,Storage) end)
  37.                 if not RunSucc then
  38.                     warn("Apollo : Apollo initialization failure when attempting to execute:",InitModule.Name,"-",RunErr)
  39.                 end
  40.             end
  41.         end
  42.     end
  43.  
  44.     local LoadOrder = {}
  45.     LoadOrder.Pre = {}
  46.     LoadOrder.Before_Meta = {}
  47.     LoadOrder.Meta = {}
  48.     LoadOrder.After_Meta = {}
  49.     LoadOrder.After_Core = {}
  50.     LoadOrder.Services = {}
  51.     LoadOrder.After_Services = {}
  52.     LoadOrder.Unordered = {}
  53.     LoadOrder.Final = {}
  54.  
  55.     for i=1,#InitializeFuncs do
  56.         local InitModule = InitializeFuncs[i]
  57.         if type(InitModule) == "userdata" and InitModule:IsA("ModuleScript") then
  58.             local InitSucc,InitErr = pcall(function() return require(InitModule) end)
  59.             if not InitSucc then
  60.                 warn("Apollo : Apollo initialization failure:",InitErr)
  61.             else
  62.                 local InitData = InitErr
  63.                 if InitData.Meta then
  64.                     table.insert(LoadOrder.Meta,{InitModule,InitData})
  65.                 else
  66.                     if InitData.LoadOrder and LoadOrder[InitData.LoadOrder] then
  67.                         table.insert(LoadOrder[InitData.LoadOrder],{InitModule,InitData})
  68.                     else
  69.                         table.insert(LoadOrder.Unordered,{InitModule,InitData})
  70.                     end
  71.                 end
  72.             end
  73.         end
  74.     end
  75.     for i=1,#LoadOrder.Pre do
  76.         local Load = LoadOrder.Pre[i]
  77.         HandleInit(Load[1],Load[2])
  78.     end
  79.     for i=1,#LoadOrder.Before_Meta do
  80.         local Load = LoadOrder.Before_Meta[i]
  81.         HandleInit(Load[1],Load[2])
  82.     end
  83.     for i=1,#LoadOrder.Meta do
  84.         local Load = LoadOrder.Meta[i]
  85.         HandleInit(Load[1],Load[2])
  86.     end
  87.     for i=1,#LoadOrder.After_Meta do
  88.         local Load = LoadOrder.After_Meta[i]
  89.         HandleInit(Load[1],Load[2])
  90.     end
  91.     for i=1,#LoadOrder.After_Core do
  92.         local Load = LoadOrder.After_Core[i]
  93.         HandleInit(Load[1],Load[2])
  94.     end
  95.     for i=1,#LoadOrder.Services do
  96.         local Load = LoadOrder.Services[i]
  97.         HandleInit(Load[1],Load[2])
  98.     end
  99.     for i=1,#LoadOrder.After_Services do
  100.         local Load = LoadOrder.After_Services[i]
  101.         HandleInit(Load[1],Load[2])
  102.     end
  103.     for i=1,#LoadOrder.Unordered do
  104.         local Load = LoadOrder.Unordered[i]
  105.         HandleInit(Load[1],Load[2])
  106.     end
  107.     for i=1,#LoadOrder.Final do
  108.         local Load = LoadOrder.Final[i]
  109.         HandleInit(Load[1],Load[2])
  110.     end
  111. end
  112.  
  113. local suc,err = pcall(function() return getmetatable(Apollo) end) print("Apollo : Apollo Meta:",suc,err)
  114.  
  115. return Apollo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement