Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

global variables and ending long running tasks

Engaged ,
Nov 12, 2025 Nov 12, 2025

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?

 

 

TOPICS
SDK
94
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 12, 2025 Nov 12, 2025

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

...
Translate
LEGEND ,
Nov 12, 2025 Nov 12, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 12, 2025 Nov 12, 2025
LATEST

Thanks John, that makes things much clearer

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines