[Solved] Plugin implementation file and scope of variables


something is not clear in the wiki : what is the scope of variables in implementation files ?
I’ve done some tests but there are still gray areas.

  • a global variable in implementation file is in fact local (a sort of plugin jail) ?
  • a global variable in implementation file is visible by all plugin implementations or each plugin has its own stack ?
    (ie, have to store specific data for the plugin implementation in a common table ?)


As far as I could figure out the variables visibility is limited to the plug in it self and its child devices. This one of the reasons why plugins like variable container are used. Second is that LUUP gets restarted fairly often (on nearly every configuration/scene/etc change) so the startup code gets executed again and all variables reset.

Not sure if startup LUA variables are an exception, but I would not rely on LUUP variables to hold any values other than for immediate use.

Cheers Rene

It’s simple …
Each PLUGIN instance has it’s own LUA namespace.
In that namespace standard LUA scopeing rules apply.

Scenes and Vera’s STARTUP LUA share the same LUA namespace … which is independent of ALL plugins.

So Scenes can’t interact with Plugins through LUA variables and functions and visa-versa.

All Namespaces have accesses to the LUA standard libraries and the luup.xxxx functions.


I thought that implementations of the same plugin share theirs variables and definitions.
So a big plugin reserves as many times memory that there are implementations ?

Thanks :slight_smile:

If you have a “Controlling Plugin” and “Controlled Devices” they share the same LUA namespace.

Much better said by the true expert ;D