Lua脚本中对话框和变量的奇怪行为

我正在使用Lua语言编写Lightroom插件,使用Lightroom SDK/API。我对Lua还不熟悉。我发现一个情况,即我的脚本仅在一个Lightroom对话框(LrDialogs.message("random message"))存在于一个函数中时才能运行。如果没有这个函数,函数会在稍后的某个时间点失败,称一个字符串变量(Image.dr)为'nil',而不是插件正常工作时具有的常规值。有人知道出了什么问题吗?下面是相关的代码段:

---读取exif输出文件并将其写入LR元数据------
function parseOutput(outputFilePath)

    LrDialogs.message("随机消息")

    local tblOutput = {}    - -保持输出exif(1列表,即数组)
    local tblImages = {}    --保存图像及其相关元数据

    for line in io.lines(outputFilePath) do
        line = removeWhitespaces(line)
        table.insert(tblOutput, line)
    end

    local str = table.remove(tblOutput)--删除表/文件中的最后一行(它是日志信息,不是exif)
    tblImages = extractExif(tblOutput)--挑选exif键/值对并添加到图像对象中

end

function extractExif(tblOutput)
    local Image = {}    --伪对象,保存每个图像的元数据
    local tblImages = {}
    local blnFlag = false
    local intCount = 0

    for k,v in pairs(tblOutput)do --迭代表中的每个值
        if string.find(v,“^ =. +”) then
            --测试除第一个之外是否有新图像
            如果blnFlag == true then
                --将Image插入tblImages,然后清除Image对象
                table.insert(tblImages, Image)
                - -Image = {}---技术上不需要这个
                blnFlag = false
                - -LrDialogs.message("在blnFlag测试中"end

            i,j = string.find(v,“/”)-- **** MAC ONLY。 Windows用反斜杠*****
            Image.filePath = string.sub(v,i)-返回文件路径
            Image.name = string.match(v,"([^ /] + ) $"--返回文件名
            blnFlag = true

        elseif string.find(v,“ISO”)〜= nil then
            Image.iso = string.match(v,“%a + :( .+ )”)--获取文本(即值)在冒号右侧
        elseif string.find(v,“胶片”)〜= nil then
            Image.filmSim = string.match(v,“%a + :( .+ )”)
        elseif string.find(v,“设置”)〜= nil then
            Image.drMode = string.match(v,“%a + :( .+ )”)
        elseifstring.find(v,“Auto”)〜= nil)或(string.find(v,“Development”)〜= nilthen
            Image.dr = string.match(v,“%a + :( .+ )”)
        other

        end
    end

    LrDialogs.message(Image.name .. Image.iso .. Image.filmSim .. Image.drMode .. Image.dr)

    返回tblImages
end

function removeWhitespacesstrreturn string.gsubstr,“%s”,“”)
end

点赞