I am trying to read a file with the end of a CR line using the file:read method, which for some reason seems to work. The contents of the file are as follows:
ABCDEFGH 12345
I want him to behave consistently with all types of line endings. Each time I try to read a file, it returns the last line in the file, combined with any trailing characters from previous lines that have a greater position than the position of the last character in the last line. Here is what I mean:
> file=io.open("test.lua", "rb") > function re_read(openFile) openFile:seek("set"); return openFile:read("*a"); end > =re_read(file) -- With CR 67895FGH > =re_read(file) -- With CRLF ABCDEFGH 12345 ## 6789 > =re_read(file) -- with LF ABCDEFGH 12345 ## 6789 >
As you can see, the returned row is the last row plus 5 in the previous row and plus FGH from the first row. Any lines shorter than the last line are skipped.
My goal is to use the file:line() method to read a file line by line. I hope that if "fix" for file:read is found, it can be applied to file:lines() .
source share