It is currently April 20th, 2024, 4:38 am

Lua scripts: GetValue() not returning values?

Discuss the use of Lua in Script measures.
User avatar
Ricardo
Posts: 6
Joined: April 28th, 2011, 11:36 am

Lua scripts: GetValue() not returning values?

Post by Ricardo »

Hi,

I was wondering if anybody could confirm this. I was trying to use a number value returned from a Lua script into a BAR meter. To my surprise, it returns zero all the time! I tried squeezing the number through a CALC measure, but again, nada. It seems that the only values I get from the script are the ones returned from GetStringValue().

So, this works fine for STRING meters. But what about those meters that require numeric inputs, like BAR and CALC? Does anybody have any insights? Comments? Suggestions? Beer?


---
Test code:

Code: Select all

;
;	GetValueTest - To test the return value from a lua script
;
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 

[Rainmeter]
Author=rmenezes
Update=1000

[Metadata]
Name=GetValueTest
Description=To test the return value from a lua script

;
;	Styles
;

[sText]
FontFace=Arial Narrow
StringStyle=BOLD
FontColor=FFFFFFFF
FontSize=11
AntiAlias=1

[sBar]
BarColor=00FF00FF
SolidColor=FF0000FF
BarOrientation=HORIZONTAL

;
;	Measures
;

[mGetValue]
Measure=Script
ScriptFile=#CURRENTPATH#GetValueTest.lua
TableName=luaTable
UpdateDivider=10

[mGetValueCalc]
Measure=Calc
Formula=mGetValue

;
;	Meters
;

[GetValue]
X=0
Y=R
Meter=STRING
MeterStyle=sText
MeasureName=mGetValue
Text="GetValue: %1"

[GetValueCalc]
X=0
Y=R
Meter=STRING
MeterStyle=sText
MeasureName=mGetValueCalc
Text="GetValue (Calc): %1"

[BarValue]
X=0
Y=R
W=300
H=5
Meter=BAR
MeterStyle=sBar
MeasureName=mGetValue

[BarValueCalc]
X=0
Y=R
W=300
H=5
Meter=BAR
MeasureName=mGetValueCalc
MeterStyle=sBar
The script:

Code: Select all

--
-- GetValueTest - To test the return value from a lua script
--

-- Required but not used
PROPERTIES = { }

-- Before start
function Initialize()
	-- Nothing to do
end

-- Do it
function Update()

	-- Nothing to do, either

end

-- Return values

-- Uncomment/comment the function to be tested

function GetValue()
	return tonumber(0.5)
end

--function GetStringValue()
--	return tostring(0.5)
--end
The enviro:

Rainmeter 2.0.0 rev 745(64-bit) Feb 6 2011

---
When it rains, it pours
Last edited by Ricardo on April 28th, 2011, 4:37 pm, edited 1 time in total.
rm


  • Anty Em,

    I hate you. I hate Kansas.
    Dorothy

    p.s. I'm taking the dog.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua scripts: GetValue() not returning values?

Post by jsmorley »

Did you try

return 0.5

without the parens?

I'm not at my usual computer to test, but I don't think you need to treat "return" as a function.
User avatar
Ricardo
Posts: 6
Joined: April 28th, 2011, 11:36 am

Re: Lua scripts: GetValue() not returning values?

Post by Ricardo »

jsmorley wrote:Did you try

return 0.5

without the parens?

I'm not at my usual computer to test, but I don't think you need to treat "return" as a function.
Thanks for replying.
Yes, I did. The parens version was just another attempt to force a return value to show up...
rm


  • Anty Em,

    I hate you. I hate Kansas.
    Dorothy

    p.s. I'm taking the dog.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Lua scripts: GetValue() not returning values?

Post by jsmorley »

You are right. I can't get it to work either. Very strange. I was certain it DID work, but something seems to be broken.

I was able to fake it out by changing the Lua script to return the number as a string

Code: Select all

PROPERTIES =
{

}

function Initialize()

end -- function Initialize

function Update()

	RetVal = 3 + 2
		
end -- function Update

function GetStringValue()

	return tostring(RetVal)
	
end -- function GetStringValue
Which is returning "5" to the skin. Then used a Calc measure in the skin to convert the string to a number.

Code: Select all

[Rainmeter]
Update=1000

[MeterBar]
Meter=BAR
MeasureName=MeasureCalc
W=100
H=20
BarColor=255,255,255,255
SolidColor=0,0,0,255
BarOrientation=HORIZONTAL 

[MeasureCalc]
Measure=Calc
Formula=[MeasureLuaScript]
MinValue=0
MaxValue=10
DynamicVariables=1

[MeasureLuaScript]
Measure=Script
ScriptFile="#CURRENTPATH#Test.lua"
TableName=Test
UpdateDivider=5
You may need to do something similar until we can investigate what is going on with a Lua measure returning a number...
User avatar
Ricardo
Posts: 6
Joined: April 28th, 2011, 11:36 am

Re: Lua scripts: GetValue() not returning values?

Post by Ricardo »

JS,

Thanks for taking the time to check into that bug. Rainmeter is such a nice tool - and being able to hook it up with a scripting language like Lua opens up many possibilities. I've just started playing with it, basically a couple of days, but already got hooked. My experience with C++ is very limited (being away from coding for a few years now). Nevertheless I did take a peek at the source repository and... well, like I said, my experience sucks. Not having familiarity with the whole project didn't help either. But if you point me to the right files I'd be glad to try to help hunt down this bugger.

BTW, I had tried to use a CALC measure before, but with no success - all I got were zeros. From your example code I realized I had forgotten to enclose the measure name in square brackets for the Formula value, like:

Code: Select all

[mGetValueCalc]
Measure=Calc
Formula=[mGetValue]
Now it works fine.

The bad news is that Calc is casting the returned value as an integer. No biggie there -- can always use min and max values, but that should be something else to look into while fooling around with the return function.

Again, thanks for the effort. Let me know if I can help, or just bring the beer.
rm


  • Anty Em,

    I hate you. I hate Kansas.
    Dorothy

    p.s. I'm taking the dog.
User avatar
Ricardo
Posts: 6
Joined: April 28th, 2011, 11:36 am

Re: Lua scripts: GetValue() not returning values?

Post by Ricardo »

Houston, we have another problem.

I was poking around the Lua return value bug and I've found another bad behavior.

If you try to return a variable (instead of a literal) created/altered in the Update() function, crazy things happen:

- You get "ERROR #nil - Unknown function/variable!" messages in the log.
- The CALC measure stops seeing the value returned altogether.
- STRING meters still work.

As in:

Code: Select all

PROPERTIES = { }

function Initialize()
end

function Update()
	n = 5
end

function GetStringValue()
	return tostring(n)
end
This will happen even if you make the variable global as in:

Code: Select all

PROPERTIES = { }

function Initialize()
	n=0
end

function Update()
	n = n+1
end

function GetStringValue()
	return tostring(n)
end
If you return a variable created/altered within the GetStringValue() function the behavior is the same as if you had used a literal (scoping is fine). But where's the fun in that?

All in the name of love...
rm


  • Anty Em,

    I hate you. I hate Kansas.
    Dorothy

    p.s. I'm taking the dog.