Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fwrite(path, text)
- local file = assert(io.open(path, "w"))
- file:write(text)
- file:close()
- end
- function fread(path)
- if fs.exists(path) then
- local file = assert(io.open(path, "r"))
- answer = file:read("*l")
- file:close()
- return answer
- end
- return nil
- end
- function writeFromTable(path, t)
- local text = ""
- for _, line in pairs(t) do
- text = text..line.."\n"
- end
- fwrite(path, text)
- end
- function getTable(path)
- if fs.exists(path) then
- local file = io.open(path, "r")
- local lines = {}
- local i = 1
- local line = file:read("*l")
- while line ~= nil do
- lines[i] = line
- line = file:read("*l")
- i = i + 1
- end
- file:close()
- return lines
- end
- return {}
- end
- function replaceLine(path, n, text)
- local lines = getTable(path)
- lines[n] = text
- writeFromTable(path, lines)
- end
- function append(path, text)
- local file = assert(io.open(path, "a"))
- file:write(text.."\n")
- file:close()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement