It is currently April 24th, 2024, 9:53 am

[BUG] Formula Parser within Inline Lua

Report bugs with the Rainmeter application and suggest features.
User avatar
Brian
Developer
Posts: 2681
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: [BUG] Formula Parser within Inline Lua

Post by Brian »

I think this is just a documentation issue. I couldn't find anything in the code that suggests that function parameters evaluate formulas before sending things to lua.

Parameters are sent to lua based on a just of couple of criteria. If the first character is a quote (single or double), the parameter is sent as a string. If the parameter is true or false, the argument is as a boolean type. Everything else is assumed to be a number (without formulas).

We can look into adding a formula check before sending it to lua. In the meantime, you can use the ParseFormula function, and send the arguments as strings (in the skin file). This way, your script will work for any version of Rainmeter since r2851.

For example, in your skin use quotes around the arguments: Text="Test = [&Script:Sum('3','(3+7)')]"

Then in your script, call the ParseFormula function.

Code: Select all

function Sum(a, b)
  -- Note: ParseFormula wants a 'string' as its parameter
  local x = SKIN:ParseFormula(tostring(a))
  local y = SKIN:ParseFormula(tostring(b))
  local result = x + y
  return result
end
Note: The tostring function may seem redundant, but I added it in case the skin file forgets the quotes (although Lua/Rainmeter seems to be forgiving in some cases).


We will discuss adding a formula check or just changing the docs.

-Brian
User avatar
Yincognito
Rainmeter Sage
Posts: 7152
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG] Formula Parser within Inline Lua

Post by Yincognito »

Brian wrote: May 26th, 2021, 6:56 amI think this is just a documentation issue. I couldn't find anything in the code that suggests that function parameters evaluate formulas before sending things to lua.
[...]
We can look into adding a formula check before sending it to lua. In the meantime, you can use the ParseFormula function, and send the arguments as strings (in the skin file). This way, your script will work for any version of Rainmeter since r2851.
[...]
We will discuss adding a formula check or just changing the docs.

-Brian
Yeah, I looked over the Rainmeter code as well and didn't find formula evaluations before sending things to Lua either. :D

Good idea to use parse formula on string arguments, didn't think of it, probably because I already found a similar workaround of using a temporary variable to more or less do the same thing but in native Rainmeter, like mentioned above. Looking forward to see what you decide on the formula check - if that means parsing a formula (or even the argument itself, even if it's a string, see below) before sending it to Lua that would be great and hopefully (if the potential Rainmeter coding additions are easy enough) would help with other related problems as well like, say, using section/nested variables like [#CURRENTSECTION] in the arguments of an inline Lua function, which you admitted it couldn't be parsed in Lua using SKIN:ParseFomula(). Assuming, of course, that current section tracking (within Rainmeter) allows it, as you explained in another thread.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth