Copy link to clipboard
Copied
I'm writing a LR Plugin that accesses proprietary fuji exif using exiftool. I have successfully read the metadata and saved it into appropriate variables. I'm now trying to write it to the custom metadata fields my plugin has defined and created. It's not working, though. Here's the function to write the metadata. It is called from within a LrTasks.startAsyncTask() function.
------- Write the relevant fuji exif to LR metadata -----------
function writeMetadata(objCat, tblImagesExif)
local arrPhotos = {} --array to hold LR photo objects
--get image list as an array of LR photo objects
arrPhotos = objCat:getMultipleSelectedOrAllPhotos()
str = objCat:withPrivateWriteAccessDo(
function(context)
for k,v in pairs(arrPhotos) do
for i,image in pairs(tblImagesExif) do
if image.filePath == v:getRawMetadata("path") then
if image.ISO ~= nil then
v:setPropertyForPlugin(_PLUGIN, "ISO", image.ISO)
end
if image.drMode ~= nil then
v:setPropertyForPlugin(_PLUGIN, "DR_Mode", image.drMode)
end
if image.dr ~= nil then
v:setPropertyForPlugin(_PLUGIN, "DR", image.dr)
end
if image.filmSim ~= nil then
v:setPropertyForPlugin(_PLUGIN, "FilmSimulation", image.filmSim)
end
break --break out of the for loop as a match has been found
end --end if
end --end for
end --end for
end --end function
)
LrDialogs.message(str)
end
Some notes - objCat and tblImagesExif are populated with the correct values, and objCat:getMultipleSelectedOrAllPhotos() returns a valid list of photos. I've put debugging break points in at
str = objCat:withPrivateWriteAccessDo(
and
function(context)
It stops at the first one twice (str=nil and then str="executed") and never stops at the second one.
Any ideas?
Copy link to clipboard
Copied
I don't see anything obviously wrong. But when you say you set a breakpoint at "function(context)" and it never stops there, that's because Lau doesn't recognize that line as "executable". Lua's debugging hook doesn't make it easier for a debugger like ZeroBrane to recognize which lines are executable and which aren't, so ZeroBrane lets you set a breakpoint there but it will never be taken. Set a break on the following line.
Copy link to clipboard
Copied
Sorry, I should have added that I set breakpoints inside each block of the function(context). It didn't stop at any of them.
Copy link to clipboard
Copied
To get breaks and stepping to work in the callback function of withPrivateWriteAccessDo(), you have to add a call to LrMobdebug.on() at the beginning of the function. In general, you need to do so for any callback function passed to the SDK API. If you don't, then breaks and stepping may not work in that function.
The reason is that under the covers, there are a number of APIs where LR executes the callback in a new task (a "coroutine" in standard Lua terminology). The debugging features have to be enabled in every task you want to debug. (This is a limitation of the core Lua debugging hooks provided by LR.)
Copy link to clipboard
Copied
Thanks John, that got the debugging going inside the callback function. So now the first 'if' in that function never evaluates as true, and the debugging watch for 'v:getRawMetadata("path")' shows the following error:
Yielding is not allowed within a C or metamethod call
Any ideas?
Copy link to clipboard
Copied
Yielding is not allowed within a C or metamethod call
This error occurs when the plugin calls an API method that must be executed within an asynchronous task (not the main task). I think you're getting this error on the debugging watch because ZeroBrane is executing getRawMetadata() within the main task, not an asynchronous task. (ZeroBrane isn't aware of such LR-specific constraints.)
I think if you want to monitor that, you'll have to first assign the expression to a local variable, and then watch the variable, forcing getRawMetadata() to executed in the current async task.
Copy link to clipboard
Copied
Thanks John. That got the debugger working in that block.