Copy link to clipboard
Copied
I have a plugin that kicks off a long running task. The task, obviously, doesn't terminate when the plugin is reloaded and I'm left with a trail of processes. Someone has suggested that there's a _G[] table or similar that I can store persistent values outside of the plugin's scope in but I'm having trouble making that work. Is it a thing or have I misunderstood?
Each plugin has its own global Lua environment for storing global variables (those not declared via a "local" statement). All invocations of plugin scripts and background tasks execute within that environment, so if one script execution sets a global, that global's value will be seen by future script invocations and background tasks. That environment is re-initialized (and all existing global variables discarded) when the plugin is loaded or reloaded.
Lua has a special built-in global _G whos
...Copy link to clipboard
Copied
Each plugin has its own global Lua environment for storing global variables (those not declared via a "local" statement). All invocations of plugin scripts and background tasks execute within that environment, so if one script execution sets a global, that global's value will be seen by future script invocations and background tasks. That environment is re-initialized (and all existing global variables discarded) when the plugin is loaded or reloaded.
Lua has a special built-in global _G whose value is a table containing all global variables. So a script can reference either the global "x" or "_G.x" -- they refer to the same global variable.
To terminate a background a plugin's background task when the plugin is removed, reloaded, or disabled or when LR is shutdown, maintain a global "running". When true, the task continues to run, but when false, the task should exit. The task should test "running" periodically. Define scripts for the Info.lua's LrShutdownPlugin, LrDisablePlugin, and LrShutdownApp that set "running" to false.
Copy link to clipboard
Copied
Thanks John, that makes things much clearer
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more