Advertisement
SuPeRMiNoR3

Untitled

Dec 12th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. local version = "0.4.5"
  2. local m = {}
  3.  
  4. local component = require("component")
  5. if not component.isAvailable("internet") then
  6. error("This program requires an internet card to run.")
  7. return
  8. end
  9.  
  10. local serial = require("serialization")
  11. local internet = require("internet")
  12. local wget = loadfile("/bin/wget.lua")
  13.  
  14. local function downloadRaw(url)
  15. local sContent = ""
  16. local result, response = pcall(internet.request, url)
  17. if not result then
  18. return nil
  19. end
  20. for chunk in response do
  21. sContent = sContent..chunk
  22. end
  23. return sContent
  24. end
  25.  
  26. local function downloadFile(url, path)
  27. return wget("-fq",url,path)
  28. end
  29.  
  30. function m.getVersion() --For getting the version of superlib without making an internet request
  31. return version
  32. end
  33.  
  34. function m.checkVersions()
  35. response = downloadFile("https://raw.githubusercontent.com/OpenPrograms/SuPeRMiNoR2-Programs/master/versions.lua", "/tmp/versions.lua")
  36. versions = loadfile("/tmp/versions.lua")() --The () are needed
  37. return versions, version
  38. end
  39.  
  40. function m.downloadFile(url, path)
  41. local success, response = pcall(downloadFile, url, path)
  42. if not success then
  43. return nil
  44. end
  45. return response
  46. end
  47.  
  48. function m.download(url)
  49. local success, response = pcall(downloadRaw, url)
  50. if not success then
  51. return nil
  52. end
  53. return response
  54. end
  55.  
  56. function m.round(what, precision)
  57. return math.floor(what*math.pow(10,precision)+0.5) / math.pow(10,precision)
  58. end
  59.  
  60. function m.pgen(stored, capacity, precision)
  61. tmp = stored / capacity
  62. tmp = tmp * 100
  63. tmp = m.round(tmp, precision)
  64. return tmp
  65. end
  66.  
  67. function m.pad(str, len)
  68. char = " "
  69. if char == nil then char = ' ' end
  70. return str .. string.rep(char, len - #str)
  71. end
  72.  
  73. function oldround(num, idp)
  74. local mult = 10^(idp or 0)
  75. return math.floor(num * mult + 0.5) / mult
  76. end
  77.  
  78. function m.decode(data)
  79. status, result = pcall(serial.unserialize, data)
  80. return status, result
  81. end
  82.  
  83. function m.encode(data)
  84. return serial.serialize(data)
  85. end
  86.  
  87. return m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement