It is currently July 23rd, 2024, 2:39 am

Is there a way to obtain a variable value fully parsed?

Discuss the use of Lua in Script measures.
Crest
Posts: 148
Joined: August 16th, 2013, 12:47 pm

Is there a way to obtain a variable value fully parsed?

Post by Crest »

Let's say we have a variable SomeVar which has a value of `[&Script:Manip('#Foo#')],(50+10)`. For the sake of this example let's say the `Manip` function returned a color value and the latter was an alpha value.

If one uses say `[LeftMouseDownAction=[&Script:Func('SomeVar')]` one can then within the Lua use `SKIN:GetVariable(var)` to obtain the variable value.

This will output the raw unparsed variable value. So if the variable itself contains script functions those will be reproduced verbatim in the returned value. The upside is the script gets passed the variable name name so it can use that for lookups.

OTOH one can use the `#SomeVar#` syntax to pass to the script instead, which will return a semi-parsed value instead of the variable name itself. Following the example let's say it returned `200,200,200,(50+10)`. The script part gets parsed but the formula part is left as-is.

Alternatively if a meter happens to have just the desired value for one of its options one can pass the meter name and option name to the script and then use (eg) `myMeter = SKIN:GetMeter(name)` and then `myMeter:GetOption(option)` to obtain the parsed version of the option value. However (at least for FontColor which I tested) oddly this doesn't return the formula part ime, so following the example this only returns `200,200,200` and the alpha isn't returned (in any form), despite the actual rendered value having alpha in Rainmeter.

Is there any way to pass to or obtain via Lua a fully parsed variable value with formulas parsed as well? Or is some internal order of execution preventing that?
Last edited by Crest on May 21st, 2024, 5:59 am, edited 1 time in total.
User avatar
Brian
Developer
Posts: 2713
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Is there a way to obtain a variable value fully parsed?

Post by Brian »

You could use the ReplaceVariables function.
https://docs.rainmeter.net/manual/lua-scripting/#ReplaceVariables

It should replace any section variables and custom functions.

You may have to also use ParseFormula as well.

-Brian
Crest
Posts: 148
Joined: August 16th, 2013, 12:47 pm

Re: Is there a way to obtain a variable value fully parsed?

Post by Crest »

Thanks! Simple enough to determine by index from delimiter which part to use ParseFormula with.