Original code is quite long so I won't post it unless it's requested, but a shorter version is below. The original returned 59 indefinitely on EOF, the code below returns 7.
The test code writes the return values to a file (on my system this is C:\Users\<me>\AppData\Roaming\LOVE\gn32\log.txt).
Code: Select all
love.filesystem.setIdentity("gn32")
function love.load()
local log = love.filesystem.newFile("log.txt")
log:open("w")
local file = love.filesystem.newFile("nbt.nbt")
file:open("r")
-- file is 227 bytes, 250 will read past EOF
for i=1, 250 do
byte, num = file:read(1) -- should return nil on EOF, and num should be 0
if not byte or num == 0 then
log:write("EOF\n")
os.exit()
else
log:write("b"..byte.."\n")
end
end
os.exit()
end