Advertisement
Zekrommaster110

[LUA | CC] getany tool

Jun 20th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | None | 0 0
  1. -- getany for ComputerCraft
  2. -- © 2017 zekro Development
  3.  
  4. -- Install tool on ComputerCraft OS with
  5. -- > pastebin get BMfsbF4j getany
  6.  
  7. -- Get usage info with:
  8. -- > getany
  9. -- Download a RAW online text file:
  10. -- > getany <filename> <url>
  11. -- INFO: <filename> needs to be ONE SINGLE STRING without spaces!
  12.  
  13.  
  14.  
  15. local args = table.pack(...)
  16.  
  17. function tablenght(intable)
  18.   local count = 0
  19.   for i in pairs(intable) do
  20.     count = count + 1
  21.   end
  22.   return count
  23. end
  24.  
  25. if args[1] == "info" then
  26.   print("\nINFO:\n")
  27.   print("(c) Copyright zekro 2017")
  28.   print("\ndev.zekro.de - github.zekro.de")
  29.   do return end
  30. end
  31.  
  32. if tablenght(args) < 2 then
  33.   print("\nUSAGE:\n")
  34.   print(" Use this to download online RAW text file:\n > getany <name_of_program> <url>\n")
  35.   print(" Use this to get informatio about the tool:\n > getany info")
  36.   do return end
  37. end
  38.  
  39. function download()
  40.  
  41.   content = http.get(args[2]).readAll()
  42.   if not content then
  43.     error("[ERROR] Could not download from " + args[2] + ".")
  44.   end
  45.  
  46.   f = fs.open(args[1], "w")
  47.   f.write(content)
  48.   f.close()
  49.  
  50.   print("\nSuccessfully saved code from \n'", args[2], "' \nunder the name \n'", args[1], "' \non this computer.")
  51.  
  52. end
  53.  
  54.  
  55. -- MAIN
  56. if string.sub(args[2], 1, 4) == "http" then
  57.   download()
  58. else
  59.   print("\nPlease enter a valid URL to download or enter argument 'info' to get information about that program.")
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement