Code: Select all
function love.load()
local file = love.filesystem.newFile("example")
local ok, err = file:open("r")
if not ok then assert(ok, err) end
print("Is file open: "..tostring(file:isOpen()))
for line in file:lines() do
print(line)
print("File is still open: "..tostring(file:isOpen()))
end
print("Is file open after reading in all the lines: "..tostring(file:isOpen()))
print("When I try to close the file it returns: "..tostring(file:close()))
end
I stumbled across this when trying to use this https://love2d.org/wiki/SICK and was wondering why I kept getting unexpected behavior.Is file open: true
First line.
File is still open: true
Second line.
File is still open: true
Third line.
File is still open: true
Here's a fourth.
File is still open: true
A fifth.
File is still open: true
A minor fall.
File is still open: true
A major lift.
File is still open: true
The broken code composing
File is still open: true
hallelujah
File is still open: true
Is file open after reading in all the lines: false
When I try to close the file it returns: false
So, I can work around this, but I'm wondering if there's any other gotchas like this. Like does read() work this way?
Also I noticed file:open() doesn't like full filepaths like using love.filesystem.getWorkingDirectory()...'/'..filename, it always says the file doesn't exist.