Can luup.devices be accessed from a call_timer callback?

I’m new to lua and plugin programming, so I don’t know what scope various symbols have.

I have a function that gets called by call_timer that tries to access luup.devices. It tries to do a lookup into it used a device number. Since the same code works from the startup function, this leads me to believe that luup.devices is not in scope for my call_timer function.

Should I be able to access luup.devices from a function that is passed to call_timer()?

Does anyone have any good pointers to doc on how scope is handled in general in lua/luup?

Thank you

[quote=“Richard, post:1, topic:168727”]I have a function that gets called by call_timer that tries to access luup.devices. It tries to do a lookup into it used a device number. Since the same code works from the startup function, this leads me to believe that luup.devices is not in scope for my call_timer function.
Should I be able to access luup.devices from a function that is passed to call_timer()?[/quote]

Yes, you should. luup.* is accessible everywhere, in every piece of Lua code that Vera runs. So there’ll be a different reason for your code not working in the context of a call_timer().

Does anyone have any good pointers to doc on how scope is handled in general in lua/luup?

The definitive reference is the Lua manual (Lua 5.1 Reference Manual). Section 2.3 describes variables and scope:

Any variable is assumed to be global unless explicitly declared as a local (see §2.4.7). Local variables are lexically scoped: local variables can be freely accessed by functions defined inside their scope (see §2.6).

This is much the same rule as languages like JavaScript (“var foo;”) and Perl (“my $foo;”), if that helps.

In the context of LuaUPnP, “global” means “global within that plugin’s interpreter”. Each plugin gets its own Lua interpreter, so globals defined in one plugin’s implementation file don’t pollute others.