Biopsy

utils 2.0

May 16th, 2012
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.90 KB | None | 0 0
  1. function termwrite(message)
  2.   cx, cy = term.getCursorPos()
  3.   mx, my = term.getSize()
  4.   term.write(message)
  5.   if(cy == my) then
  6.     term.scroll(1)
  7.     term.setCursorPos(1, cy)
  8.   else
  9.     term.setCursorPos(1, cy + 1)
  10.   end  
  11. end
  12.  
  13. function copytable(t)
  14.   local t2 = {}
  15.   for k,v in pairs(t) do
  16.     t2[k] = v
  17.   end
  18.   return t2
  19. end
  20.  
  21. function download(source, destination)
  22.   local tmpF = http.get(source)
  23.   sleep(5)
  24.   local txt = tmpF:readAll()
  25.   local file = io.open(destination, "w")
  26.   file:write(txt)
  27.   file:close()
  28. end
  29.  
  30. function vartofile(variable, filename)
  31.   file = fs.open(filename, "w")
  32.   file.write(textutils.serialize(variable))
  33.   file:close()
  34. end
  35.  
  36. function varfromfile(filename)
  37.   if(fs.exists(filename)) then
  38.     file = fs.open(filename, "r")
  39.     contentsu = textutils.unserialize(file.readLine())
  40.     file:close()
  41.     return contentsu
  42.   else
  43.     return nil
  44.   end
  45. end
Advertisement
Add Comment
Please, Sign In to add comment