It is currently November 19th, 2018, 8:11 am

Lua for me.

Discuss the use of Lua in Script measures.
User avatar
kyriakos876
Posts: 814
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 28th, 2018, 6:15 am

Also, could you please explain what's going on in your .lua code on the newT( t ) function? I'm no lua expert as you must have figured out by now.
User avatar
balala
Rainmeter Sage
Posts: 7014
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua for me.

balala » September 28th, 2018, 11:53 am

kyriakos876 wrote:Also you can only open and rewrite on a file without deleting everything only if it's in .txt format
Yep, I realized this and it's clear. However I think rewriting the code when any changes occurs isn't extremely efficient approach. Especially that in such cases you have to refresh the skin, to use the rewritten file.
User avatar
kyriakos876
Posts: 814
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 28th, 2018, 12:55 pm

balala wrote:Yep, I realized this and it's clear. However I think rewriting the code when any changes occurs isn't extremely efficient approach. Especially that in such cases you have to refresh the skin, to use the rewritten file.
That is true and one of my concerns. I'm studying raiguards code that could solve many of my problems though.
User avatar
balala
Rainmeter Sage
Posts: 7014
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua for me.

balala » September 28th, 2018, 1:16 pm

kyriakos876 wrote:That is true and one of my concerns. I'm studying raiguards code that could solve many of my problems though.
I have no good ideas, because if the file is rewritten a refresh of the skin is absolutely necessary. No other ways.
User avatar
kyriakos876
Posts: 814
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 28th, 2018, 1:29 pm

balala wrote:I have no good ideas, because if the file is rewritten a refresh of the skin is absolutely necessary. No other ways.
I think I can compromise one refresh every time a disk is added or removed...It does happen a lot but It's not THAT often and nothing that a computer made for server can't handle. Imagine a refresh every 1 hour for example... It's not that bad... but at the moment I don't know how to do that. Maybe you could help me here...

My issue is :

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=wmic logicaldisk get caption
OutputType=ANSI
RegExpSubstitute=1
Substitute="Caption":""," ":"",":":"","Name.*#CRLF#":"","#CRLF#":"
OnUpdateAction=[!SetVariable AllDisks "[#CurrentSection#]"]
OnChangeAction=[bang that rewrites everything][!Delay 1000][!Refresh]
DynamicVariables=1
This will OnChangeAction will be triggered from the first update because the [MeasureRun] will first have " " as return which is nothing, and then in the next update it will have the actual value... what could I do about this? Any ideas?
User avatar
kyriakos876
Posts: 814
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 28th, 2018, 2:48 pm

By the way, I almost went crazy until I found out how to make this work:

Code: Select all

SKIN:Bang(string.format('!WriteKeyValue Background_Disk_%s "MouseLeaveAction" "[!CommandMeasure DiskAnimation%s "Stop 1"][!CommandMeasure DiskAnimation%s "Execute 2"]" "#@#FileToEdit.txt"',i,i,i))
I literally tried everything in my power, only to come up with this:

\#*quotes*\#Stop 2\#*quotes*\#

I basically named a variable quotes=" because I just couldn't make it work any other way. I swear this has to be the stupidest thing I've ever done. :? :? :? :? :?
User avatar
balala
Rainmeter Sage
Posts: 7014
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua for me.

balala » September 28th, 2018, 3:22 pm

kyriakos876 wrote:My issue is :

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=wmic logicaldisk get caption
OutputType=ANSI
RegExpSubstitute=1
Substitute="Caption":""," ":"",":":"","Name.*#CRLF#":"","#CRLF#":"
OnUpdateAction=[!SetVariable AllDisks "[#CurrentSection#]"]
OnChangeAction=[bang that rewrites everything][!Delay 1000][!Refresh]
DynamicVariables=1
This will OnChangeAction will be triggered from the first update because the [MeasureRun] will first have " " as return which is nothing, and then in the next update it will have the actual value... what could I do about this? Any ideas?
Maybe try something like the following: add the following String measure:

Code: Select all

[MeasureDisks]
Measure=String
String=[MeasureRun]
DynamicVariables=1
OnChangeAction=[bang that rewrites everything][!Delay 1000][!Refresh]
UpdateDivider=-1
then add the FinishAction=[!UpdateMeasure "MeasureDisks"] option to the [MeasureRun] measure.
User avatar
kyriakos876
Posts: 814
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 28th, 2018, 3:39 pm

balala wrote:Maybe try something like the following: add the following String measure:

Code: Select all

[MeasureDisks]
Measure=String
String=[MeasureRun]
DynamicVariables=1
OnChangeAction=[bang that rewrites everything][!Delay 1000][!Refresh]
UpdateDivider=-1
then add the FinishAction=[!UpdateMeasure "MeasureDisks"] option to the [MeasureRun] measure.
So you mean this?

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=wmic logicaldisk get caption
OutputType=ANSI
RegExpSubstitute=1
Substitute="Caption":""," ":"",":":"","Name.*#CRLF#":"","#CRLF#":"
OnUpdateAction=[!SetVariable AllDisks "[#CurrentSection#]"]
FinishAction=[!UpdateMeasure "MeasureDiskss"]
DynamicVariables=1

[MeasureDiskss]
Measure=String
String=[MeasureRun]
DynamicVariables=1
OnChangeAction=[!CommandMeasure "MeasureLua" "Split()"][!Delay 2400][!Refresh]
UpdateDivider=-1
This just keeps refreshing the skin every 1 second... Did I do something wrong?
User avatar
jsmorley
Developer
Posts: 18330
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua for me.

jsmorley » September 28th, 2018, 3:41 pm

If you have a FinishAction that triggers, even second-hand, a refresh of the skin, that is going to be fired every time the skin is refreshed. That is a certain endless loop.

Understand that any IfCondition or IfMatch works in the following way:

1. The test is done the first time the measure it is on is updated, and the results of "true" or "false" are acted on.
2. The test is done on every subsequent update of the measure and the "true" or "false" actions are taken if the result of the test has changed. So in other words, when the result changes from "true" to "false" or from "false" to "true".
3. The "true" or "false" actions are not taken if the result of the test has not changed. The action is not taken if the result was "true" and is still "true".
4. IfConditionMode can change that behavior so the actions are taken on every update, even if they remain in the same "true" or "false" state.

Refreshing a skin will always cause item 1. to apply. When a skin is refreshed, it is started over, and there is no way for it to remember any previous state of "true" or "false", thus the appropriate action is applied. Only with some clever use of !WriteKeyValue can make any state be "persistent" and survive a refresh of the skin.
User avatar
kyriakos876
Posts: 814
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Lua for me.

kyriakos876 » September 28th, 2018, 3:51 pm

jsmorley wrote:If you have a FinishAction that triggers, even second-hand, a refresh of the skin, that is going to be fired every time the skin is refreshed. That is a certain endless loop.

Understand that any IfCondition or IfMatch works in the following way:

1. The test is done the first time the measure it is on is updated, and the results of "true" or "false" are acted on.
2. The test is done on every subsequent update of the measure and the "true" or "false" actions are taken if the result of the test has changed. So in other words, when the result changes from "true" to "false" or from "false" to "true".
3. The "true" or "false" actions are not taken if the result of the test has not changed. The action is not taken if the result was "true" and is still "true".
4. IfConditionMode can change that behavior so the actions are taken on every update, even if they remain in the same "true" or "false" state.

Refreshing a skin will always cause item 1. to apply.
So basically I need a second skin that handles this...