[icinga-users] var and locals keywords
Kai.Nothdurft at Rantzau.de
Thu Nov 23 16:14:06 CET 2017
>>> On 23.11.2017 at 13:31, Tobias Koeck <tobias.koeck at gmail.com> wrote:
> just checked it out. It's possible to create a local variable with
> locals.temp = a * b
> instead of
> var temp = a * b.
great, that you shared your test-results. Thanks.
> The usage of the keywords locals, this and globals aren't necessary just
> for readability. As far as I have read there is a priority from locals to
> this to globals variables. If you just write
> 'something ...' = temp
> it will check out the different scopes and gets the first that fits.
That's correct. You know it, Icinga2 knows it. Some other girl/guy, reading your config may not know it. So even when accessing a local variable, it may be good practice, to prepend it with "locals." when you have variables with the same name in different scopes. With "just for readability" I only meant your special case of using "locals" for a local variable.
> With the keyword you can force Icinga 2 to take a specific scope variable.
Jepp. Again, if you have a variable with the same name in global- and in local-scope, you have to prepend it with "globals.", to acces the one in the global-space. You dont' have to use "locals." to access the one in the local scope, but you CAN if you whish.
Hope I clarified it a little.
More information about the icinga-users