0

I'm writing a Lightroom plugin using the Lightroom SDK/API in the Lua language. I'm new to Lua. I've found a situation where my script only works if a Lightroom dialog box (LrDialogs.message("random message")) is present in one function. Without it the function falls over at a later point claiming a string variable (Image.dr in the last LrDialogs.message) is 'nil' as opposed to the normal value it has when the plugin is working properly. Anyone know what's going wrong? Here's the relevant code segment:

------ 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
4

0 回答 0