Advertisement
ZottelvonUrvieh

test

Jul 26th, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. function fwrite(path, text)
  2.     local file = assert(io.open(path, "w"))
  3.     file:write(text)
  4.     file:close()   
  5. end
  6.  
  7. function fread(path)
  8.     if fs.exists(path) then
  9.         local file = assert(io.open(path, "r"))
  10.         answer =  file:read("*l")
  11.         file:close()
  12.         return answer
  13.     end
  14.     return nil
  15. end
  16.  
  17. function writeFromTable(path, t)
  18.     local text = ""
  19.     for _, line in pairs(t) do
  20.         text = text..line.."\n"
  21.     end
  22.     fwrite(path, text)
  23. end
  24.  
  25. function getTable(path)
  26.     if fs.exists(path) then
  27.         local file = io.open(path, "r")
  28.         local lines = {}
  29.         local i = 1
  30.         local line = file:read("*l")
  31.         while line ~= nil do
  32.             lines[i] = line
  33.             line = file:read("*l")
  34.             i = i + 1
  35.         end
  36.         file:close()
  37.         return lines
  38.     end
  39.     return {}
  40. end
  41.  
  42. function replaceLine(path, n, text)
  43.     local lines = getTable(path)
  44.     lines[n] = text
  45.     writeFromTable(path, lines)
  46. end
  47.  
  48. function append(path, text)
  49.     local file = assert(io.open(path, "a"))
  50.     file:write(text.."\n")
  51.     file:close()
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement