i am having a hard time trying to figure out what is wrong: i am supposed to read lines from a text file using lua, and print said lines who contain the strings "login" or "logout" - and if i reach the end of the file, to print ("reached end of file"). for some reason the first line (i think) is receiving a nil value, and therefore i am stuck.... i will mention i am running the lua code using cmd from the exact folder the script is written
lua code:
file = io.open("dummy_log.txt", "r")
line = file:read()
while true do
print("first line is: "..line)
if line == nil then
print("reached end of file")
break
else
if string.match(line, "login") then
print("reached login line: " .. line)
elseif string.match(line, "logout") then
print("reached logout line: " .. line)
end
end
line = file:read()
end
file:close()
log file:
13:20:20 [111] log-in
13:22:00 [111] deposit
13:22:01 [111] phone-call
13:50:50 [111] log-out
(is written in a text file).
help will be appreciated...