Advertisement
Hoolaf

lib/updates/updater

Sep 15th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.12 KB | None | 0 0
  1. -- AutoUpdater v1.1 by Hoolaf for ComputerCraft
  2. os.loadAPI ("//lib/updates/src")
  3. src = src.init()
  4. Updater = { src = src }
  5. Updater.mt = { }
  6.  
  7. function Updater:new ()  
  8.   local updater = Updater
  9.   setmetatable(updater, Updater.mt)
  10.   return updater
  11. end  
  12.  
  13. function Updater:expandTable (table)
  14.    
  15.     for k, v in pairs(table) do
  16.       if type(v) ==  "string" then
  17.         Updater[k] = v
  18.       end
  19.      
  20.       if type(v) == "table" then
  21.         for key, val in pairs(v) do
  22.           Updater[key] = val
  23.         end
  24.       end
  25.     end
  26.   return Updater
  27. end
  28.  
  29. function Updater:update (mode)
  30.   Updater = Updater:expandTable(Updater.src.getTable(mode))
  31.  
  32.   if turtle == false then
  33.    tbl = Updater.src.getTable("turtle")
  34.     for k, v in pairs(Updater) do
  35.       for key, val in pairs(tbl) do
  36.         if tostring(key) == tostring(k) then k = nil end
  37.       end
  38.     end
  39.   end
  40.  
  41.   for k, v in pairs(Updater) do
  42.     if type(v) == "string" then
  43.       dir = "//" .. string.gsub(tostring(k), "_",  "/")
  44.       didPaste = shell.run("pastebin", "get", v, dir)
  45.     end
  46.   end
  47. end
  48.  
  49. updater = Updater:new()
  50. return updater
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement