It is currently March 28th, 2024, 4:23 pm

Passing result of measure to LUA script

Discuss the use of Lua in Script measures.
Post Reply
drmonero
Posts: 2
Joined: May 8th, 2017, 12:06 am

Passing result of measure to LUA script

Post by drmonero »

I'm trying to wrap my head around how LUA in rainmeter works.

With my own trials and error I successfully figured out how to pass a string/text to the LUA file, make some alterations, and then return the altered string back to the rainmeter skin.

However, what I would like to do and can't for the life of me figure out. Is to pass the result of a measure to the LUA script instead.

Here's the working example(Note: I don't actually know when it's appropriate/necessary to use DynamicVariables):

SKIN:

Code: Select all

[MeasureLuaScript]
Measure=Script
ScriptFile="#CURRENTPATH#BalanceConverter.lua"
TableName=BalanceConverter
MinexmrBalanceLua=9999999
UpdateDivider=140
DynamicVariables=1

[MeasureMinexmrSite]
Measure=Plugin
Plugin=WebParser
URL=http://api.minexmr.com:8080/stats_address?address=43vT6oYBds9dsaRZAwtusfYWZR3P2gVqgcFtj85pWmPq8GeQJzuFk2wF5VQFBVFcRsUTSvWFTGXb3FZT7Xd3NZ2fNRVaxyx
RegExp=(?siU)"balance":"(.*)".*
UpdateRate=3600
DynamicVariables=1

[MeasureMinexmrBalance]
Measure=Plugin
Plugin=WebParser
URL=[MeasureMinexmrSite]
StringIndex=1
DynamicVariables=1

[MeterLuaReturn]
Meter=String
MeasureName=MeasureLuaScript
MeterStyle=styleText
X=305
Y=40
Text=%1 XMR
AutoScale=1
DynamicVariables=1
Here's what I'd like to do and what doesn't work:

SKIN:

Code: Select all

[MeasureLuaScript]
Measure=Script
ScriptFile="#CURRENTPATH#BalanceConverter.lua"
TableName=BalanceConverter
MinexmrBalanceLua=[MeasureMinexmrBalance] (NOTE: Also tried #MeasureMinexmrBalance#)
UpdateDivider=140
DynamicVariables=1

[MeasureMinexmrSite]
Measure=Plugin
Plugin=WebParser
URL=http://api.minexmr.com:8080/stats_address?address=43vT6oYBds9dsaRZAwtusfYWZR3P2gVqgcFtj85pWmPq8GeQJzuFk2wF5VQFBVFcRsUTSvWFTGXb3FZT7Xd3NZ2fNRVaxyx
RegExp=(?siU)"balance":"(.*)".*
UpdateRate=3600
DynamicVariables=1

[MeasureMinexmrBalance]
Measure=Plugin
Plugin=WebParser
URL=[MeasureMinexmrSite]
StringIndex=1
DynamicVariables=1

[MeterLuaReturn]
Meter=String
MeasureName=MeasureLuaScript
MeterStyle=styleText
X=305
Y=40
Text=%1 XMR
AutoScale=1
DynamicVariables=1
Here's my LUA just in case it's relevant:

Code: Select all

function Initialize()

end

function Update()
	sMinexmrBalance = SELF:GetOption('MinexmrBalanceLua')
	sMinexmrBalanceUpdated = ""
	
	if string.len(sMinexmrBalance) == 12 then
		sMinexmrBalanceUpdated = "0." .. sMinexmrBalance
	elseif string.len(sMinexmrBalance) == 11 then
		sMinexmrBalanceUpdated = "0.0" .. sMinexmrBalance
	elseif string.len(sMinexmrBalance) == 10 then
		sMinexmrBalanceUpdated = "0.00" .. sMinexmrBalance
	elseif string.len(sMinexmrBalance) == 9 then
		sMinexmrBalanceUpdated = "0.000" .. sMinexmrBalance
	elseif string.len(sMinexmrBalance) == 8 then
		sMinexmrBalanceUpdated = "0.0000" .. sMinexmrBalance
	elseif string.len(sMinexmrBalance) == 7 then
		sMinexmrBalanceUpdated = "0.00000" .. sMinexmrBalance
	elseif string.len(sMinexmrBalance) == 6 then
		sMinexmrBalanceUpdated = "0.000000" .. sMinexmrBalance
	elseif string.len(sMinexmrBalance) == 5 then
		sMinexmrBalanceUpdated = "0.0000000" .. sMinexmrBalance
	elseif string.len(sMinexmrBalance) == 4 then
		sMinexmrBalanceUpdated = "0.00000000" .. sMinexmrBalance
	elseif string.len(sMinexmrBalance) == 3 then
		sMinexmrBalanceUpdated = "0.000000000" .. sMinexmrBalance
	elseif string.len(sMinexmrBalance) == 2 then
		sMinexmrBalanceUpdated = "0.0000000000" .. sMinexmrBalance
	elseif string.len(sMinexmrBalance) == 1 then
		sMinexmrBalanceUpdated = "0.00000000000" .. sMinexmrBalance
	end
	
	return(sMinexmrBalanceUpdated)
end
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Passing result of measure to LUA script

Post by jsmorley »

The problem is that when the skin is first loaded, and the Lua script is executed, the value of the WebParser measure is "" or an empty string. You are then waiting 140 seconds before you update the Lua script again.

If you do this:

Code: Select all

[MeasureLuaScript]
Measure=Script
ScriptFile="#CURRENTPATH#Test.lua"
MinexmrBalanceLua=[MeasureMinexmrBalance]
Disabled=1
UpdateDivider=-1
DynamicVariables=1

[MeasureMinexmrSite]
Measure=Plugin
Plugin=WebParser
URL=http://api.minexmr.com:8080/stats_address?address=43vT6oYBds9dsaRZAwtusfYWZR3P2gVqgcFtj85pWmPq8GeQJzuFk2wF5VQFBVFcRsUTSvWFTGXb3FZT7Xd3NZ2fNRVaxyx
RegExp=(?siU)"balance":"(.*)".*
UpdateRate=3600
FinishAction=[!EnableMeasure MeasureLuaScript][!UpdateMeasure MeasureLuaScript]
It should work fine.

I think you might want NumOfDecimals on the String meter, not AutoScale.

P.S. You don't need TableName on a Script measure. That has long ago been deprecated and doesn't do anything.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Passing result of measure to LUA script

Post by jsmorley »

Oh, don't forget to change the name of your .lua file back. I changed it to my standard "testing" template.
drmonero
Posts: 2
Joined: May 8th, 2017, 12:06 am

Re: Passing result of measure to LUA script

Post by drmonero »

That worked! Thank you so much, hope you have a great day. You've made mine!

EDIT: I will have to do a bit more reading on what AutoScale and Numofdecimals actually do.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Passing result of measure to LUA script

Post by jsmorley »

Glad to help.
Post Reply