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

时间:2017-06-12 08:23:30

标签: plugins lua dialog lightroom

我正在使用Lua语言中的Lightroom SDK / API编写Lightroom插件。我是Lua的新手。我发现一种情况,我的脚本只有在一个函数中存在Lightroom对话框(LrDialogs.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

0 个答案:

没有答案