vakot wrote: ↑February 6th, 2024, 2:34 pm
[#CurrentSection#Measure] is a good solution, but it's not exactly what i want to have.
As promised, here is the Lua alternative...
...\@Resources\Script.lua:
Code: Select all
function OptionValue(section, option)
return ((SKIN:GetMeasure(section) or SKIN:GetMeter(section)) and (SKIN:GetMeasure(section) or SKIN:GetMeter(section)):GetOption(option) or '')
end
...\Skin.ini:
Code: Select all
[Variables]
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=47,47,47,255
---Measures---
[Script]
Measure=Script
ScriptFile=#@#Script.lua
UpdateDivider=-1
[Number]
Measure=Calc
Formula=(7+3)
UpdateDivider=-1
DynamicVariables=1
---Meters---
[Result]
Meter=String
FontColor=255,255,255,255
FontFace=Consolas
FontSize=16
Padding=5,5,5,5
AntiAlias=1
MeasureName=Number
Text=Measure Name (literal) = [&Script:OptionValue('[#CURRENTSECTION]','MeasureName')]#CRLF#Measure Value (number) = [[&Script:OptionValue('[#CURRENTSECTION]','MeasureName')]:]
UpdateDivider=-1
DynamicVariables=1
Details in the two links I posted above. The "A and B or C" construct in Lua is equivalent to a
numerical conditional in plain Rainmeter and basically means "if A is true, then return B, else return C". The "A or B" construct in Lua basically means "if A is valid, then return A, else return B" (where valid might mean that it exists and it's not nil, for example). Notice how the round brackets are placed, to understand the order of these tests. Obviously, the function's contents can also be written using plain
"if ... then ... else ... end" statements (equivalent implementation in the spoiler below), it's just that I like compact one-liners so I used the logical operators instead for this error handling system.
P.S. The return value of the function is a string (similar to how #CURRENTSECTION# works), so its parsing can be then adjusted as desired in plain Rainmeter, ensuring maximum flexibility. Because of that, no variable replacing or formula parsing was done in Lua. Also, I used the
nested syntax for CURRENTSECTION in the inline Lua because of
this.
EDIT: Adjusted the alternative in the spoiler to use "sectionhandle" as a local variable in that function, instead of a global one like it was in the original version. A minor omission due to successive editing of the .lua file.