1

我正在编写一个脚本,以便在使用 MPV 时在每个视频的 .txt 中添加一行。

但是,我在第 68 行的 for 循环中遇到了一个奇怪的错误。它只是告诉我:没有错误。如果我向 file:write(message, error) 添加错误参数,它会给我另一条错误消息,说明:bad argument #2 to 'write' (string expected, got function). 任何帮助,将不胜感激。

function on_file_end(event)
    if not paused then totaltime = totaltime + os.clock() - lasttime end
    local message = (totaltime .. "s, " .. timeloaded .. ", " .. filename)
    local lines = {}
    local file = io.open(logpath, "r+")
    if file_exists(logpath) then
        for l in file:lines() do 
            if not l:find(message, 1, true) then
                lines[#lines+1] = 1
                file:write(message)
            end
        end
        file:close()
    end
end
4

1 回答 1

1

'write' 的错误参数 #2(需要字符串,得到函数)

error不是“错误参数”,它是一个全局函数,允许在 Lua 中引发您自己的错误。

https://www.lua.org/manual/5.4/manual.html#pdf-error

于 2022-02-09T12:18:54.057 回答