Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- cJdTak4C
- local module = {}
- module.setLines = function(filePath,lines)
- if filePath == nil then printError("Filepath is nil"); end
- if fs.isDir(filePath) then return nil end
- local file = fs.open( filePath, "w" )
- local data = ""
- for i = 1, #lines do
- data = data..lines[i]
- if i ~= #lines then
- data = data.."\n"
- end
- end
- file.write(data)
- file.close()
- end
- module.getLines = function(filePath)
- if filePath == nil then printError("Filepath is nil"); end
- if fs.exists(filePath) == false then return nil end
- if fs.isDir(filePath) then return nil end
- local fileHandle = fs.open(filePath, 'r')
- -- Validate handle.
- if not fileHandle then
- return
- end
- local fileContents = fileHandle.readAll()
- fileHandle.close()
- local lines = {}
- local i = 1
- for line in fileContents:gmatch("[^\n]+") do
- lines[i] = string.gsub(line,"\n","")
- i = i + 1
- end
- return lines
- end
- return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement