death.crafter wrote: ↑May 25th, 2021, 3:03 pm
I don't think the fault is in Rainmeter at all. Input text being a C++ plugin(most probably) it returns a string value. So it can not directly be added to an integer. So if you try it even without lua for example Command1=[!Log "$UserInput$+3"], it would log "20+3" as a string. You get the gist.
Well, being a fault or not and its location depends, in this case. You're right that the InputText measure's return value is a string ... BUT the formula parser in Rainmeter (which is triggered by encountering the "(" character in most options and bangs - that's why you have to always enclose formulas between round brackets in Rainmeter in the first place) automatically converts a numerical string into the corresponding number in the appropriate moment (i.e. at usage), as long as it's a part of a valid
(formula
). Try for example,
Command1=[!SetVariable Sum "(20+3)"][!Log "[#Sum]"],
Command1=[!SetVariable Sum ("20"+3)][!Log "[#Sum]"] or even (similar to what I mentioned already above)
[!SetVariable Sum ($UserInput$+3)][!Log "[#Sum]"] and you'll get
23 in all cases - sure, it's not that directly done, but strings are being used. Similarly, you can even use a string in the Formula option of a Calc measure and, as long as that string is a valid
(formula
), the measure will yield the actual result.
The question here is more or less of
what operations are going on and their
order. If the formula parser would happen
before the Lua parsing in the inline Lua (it doesn't seem the case, I'm not even sure it happens in the first place for the arguments of an inline Lua function, maybe because inline Lua is basically a section variable and not a bang), then
[&SomeLuaScript:SomeLuaFunction(3,($UserInput$-[#SomeOtherVariable]),5)] will be parsed as
[&SomeLuaScript:SomeLuaFunction(3,TheSaidOperationResult,5)], where
TheSaidOperationResult is the numerical result of the operation. If the formula parser doesn't happen or it happens
after the Lua parsing in the inline Lua, then obviously it would explain the behavior and why the stringified formula is passed as the argument instead of its result.
Another proof that this isn't related to the fact that string values are used - I just tried
[&SomeLuaScript:SomeLuaFunction(3,(3+7),5)] and got nothing. This means that Rainmeter doesn't convert the
(3+7) formula (no strings involved this time, right?) to
10 beforehand, in order to pass the result as the 2nd argument to the aforementioned SomeLuaFunction. I'm just trying to understand if this is normal / expected or not.
And some excerpt from the
manual:
The types of parameters that can be passed to the Lua function() are:
Number Any number literal, formula or variable that resolves to a number.
String Any 'string' literal, or variable that resolves to a string, enclosed in 'single quotes'.
Boolean One of either true or false.
The above (3+7) for example, fits right into the 1st category in the list, i.e. "any number literal,
formula or variable that resolves to a number".