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

some parsing...

Discuss the use of Lua in Script measures.
Pul53dr1v3r
Posts: 103
Joined: July 30th, 2014, 10:30 am

some parsing...

Pul53dr1v3r » March 7th, 2018, 11:02 am

Hi. I'd just want to confirm if i have used the right way to parse the current code as this is my very first touch with Lua.
(i dont need CRLF-ing, thus i removed it).

original:

Code: Select all

--SKIN:Bang('!SetOption', 'MoonRiseSet', 'Text', (""..'Moon:#CRLF#'..StrMoonRiseTip..'#CRLF#'..StrMoonSetTip.."") )	
	--SKIN:Bang('!UpdateMeter', '*')
	--SKIN:Bang('!Redraw')
parsed:

Code: Select all

SKIN:Bang('!SetOption', 'MoonRiseSet', 'Text', 'MOON:')	
	SKIN:Bang('!UpdateMeter', 'MoonRiseSet')
	SKIN:Bang('!Redraw')
	SKIN:Bang('!SetOption', 'MoonRise', 'Text', ""..StrMoonRiseTip.."")
	SKIN:Bang('!UpdateMeter', 'MoonRise')
	SKIN:Bang('!Redraw')
	SKIN:Bang('!SetOption', 'MoonSet', 'Text', ""..StrMoonSetTip.."")
	SKIN:Bang('!UpdateMeter', 'MoonSet')
	SKIN:Bang('!Redraw')
Last edited by Pul53dr1v3r on March 7th, 2018, 5:52 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 18330
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: some parsing...

jsmorley » March 7th, 2018, 11:53 am

Pul53dr1v3r wrote:Hi. I'd just want to confirm if i have used the right way to parse the current code as this is my very first touch with Lua.
(i dont need CRLF-ing, thus i removed it).

original:

Code: Select all

--SKIN:Bang('!SetOption', 'MoonRiseSet', 'Text', (""..'Moon:#CRLF#'..StrMoonRiseTip..'#CRLF#'..StrMoonSetTip.."") )	
	--SKIN:Bang('!UpdateMeter', '*')
	--SKIN:Bang('!Redraw')
parsed:

Code: Select all

SKIN:Bang('!SetOption', 'MoonRiseSet', 'Text', 'MOON:')	
	SKIN:Bang('!UpdateMeter', 'MoonRiseSet')
	SKIN:Bang('!Redraw')
	SKIN:Bang('!SetOption', 'MoonRise', 'Text', ""..StrMoonRiseTip.."")
	SKIN:Bang('!UpdateMeter', 'MoonRise')
	SKIN:Bang('!Redraw')
	SKIN:Bang('!SetOption', 'MoonSet', 'Text', ""..StrMoonSetTip.."")
	SKIN:Bang('!UpdateMeter', 'MoonSet')
	SKIN:Bang('!Redraw')
You don't need to send the "quotes" to Rainmeter. Option values in Rainmeter never, ever need quotes.

SKIN:Bang('!SetOption', 'MoonRise', 'Text', StrMoonRiseTip)

I know this might on the surface be a bit confusing, since we do recommend sending "quotes" on string values in the parameters of a Bang in Rainmeter. However, that doesn't apply when using the SKIN:Bang() function in Lua. The reason you want quotes on string values in bangs in Rainmeter is that the bang is all one long text option, using spaces to separate the parameters. It's not that we need the quotes on the option itself, it's that we need the quotes to reliably parse the bang. In Lua, the SKIN:Bang() function sends the various parameters as entirely distinct things, separated by single quotes and commas. There is no possibility of confusion about where one parameter ends and the next starts.

That is the beauty of the way the SKIN:Bang() function works, it eliminates needing some really hideously complicated quoting when sending bangs to the skin that contain variables in Lua.

You CAN send a form of the SKIN:Bang() function as one long string in Lua, and then quotes come into play as spaces become a factor. I recommend against this though, that is really an old, deprecated form of the function and shouldn't be used.

In addition, don't bother sending distinct !UpdateMeter and !Redraw commands in between each bang. All the bangs will "happen at once" when control is returned from Lua to Rainmeter at the end of the Update() function or any custom FunctionName() that you call, and there is just no need to hammer Rainmeter with updates and redraws. The last one is all you need.

Code: Select all

SKIN:Bang('!SetOption', 'MoonRiseSet', 'Text', 'MOON:')	
SKIN:Bang('!SetOption', 'MoonRise', 'Text', StrMoonRiseTip)
SKIN:Bang('!SetOption', 'MoonSet', 'Text', StrMoonSetTip)
SKIN:Bang('!UpdateMeter', '*')
SKIN:Bang('!Redraw')
If you really want to update just specific meters, that's fine, but for sure you only need one !Redaw. More than that is just wasting resources.

Code: Select all

SKIN:Bang('!SetOption', 'MoonRiseSet', 'Text', 'MOON:')	
SKIN:Bang('!SetOption', 'MoonRise', 'Text', StrMoonRiseTip)
SKIN:Bang('!SetOption', 'MoonSet', 'Text', StrMoonSetTip)
SKIN:Bang('!UpdateMeter', 'MoonRiseSet')
SKIN:Bang('!UpdateMeter', 'MoonRise')
SKIN:Bang('!UpdateMeter', 'MoonSet')
SKIN:Bang('!Redraw')
In a nutshell, this is why !UpdateMeter and !Redraw are separate things but are almost always used together. !UpdateMeter is relatively "cheap" and !Redraw is relatively "expensive". Update individual meters to your hearts content, then just fire off one single !Redraw.
Pul53dr1v3r
Posts: 103
Joined: July 30th, 2014, 10:30 am

Re: some parsing...

Pul53dr1v3r » March 7th, 2018, 5:52 pm

Thx!