Plugins Lightroom插件Lua脚本中对话框和变量的奇怪行为

Plugins Lightroom插件Lua脚本中对话框和变量的奇怪行为,plugins,lua,dialog,lightroom,Plugins,Lua,Dialog,Lightroom,我正在用Lua语言编写Lightroom插件,使用Lightroom SDK/API。我是卢阿的新手。我发现只有在一个函数中存在Lightroom对话框(lDialogs.message(“random message”))的情况下,我的脚本才能工作。如果没有它,函数将在稍后的某一点失效,该点声明字符串变量(最后一个LrDialogs.message中的Image.dr)为“nil”,而不是插件正常工作时的正常值。有人知道怎么回事吗?以下是相关代码段: ------ read output fi

我正在用Lua语言编写Lightroom插件,使用Lightroom SDK/API。我是卢阿的新手。我发现只有在一个函数中存在Lightroom对话框(lDialogs.message(“random message”))的情况下,我的脚本才能工作。如果没有它,函数将在稍后的某一点失效,该点声明字符串变量(最后一个LrDialogs.message中的Image.dr)为“nil”,而不是插件正常工作时的正常值。有人知道怎么回事吗?以下是相关代码段:

------ read output file for exif and write to LR metadata ------
function parseOutput(outputFilePath)

    LrDialogs.message("random message")

    local tblOutput = {}    --to hold the output exif (1 column table, i.e. an array)
    local tblImages = {}    --to hold the images and their relevant metadata

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

    local str = table.remove(tblOutput) --remove last line in table/file (it's log info, not exif)
    tblImages = extractExif(tblOutput)  --pick out the exif key/value pairs and add to Image objects

end

function extractExif(tblOutput)
    local Image = {}    --pseudo object to hold metadata for each image
    local tblImages = {}
    local blnFlag = false
    local intCount = 0

    for k,v in pairs(tblOutput) do  --iterate through each value in the table
        if string.find(v, "^=.+") then
            --test if new image other than the first one
            if blnFlag == true then
                --add Image to tblImages and then clear Image object
                table.insert(tblImages, Image)
                --Image = {}    --don't technically need this
                blnFlag = false
                --LrDialogs.message("inside blnFlag test")
            end

            i, j = string.find(v, "/")  -- **** MAC ONLY. Back slash for Windows *****
            Image.filePath = string.sub(v, i)   --returns the file path
            Image.name = string.match(v, "([^/]+)$")    --return the file name
            blnFlag = true

        elseif string.find(v, "ISO") ~= nil then
            Image.iso = string.match(v, "%a+:(.+)") --get text (i.e value) to right of colon
        elseif string.find(v, "Film") ~= nil then
            Image.filmSim = string.match(v, "%a+:(.+)")
        elseif string.find(v, "Setting") ~= nil then
            Image.drMode = string.match(v, "%a+:(.+)")
        elseif (string.find(v, "Auto") ~= nil) or (string.find(v, "Development") ~= nil) then  
            Image.dr = string.match(v, "%a+:(.+)")
        else

        end
    end

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

    return tblImages
end

function removeWhitespaces(str)
    return string.gsub(str, "%s", "")
end

我只是想补充一点,因为我是Lua和Macs的noob,我不知道如何使用控制台记录调试输出。这就是为什么我要使用对话框。因为我很懒。我给自己准备了一个调试器IDE,如果没有包含第一个对话框,那么程序流永远不会进入io.lines(outputFilePath)中的
行,尽管outputFilePath中填充了正确的路径字符串。