Posted 17 February 2012 - 05:37 AM
http://pastebin.com/rfejBmri
I'm probably f***ing up with io.open too much.
I'm probably f***ing up with io.open too much.
if io.open(shell.resolve(".") .. "coo.kie","r") ~= nil then
…try to assign it to a variable first and then check that variable instead, like e.g.:local hCookie = io.open(shell.resolve(".") .. "coo.kie","r")
if hCookie then
This will open the file "coo.kie" and assign its file-handle/-reference to the variable hCookie.local cookieContent = hCookie:read("*all")
Once you've read the content from the file you can't read it again, at least not with the same handle.myfile:read("*all")
Then you've read the file (of handle "myfile") already and can't read it again.
local hFile -- Handle, that will hold the reference to the opened file.
local fileContent -- We will read the whole file in one go into this variable.
hFile = io.open("somefile", "r") -- Load the file for reading.
fileContent = hFile:read("*all") -- Read the whole file into 'fileContent'
hFile:close() -- We have read the whole file into 'fileContent', so we do not need the file handle anymore.
-- From now on we will continue to work with the data in 'fileContent'
local hFile = io.open("somefile", "r")
while true do
local line = io.read()
if line == nil then break end -- If the last line read is nil, then we have reached the end of the file and this break out of the loop.
-- Do something with the line here.
end