我正在记录我通过 MPV 播放的视频文件,并且在使用 io 时我希望它为每个视频创建一行。使用初始选项它会删除它,并且在转到下一个视频时,默认情况下它不会添加新行。
我认为脚本应该接近工作。但是,这个问题挡住了我的路:“'(for generator)' 的错误参数 #1(无效选项)。显然,for 循环有问题,但我无法查明它,希望能有双手解决这个问题,因为我还在学习lua。
这是到目前为止的代码:
if not paused then totaltime = totaltime + os.clock() - lasttime end
message = (totaltime .. "s, " .. timeloaded .. ", " .. filename)
local file = io.open(logpath, "r+")
local lines = {}
if file_exists(logpath) then
for l in file:lines('L') do
if not l:find(message, 1, true) then
lines[#lines+1] = 1
file.write(message)
file:close()
end
end
end
end