Advertisement
billysback

modder

Dec 20th, 2012
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. --[[
  2.     MOD SETTINGS:
  3.         ROOT = ROOT OF MAIN PROGRAM IN COMPUTER
  4.         MODS = TABLE CONTAINING ALL MOD ROOTS, enter string containing root.
  5. ]]
  6.  
  7. local root = "PUT PROGRAM ROOT HERE"
  8. local mods = {
  9.  
  10. }
  11.  
  12.  
  13. --[[
  14.     MOD INSTALLER CODE
  15.     COMPATIBALE WITH MOST THINGS
  16. ]]
  17.  
  18. local tAPIsLoading = {}
  19. local function loadMod(dir)
  20.     if dir ~= nil then
  21.         local _sPath = dir
  22.         local sName = fs.getName( _sPath )
  23.         local n = 1
  24.         while tAPIsLoading[sName] == true and n < 300 do
  25.             n = n + 1
  26.             sleep(0)
  27.         end
  28.         if n < 300 then
  29.             tAPIsLoading[sName] = true
  30.                
  31.             local tEnv = {}
  32.             setmetatable( tEnv, { __index = _G } )
  33.             local fnAPI, err = loadfile( _sPath )
  34.             if fnAPI then
  35.                 setfenv( fnAPI, tEnv )
  36.                 fnAPI()
  37.             else
  38.                 printError( err )
  39.                 tAPIsLoading[sName] = nil
  40.                 return nil
  41.             end
  42.            
  43.             local tAPI = {}
  44.             for k,v in pairs( tEnv ) do
  45.                 tAPI[k] =  v
  46.             end
  47.            
  48.             tAPIsLoading[sName] = nil
  49.             return tAPI
  50.         else
  51.             return nil
  52.         end
  53.     else
  54.         return nil
  55.     end
  56. end
  57.  
  58. if fs.exists(root) then
  59.     local main = loadMod(root)
  60.    
  61.     main.startup()
  62.     local lMods = {}
  63.     for i=1,#mods do
  64.         if fs.exists(mods[i]) then
  65.             local md = loadMod(mods[i])
  66.             md.run(main)
  67.             lMods[#lMods + 1] = md
  68.         end
  69.     end
  70.     main.run(lMods)
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement