It is currently November 15th, 2018, 3:36 pm

[Oops, not a bug...] Variables do not resolve through inline LUA

Report bugs with the Rainmeter application and suggest features.
User avatar
raiguard
Posts: 474
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

[Oops, not a bug...] Variables do not resolve through inline LUA

raiguard » October 5th, 2017, 2:02 am

When experimenting with Inline LUA, I discovered that returning a variable (whether it be the #old# syntax or the [#new] syntax) through inline LUA does not resolve. See this example skin and script, and the attached image:

LuaVariables.ini

Code: Select all

[Rainmeter]
AccurateText=1
MiddleMouseUpAction=[!Refresh]

[Variables]
arrowImg=#@#Images\arrow-up.png

[MeasureScript]
Measure=Script
ScriptFile=#@#Scripts\LuaVariables.lua

[MeterBackground]
Meter=Shape
Shape=Rectangle 0,0,82,30 | Fill Color 15,15,15 | StrokeWidth 0

[MeterArrowControl]
Meter=Image
ImageName=#arrowImg#
X=5
Y=5
W=20
H=20

[MeterArrowImg]
Meter=Image
ImageName=[MeasureScript:GetIcon()]
X=30
Y=5
W=20
H=20
DynamicVariables=1

[MeterArrowAlt]
Meter=Image
ImageName=[MeasureScript:GetIconAlt()]
X=55
Y=5
W=20
H=20
DynamicVariables=1
LuaVariables.lua

Code: Select all

function Initialize() end

function Update() end

function GetIcon()

	return '#arrowImg#'

end

function GetIconAlt()

	return tostring(SKIN:GetVariable('arrowImg'))

end
2017-10-04 19_58_27-.png
In this skin, there should be three arrows lined up in a row. However, the second one does not show up, because the image meter throws the following error: Unable to open:D:\Files\Settings\Caleb\Rainmeter\Skins\Testing\@Resources\Images\#arrowImg#.png. The short of it is that when an inline LUA function returns a Rainmeter-formatted variable (without using SKIN:GetVariable()), it does not resolve before attempting to execute.

For convenience, here is the arrow image I was using:
You do not have the required permissions to view the files attached to this post.
Last edited by raiguard on October 5th, 2017, 4:59 am, edited 1 time in total.
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
Brian
Developer
Posts: 1789
Joined: November 24th, 2011, 1:42 am
Location: Ohio

Re: [Bug] Variables do not resolve through inline LUA

Brian » October 5th, 2017, 3:43 am

Interesting use case.

The problem here is the 'order' in which variables are replaced when parsing an option. Regular #variables# are parsed before section [variables]. So, returning a regular #variable# from a section [variable] won't work.

What you need to do is use the nesting syntax in both places, like this:
ini:

Code: Select all

[MeterArrowImg]
Meter=Image
ImageName=[&MeasureScript:GetIcon()]
X=30
Y=5
W=20
H=20
DynamicVariables=1
lua:

Code: Select all

function GetIcon()

   return '[#arrowImg]'

end
This works because you are essentially nesting the value of the section variable with that of a regular variable.

-Brian
User avatar
raiguard
Posts: 474
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: [Bug] Variables do not resolve through inline LUA

raiguard » October 5th, 2017, 3:59 am

Brian wrote:Interesting use case.

The problem here is the 'order' in which variables are replaced when parsing an option. Regular #variables# are parsed before section [variables]. So, returning a regular #variable# from a section [variable] won't work.

What you need to do is use the nesting syntax in both places, like this:
ini:

Code: Select all

[MeterArrowImg]
Meter=Image
ImageName=[&MeasureScript:GetIcon()]
X=30
Y=5
W=20
H=20
DynamicVariables=1
lua:

Code: Select all

function GetIcon()

   return '[#arrowImg]'

end
This works because you are essentially nesting the value of the section variable with that of a regular variable.

-Brian
Actually, I had already tried that, and it doesn't work. It comes up with the same error. I should have included a nested syntax example with the skin I provided.
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
raiguard
Posts: 474
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: [Bug] Variables do not resolve through inline LUA

raiguard » October 5th, 2017, 4:02 am

AH. *facepalm*

It's because I didn't use the nested section variables syntax. My bad. There is no bug. :oops:
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
raiguard
Posts: 474
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: [Bug] Variables do not resolve through inline LUA

raiguard » October 5th, 2017, 4:57 am

Perhaps you could help me a bit with a problem related to the implementation of this. Attached is an example skin.
2017-10-04 22_51_08-.png
I am creating a toggle button that will load/unload another skin. I am attempting to implement it so the skin does not need to refresh whenever the toggle is clicked. But there is a problem with the toggle meter:

Code: Select all

[MeterSkinToggle]
Meter=Image
ImageName=[&MeasureScript:GetIcon([#toggledSkinLoaded])]
X=5R
Y=-2r
W=31
H=20
DynamicVariables=1
LeftMouseUpAction=[!CommandMeasure MeasureScript "ToggleSkin([#toggledSkinLoaded], 'ToggledSkin')"]
Group=SkinToggles
For some reason, the [#toggledSkinLoaded] variable in the ImageName will dynamically update, but the variable in the !CommandMeasure will not, requiring a refresh before the button will work again. I've been scratching my head about this for the better part of a day. Did I miss something important?
You do not have the required permissions to view the files attached to this post.
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
Brian
Developer
Posts: 1789
Joined: November 24th, 2011, 1:42 am
Location: Ohio

Re: [Oops, not a bug...] Variables do not resolve through inline LUA

Brian » October 5th, 2017, 5:25 am

I think the problem isn't the use of variables, but when you call the 'ReadIni' function.

You call it in Initialize, but no where else. So it's filling your table once when the skin is loaded or refreshed and not looking in the settings file again.

Try placing the 'ReadIni' call in your ToggleSkin function.

-Brian

PS - Look at using the !ToggleConfig bang.
User avatar
raiguard
Posts: 474
Joined: June 25th, 2015, 7:02 pm
Location: The Sky, USA

Re: [Oops, not a bug...] Variables do not resolve through inline LUA

raiguard » October 5th, 2017, 5:34 am

Brian wrote:I think the problem isn't the use of variables, but when you call the 'ReadIni' function.

You call it in Initialize, but no where else. So it's filling your table once when the skin is loaded or refreshed and not looking in the settings file again.

Try placing the 'ReadIni' call in your ToggleSkin function.

-Brian

PS - Look at using the !ToggleConfig bang.
I knew it was something simple... I intended to reference the state argument there, not the ini table. I guess I was so convinced it was the variable being problematic that I didn’t properly look over the script.

Thanks for the help.

Edit: Wait, !ToggleConfig is a thing? WHY DIDN’T I KNOW ABOUT THIS!?
”We are pretty sure that r2922 resolves the regression in resolution caused by a reversion to a revision.” - jsmorley, 2017
User avatar
Brian
Developer
Posts: 1789
Joined: November 24th, 2011, 1:42 am
Location: Ohio

Re: [Oops, not a bug...] Variables do not resolve through inline LUA

Brian » October 5th, 2017, 5:35 am

Glad to help!

-Brian