It is currently March 29th, 2024, 3:00 pm

Questions About Calc Measure

Get help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Questions About Calc Measure

Post by jsmorley »

Sometimes the gigantic amount of effort and complicated code that is used to avoid one line of Lua is just ... well, to each his own.

I think Inline Lua is one of the better things we ever implemented, and I love it.
User avatar
Yincognito
Rainmeter Sage
Posts: 7031
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Questions About Calc Measure

Post by Yincognito »

jsmorley wrote: March 5th, 2020, 1:23 pm Sometimes the gigantic amount of effort and complicated code that is used to avoid one line of Lua is just ... well, to each his own.

I think Inline Lua is one of the better things we ever implemented, and I love it.
Well, you know my opinion about this: if it's possible in Rainmeter proper, then make it possible. I would have turned to Lua only if this wasn't possible in Rainmeter proper. It wasn't a "gigantic amount of effort" or "complicated code" in this case, but it may very well be if the process of conversion itself is complicated in the case of negative numbers. In other words, it's the process that can be complicated, the complexity of the code is a consequence of the process' complexity.

And yes, as we already discussed, Lua scripts are an excellent addition to Rainmeter ... for things you can't do in Rainmeter proper. This isn't one of them, in my view.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Questions About Calc Measure

Post by jsmorley »

In my view, The Lua Script measure is just as "proper Rainmeter" as any other measure. Creating and using the external .lua file is no more complicated than creating a .inc file, and I'm sorry, but having a complicated and tortuous Substitute or a boatload of Calc or String measures simply to avoid Lua makes no sense at all to me. I see NO advantage whatsoever, other than some weird "Sure, it's hideous and impossible for the average user to understand, but at least I didn't have to use Lua!" thinking...

Again, to each his own.
User avatar
Yincognito
Rainmeter Sage
Posts: 7031
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Questions About Calc Measure

Post by Yincognito »

jsmorley wrote: March 5th, 2020, 1:46 pm In my view, The Lua Script measure is just as "proper Rainmeter" as any other measure. Creating and using the external .lua file is no more complicated than creating a .inc file, and I'm sorry, but having a complicated and tortuous Substitute or a boatload of Calc or String measures simply to avoid Lua makes no sense at all to me. I see NO advantage whatsoever, other than some weird "Sure, it's hideous and impossible for the average user to understand, but at least I didn't have to use Lua!" thinking...

Again, to each his own.
You see, there's another, personal reason for this. If I had always chosen the easiest path (or given up at the slightest sign of "difficulty") in my attempts, I would have never become a decent programmer - and you or Brian wouldn't have either (this can be extended for the "code" in Rainmeter). One can never learn to do 17+18 if he turns to a calculator (or smartphone, in recent days) each time he has to compute something. Sure, one has to know when to choose the easier path, as trying "the hard way" all the time can become pretty stupid if abused, on that we agree, but I am not one exclude easy avenues all the times - just when I think it's reasonable.

Other than that, I'm totally fine with my methods being considered "weird" and "hideous", LOL. What I can't stand is for them to be considered "average" / "lame" / "ineffective" (or worse, if you know what I mean). That being said, I doubt using a single Calc measure and a single string variable is "hideous and impossible for the average user to understand" in this case, just because there are these lovely Lua scripts that give you everything on a plate - people can understand far more complicated things than this little 10 lines measure... ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Questions About Calc Measure

Post by jsmorley »

Sorry, but I just love the beauty and simplicity of something like:

Code: Select all

function AddSuffix(num)

	local n = num % 10

	if (num - n) == 10 then
		suffix = 'th'
	else
		suffix = (n == 1 and 'st' or n == 2 and 'nd' or n == 3 and 'rd' or 'th')
	end

	return suffix
end
To turn 1 into 1st and 23 into 23rd. The power of actual procedural programming, with If/Then/Else and For/Next and all that, along with the fact that this is then turned into a reusable "function" by Inline Lua, so it can be written once, and called for any and every number you like, makes this very appealing to me.


1.jpg


Text=%1[&LuaHost:AddSuffix([&MeasureDayNoZero])]

Can I do this just using Rainmeter measures and options? Probably. Would I? Not really.

In general, I'm not sure I really like "reinventing the wheel" all that much. Converting decimal to hex falls in this category for me. There is a simple, baked-in mathematical function in Lua that does this for you.


Here is another example...


2.jpg


Getting that "number of minutes old" information from the timestamps embedded in the feed can be done with a handful of Time and Calc and Uptime measures in Rainmeter, but then it has to be replicated for every "item" in the feed, over and over. I prefer to just write the code in Lua one time, and call it where needed.

Anyway, not to belabor the point. As I said, to each his own. There is almost always more than one way to do things in Rainmeter. I just get excited about Inline Lua, as it is just so useful and cool...
You do not have the required permissions to view the files attached to this post.
User avatar
Yincognito
Rainmeter Sage
Posts: 7031
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Questions About Calc Measure

Post by Yincognito »

jsmorley wrote: March 5th, 2020, 2:35 pm Sorry, but I just love the beauty and simplicity of something like [...] The power of actual procedural programming, with If/Then/Else and For/Next and all that, along with the fact that this is then turned into a reusable "function" by Inline Lua, so it can be written once, and called for any and every number you like, makes this very appealing to me.
I'm the first to appreciate the power of procedural programming and the fact that one can reuse code. But yeah, I am an "all or nothing" guy: I either like to do it all in Rainmeter, or do it all in Lua (in these "simple" cases) - and since I already do most of it in Rainmeter code, Lua gets ignored. Let's say that this is actually something one can criticize about my approach: that I tend to not mix one with the other - and I would agree on it. Sometimes mixing them is very useful, but I would rather do it only in (very) complex scenarios, where there aren't alternatives. By the way, a small question, out of curiosity: isn't there any "lag drawback" in using Lua at all? Since, you know, different (script) file on disk, (probably) different DLL library(es) called, etc...
P.S. The example you used to emphasise your point here was a bit poorly chosen, as this (i.e. 1st, 2nd, 3rd, 4th, ...) could have been done easily in a very short regex substitute. I did get what you meant though, so no worries.
jsmorley wrote: March 5th, 2020, 2:35 pmIn general, I'm not sure I really like "reinventing the wheel" all that much. Converting decimal to hex falls in this category for me. There is a simple, baked-in mathematical function in Lua that does this for you.
You're probably right on this one, yeah. Look, I didn't post my sample to force others to do the same or to stricly "reinvent the wheel" - I just wanted to improve mak_kawa's approach, and prove that you can do it as simple in Rainmeter code as it was in Lua (i.e. single measure/variable/instruction). I didn't mean to say "ditch Lua and use my Rainmeter code method". "The more the merrier", I believe you once said regarding multiple alternative ways of doing something - and this was exactly that (not to mention extremely short)... :D
jsmorley wrote: March 5th, 2020, 2:35 pmGetting that "number of minutes old" information from the timestamps embedded in the feed can be done with a handful of Time and Calc and Uptime measures in Rainmeter, but then it has to be replicated for every "item" in the feed, over and over. I prefer to just write the code in Lua one time, and call it where needed.
Indeed, that's something Lua is definitely superior to Rainmeter code. The latter requires you to replicate measures and stuff, the former doesn't. Although, if you permit (yeah, I know, not again :rofl: ), you don't necessarily have to replicate measures to do the above: you can reuse 3 (more or less) Time/Calc/Uptime measures for every item in the feed, if you dynamically !SetOption on them, for example. I successfully used this method to turn skins with hundreds of (replicating) measures into ones with just a few dozens. I do agree with you that using Lua instead is much simpler though - the only small note I would add is "...because simplifying things in Rainmeter code wasn't even attempted". ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Questions About Calc Measure

Post by balala »

jsmorley wrote: March 5th, 2020, 2:35 pm Sorry, but I just love the beauty and simplicity of something like:

Code: Select all

function AddSuffix(num)

	local n = num % 10

	if (num - n) == 10 then
		suffix = 'th'
	else
		suffix = (n == 1 and 'st' or n == 2 and 'nd' or n == 3 and 'rd' or 'th')
	end

	return suffix
end
To turn 1 into 1st and 23 into 23rd. The power of actual procedural programming, with If/Then/Else and For/Next and all that, along with the fact that this is then turned into a reusable "function" by Inline Lua, so it can be written once, and called for any and every number you like, makes this very appealing to me.



1.jpg



Text=%1[&LuaHost:AddSuffix([&MeasureDayNoZero])]

Can I do this just using Rainmeter measures and options? Probably. Would I? Not really.
For sure in many cases using a lua script is far more easier than achieving the same result through Rainmeter code, however I'm not sure in this case this is true. For instance the above thing, using just native Rainmeter code can be easily done with simple substitution:

Code: Select all

[MeasureCount]
Measure=Calc
Formula=( MeasureCount + 1 )
RegExpSubstitute=1
Substitute="^(1)$":"\1st","^(2)$":"\1nd","^(3)$":"\1rd","^(\d{1})$":"\1th","^(1.)$":"\1th","^(\d{1,}1)$":"\1st","^(\d{1,}2)$":"\1nd","^(\d{1,}3)$":"\1rd","^(\d{1,}4|\d{1,}5|\d{1,}6|\d{1,}7|\d{1,}8|\d{1,}9|\d{1,}0)$":"\1th"
In my opinion, this, in this case, is much more easy then using a .lua script.
But as said :
jsmorley wrote: March 5th, 2020, 1:23 pm to each his own.
User avatar
Yincognito
Rainmeter Sage
Posts: 7031
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Questions About Calc Measure

Post by Yincognito »

balala wrote: March 5th, 2020, 8:22 pm

Code: Select all

[MeasureCount]
Measure=Calc
Formula=( MeasureCount + 1 )
RegExpSubstitute=1
Substitute="^(1)$":"\1st","^(2)$":"\1nd","^(3)$":"\1rd","^(\d{1})$":"\1th","^(1.)$":"\1th","^(\d{1,}1)$":"\1st","^(\d{1,}2)$":"\1nd","^(\d{1,}3)$":"\1rd","^(\d{1,}4|\d{1,}5|\d{1,}6|\d{1,}7|\d{1,}8|\d{1,}9|\d{1,}0)$":"\1th"
Actually, it can be even shorter/simpler, like

Code: Select all

Substitute="^(\d+)$":"\1th","1th$":"1st","2th$":"2nd","3th$":"3rd","^(\d*1[1-3])(?:st|nd|rd)$":"\1th"
(5 subs) - the range class in regex helps you avoid long alternation groups. By the way, in your sample 111 becomes 111st, which is incorrect, as it's 111th (one hundred and eleventh), same for numbers ending in 12 or 13.

P.S. Also, turning this into a reusable "function" that can be written once, and called for any and every number you like, can be simulated by creating an entry in the [Variables] section, like AddSuffix="^(\d+)$":"\1th","1th$":"1st","2th$":"2nd","3th$":"3rd","^(\d*1[1-3])(?:st|nd|rd)$":"\1th", that you can then use in any measure with a Substitute="#AddSuffix#". This is just as appealing to me as a lovely Inline Lua function is for jsmorley. Not my fault that the devs made Rainmeter so good that it rarely needs Lua's help... :D
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Lssg97
Posts: 36
Joined: October 21st, 2018, 2:55 am

Re: Questions About Calc Measure

Post by Lssg97 »

Yincognito wrote: March 5th, 2020, 1:16 pm So how does one convert negative numbers to base N? As far as I understood, there is the extension of two's complement for conversion to binary, but what about other bases? Just curious...
You're right, negative numbers can be represented in two's complement for binary. And octal or hexadecimal can use binary conversion directly. As for the other bases, I honestly can't imagine how to represent negative numbers.
User avatar
Lssg97
Posts: 36
Joined: October 21st, 2018, 2:55 am

Re: Questions About Calc Measure

Post by Lssg97 »

jsmorley wrote: March 5th, 2020, 1:46 pm In my view, The Lua Script measure is just as "proper Rainmeter" as any other measure. Creating and using the external .lua file is no more complicated than creating a .inc file, and I'm sorry, but having a complicated and tortuous Substitute or a boatload of Calc or String measures simply to avoid Lua makes no sense at all to me. I see NO advantage whatsoever, other than some weird "Sure, it's hideous and impossible for the average user to understand, but at least I didn't have to use Lua!" thinking...

Again, to each his own.
I think either approach is interesting. But in this case, I did see the superiority of Lua scripts. I also have some opinions on whether to use Lua scripts in the skin.

In fact, I once did not like to attach too many attachments to the skin I made, and functions that can be implemented directly in the skin file will be implemented in the skin file (weird obsessive-compulsive disorder ... right? :???: ). Once I even used Shape Mater to draw a picture myself to remove the picture files in the folder!

Code: Select all

[Rainmeter]
UpDate=-1

[Variables]
;========缩放倍数========
Zoom=0.15

[MeterLogo]
Meter=Shape
Shape=Rectangle 196,55,264,279 | Fill Color 119,185,0,255 | StrokeWidth 0
Shape2=Path MainLogo | Fill Color 119,185,0,255 | StrokeWidth 0
Shape3=Path LogoNameN | Fill Color 0,0,0,255 | StrokeWidth 0
Shape4=Path LogoNameV | Fill Color 0,0,0,255 | StrokeWidth 0
Shape5=Path LogoNameI1 | Fill Color 0,0,0,255 | StrokeWidth 0
Shape6=Path LogoNameDw | Fill Color 0,0,0,255 | StrokeWidth 0
Shape7=Path LogoNameDn | Fill Color 0,0,0,255 | StrokeWidth 0
Shape8=Path LogoNameI2 | Fill Color 0,0,0,255 | StrokeWidth 0
Shape9=Path LogoNameAw | Fill Color 0,0,0,255 | StrokeWidth 0
Shape10=Path LogoNameAn | Fill Color 0,0,0,255 | StrokeWidth 0
Shape11=Ellipse 453.5,437.5,5.5 | Fill Color 0,0,0,0 | StrokeWidth 1.5
Shape12=Path LogoRegister | Stroke Color 0,0,0,255 | StrokeWidth 1.5
Shape13=Combine Shape | XOR Shape2
Shape14=Combine Shape3 | Union Shape4 | Union Shape5 | Union Shape6 | Union Shape8 | Union Shape9 | Exclude Shape7 | Exclude Shape10
MainLogo=38,171 | CurveTo 362,171,195,32,308,108 | CurveTo 114,178,273,276,160,297 | CurveTo 280,172,160,136,235,117 | LineTo 244,203 | CurveTo 219,168,234,185,228,174 | CurveTo 148,182,210,161,180,148 | CurveTo 318,172,178,268,257,254 | CurveTo 81,175,252,89,143,98 | CurveTo 381,203,140,324,274,300 | CurveTo 429,233,406,219,426,228 | CurveTo 196,302,386,269,265,309 | CurveTo 38,171,133,294,73,256 | ClosePath 1
LogoNameN=40,442 | LineTo 40,367 | LineTo 83,367 | CurveTo 115,396,109,368,114,380 | LineTo 115,442 | LineTo 94,442 | LineTo 95,405 | CurveTo 80,385,95,397,93,386 | LineTo 61,385 | LineTo 61,442 | LineTo 40,442 | ClosePath 1
LogoNameV=143,442 | LineTo 119,367 | LineTo 140,367 | LineTo 158,427 | LineTo 176,367 | LineTo 197,367 | LineTo 173,442 | LineTo 143,442 | ClosePath 1
LogoNameI1=207,442 | LineTo 207,367 | LineTo 228,367 | LineTo 228,442 | LineTo 207,442 | ClosePath 1
LogoNameDw=242,442 | LineTo 242,367 | LineTo 276,367 | CurveTo 314,405,298,367,315,376 | CurveTo 276,442,314,440,297,442 | LineTo 242,442 | ClosePath 1
LogoNameDn=263,426 | LineTo 263,383 | LineTo 277,383 | CurveTo 294,405,283,383,294,388 | CurveTo 277,426,294,422,283,426 | LineTo 263,426 | ClosePath 1
LogoNameI2=325,442 | LineTo 325,367 | LineTo 346,367 | LineTo 346,442 | LineTo 325,442 | ClosePath 1
LogoNameAw=355,442 | LineTo 385,367 | LineTo 413,367 | LineTo 442,442 | LineTo 421,442 | LineTo 416,428 | LineTo 381,428 | LineTo 376,442 | LineTo 355,442 | ClosePath 1
LogoNameAn=385,416 | LineTo 398,381 | LineTo 412,416 | LineTo 385,416 | ClosePath 1
LogoRegister=452,441 | LineTo 452,435 | LineTo 454,435 | ArcTo 454,438 | LineTo 453,438 | LineTo 456,441
W=500
H=500
AntiAlias=1
;TransformationMatrix=#Zoom#;0;0;#Zoom#;0;0
nvidia.png
After all, Lua scripts are different from .inc files: .inc files can be integrated into skin .ini files, but Lua scripts cannot. I have also been distressed to implement certain algorithms.

I think another problem with Lua scripts is that the learning cost may be slightly higher. The Rainmeter skin file is a configuration file, and the Lua script is more like computer language, which may not be well understood by most people. Although learning links are given in the manual (https://docs.rainmeter.net/manual/lua-scripting/), it is really too difficult for non-computer majors and non-native English speakers ...

But judging from this case, the Lua script did give me the result I wanted most. I will consider studying Lua scripts. To be honest, I like it a bit now. :great:
You do not have the required permissions to view the files attached to this post.