【发布时间】:2020-03-06 08:48:54
【问题描述】:
我很难找出问题所在: 我应该使用lua从文本文件中读取行,并打印包含字符串“login”或“logout”的行 - 如果我到达文件末尾,则打印(“到达文件末尾”)。 出于某种原因,第一行(我认为)正在接收 nil 值,因此我被卡住了.... 我会提到我正在使用 cmd 从编写脚本的确切文件夹中运行 lua 代码
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).
我们将不胜感激...
【问题讨论】:
标签: lua