Variable visibility inside a LUA plugin function.
I am new to lua and am trying to create a plugin to assist my use of keywords in Lightroom Classic. I am creating my own UI for this tool and intend to include buttons to activate certain functions. However I am having problems getting a keyword variable to be visible inside a function attached as an action to a button. I can get a string variable passed in no problem, but not a keyword variable.
Here is the code, the variable KeywordIn is one of the top level kewwords in my catalog -
local function show_Dialog(KeywordIn)
local kw_In_Name = KeywordIn:getName()
outputToLog("in show_Dialog, input keyword - " .. kw_In_Name )
LrFunctionContext.callWithContext( "show_Dialog", function( context )
local props = LrBinding.makePropertyTable( context )
props.myObservedString = "Birds (Aves)"
local f = LrView.osFactory()
local staticTextValue = f:static_text {
title = props.myObservedString,
}
local updateField = f:edit_field {
immediate = true,
value = props.myObservedString -- "Birds (Aves)"
}
local c = f:column {
spacing = f:dialog_spacing(),
f:row {
f:static_text {
alignment = "right",
width = LrView.share "label_width",
title = "Class to be Searched: "
},
updateField,
f:push_button {
title = "Run",
-- When the 'Run' button is clicked.
action = function()
outputToLog( "Run button clicked." )
staticTextValue.text_color = LrColor ( 0, 0, 0)
props.myObservedString = updateField.value
local kwClassName = updateField.value
outputToLog("Data from Field - " .. kwClassName)
outputToLog("keyword Inputted, name passed as string - " .. kw_In_Name)
outputToLog("keyword Inputted, name from getName - " .. KeywordIn:getName() )
end
},
}, -- end of row
} -- end of column
LrDialogs.presentModalDialog {
title = "Trial Dialog",
contents = c
}
end)
end
When I run this plugin it works fine until I click on the run button. All works apart from the line outputting the keyword name using getName, which is not printed to the debug viewer.
Can anyone tell me what I am doing wrong please?
Pete Rowland
