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

Report bugs with the Rainmeter application and suggest features.
User avatar

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

October 5th, 2017, 2:02 am
raiguard
   [234 posts]

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:
Attachments
arrow-up.png
Last edited by raiguard on October 5th, 2017, 4:59 am, edited 1 time in total.
User avatar

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

October 5th, 2017, 3:43 am
Brian
Developer   [1591 posts]

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

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

October 5th, 2017, 3:59 am
raiguard
   [234 posts]

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.
User avatar

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

October 5th, 2017, 4:02 am
raiguard
   [234 posts]

AH. *facepalm*

It's because I didn't use the nested section variables syntax. My bad. There is no bug. :oops:
User avatar

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

October 5th, 2017, 4:57 am
raiguard
   [234 posts]

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?
Attachments
SkinToggleTesting_1.0.0.rmskin
(9.43 KiB) Downloaded 5 times
User avatar

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

October 5th, 2017, 5:25 am
Brian
Developer   [1591 posts]

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

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

October 5th, 2017, 5:34 am
raiguard
   [234 posts]

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!?
User avatar

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

October 5th, 2017, 5:35 am
Brian
Developer   [1591 posts]

Glad to help!

-Brian

Return to “Bugs & Feature Suggestions”



Who is online

Users browsing this forum: No registered users and 3 guests