It is currently April 19th, 2024, 3:35 am

[Fixed] Problem with returning Numbers formatted as strings.

Discuss the use of Lua in Script measures.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

[Fixed] Problem with returning Numbers formatted as strings.

Post by smurfier »

When returning numbers that have been formatted as strings, they are returned as numbers, sans format.

Code: Select all

PROPERTIES = {}
function Initialize()
Try = 1
end
function Update()
Try = string.format("%02d",Try)
return Try
end
This should return 01 but instead returns 1.
When using print() or !SetOption, 01 is returned just fine.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Problem with returning Numbers formatted as strings.

Post by poiru »

This is due to the nature of Lua as it is a dynamically typed language, which is why something like this will work:

Code: Select all

function Update()
	local ret = string.format("%02d", 1)
	ret = ret + 1
	return ret -- returns 2
end
Prior to r885, Rainmeter 'requested' a textual value and a numerical value. This, however, rendered NumOfDecimals, Scale, AutoScale, and Percentual useless when using MeasureName=ScriptMeasure on STRING meters as Rainmeter simply used whatever textual value Lua gave.

r855 and later request a numerical value first and, if it is not available, request a textual value. Because "02" and 2 are analogous in Lua, they both return true in the 'get numerical value' stage.

Fixing this would require reverting the pre-r885 behavior and thus break NumOfDecimals, Scale, etc. I will discuss this matter with the other devs.
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Problem with returning Numbers formatted as strings.

Post by poiru »

I made some changes for the next beta that should resolve things once and for all. return 1 is now treated differently from return "1" (and return "01", for the matter).

return 1 -> NumOfDecimals, Scale, etc. work.
return "1" -> NumOfDecimals, Scale, etc. do not work

This will care of your issue as well.
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Problem with returning Numbers formatted as strings.

Post by smurfier »

Thank you.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Problem with returning Numbers formatted as strings.

Post by jsmorley »

Here is a build with that fix for you to test Smurfie...

http://dl.dropbox.com/u/4991063/Rainmeter/Build/Rainmeter-2.1-r888-beta.exe
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Problem with returning Numbers formatted as strings.

Post by smurfier »

Works wonderfully.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .