Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 153

Bugs & Feature Suggestions • Re: [BUG] Multiple Lua functions calling CURRENTSECTION

$
0
0
The following is part of this discussion, reposted here because it belongs to this thread.

I've tested with 3 functions after the OV function. Both SectionIndex and SI are returning 0 only if they are placed after OV, they both work fine if they're before OV. Both SectionIndex and SI have one thing in common: SKIN:ParseFormula.

Code:

function OV(...) local s = arg[1] or SKIN:GetVariable('CURRENTSECTION'); local f, v = SKIN:GetMeasure(s), SKIN:GetMeter(s); return ((f or v) and (f or v):GetOption(arg[2] or (f and 'Measure' or 'Meter'), '', arg[3]) or '') endfunction SI(...) local I = {}; for i in (arg[1] or SKIN:GetVariable('CURRENTSECTION')):gmatch('%d+') do I[#I+1] = i end; return tostring(SKIN:ParseFormula((arg[3] or 'i'):gsub('i', I[arg[2] or #I] or '0'))) or '0' endfunction SectionIndex(section, occurrence, formula)  local indexes = {}  for index in section:gmatch('%d+') do table.insert(indexes, index) end  if occurrence == 'first' then occurrence = 1 elseif occurrence == 'last' then occurrence = #indexes end  return tostring(SKIN:ParseFormula(string.gsub(formula, '<x>', tostring(indexes[tonumber(occurrence)] or '0')))) or '0'end

So I've added this other function to the test with SKIN:parseFormula:

Code:

function cond2(cond_str, true_str, false_str)    if SKIN:ParseFormula(SKIN:ReplaceVariables(cond_str)) == 1 then        return true_str    else        return false_str    endend
That's one of the conditional functions discussed on this topic. So as I suspected, it doesn't work correctly. This is the measure:

Code:

[12]Measure=StringString=[&S:OV()][&S:cond2('([#CurrentSection]=12)','1','2')]UpdateDivider=-1DynamicVariables=1
it incorrectly returns "String2", instead of the expected "String1" (since the statement 12=12 is true).

If I do the oposite:

Code:

[12]Measure=StringString=[&S:cond2('([#CurrentSection] = 12)','1','2')][&S:OV()]UpdateDivider=-1DynamicVariables=1
Now the result is "1String" which is correct.

So, to try to be sure, I added another function, the simplest:

Code:

function con(cond, true_str, false_str)    if cond == 0 then        return false_str    else        return true_str    endend
If I place it before OV, the result is "1String" as expected

Code:

[12]Measure=StringString=[&S:con(([#CurrentSection] = 12),'1','2')][&S:OV()]UpdateDivider=-1DynamicVariables=1
However, if I do the oposite.

Code:

[12]Measure=StringString=[&S:OV()][&S:con(([#CurrentSection] = 12),'1','2')]UpdateDivider=-1DynamicVariables=1
The result is: String[&S:con(( = 12),'1','2')] :rofl:

This took me to test without any other function:

Code:

[12]Measure=StringString=[&S:OV()][#CurrentSection]UpdateDivider=-1DynamicVariables=1
Which, only returns: "String" (the oposite does return 12String correctly).

Whatever is causing this has to be inside the OV function, since I can use any other function with as many [#CurrentSection]s as I want and they work properly.

Code:

[12]Measure=StringString=[&S:SI()]-[#CurrentSection]-[&S:con(([#CurrentSection] = 12),'1','2')]-[&S:cond2('([#CurrentSection] = 12)','1','2')]UpdateDivider=-1DynamicVariables=1
This returns 12-12-1-1 which is correct.

However this:

Code:

[12]Measure=StringString=[&S:SI()]-[#CurrentSection]-[&S:con(([#CurrentSection] = 12),'1','2')]-[&S:cond2('([#CurrentSection] = 12)','1','2')]-[&S:OV()]-[&S:SI()]-[#CurrentSection]-[&S:con(([#CurrentSection] = 12),'1','2')]-[&S:cond2('([#CurrentSection] = 12)','1','2')]UpdateDivider=-1DynamicVariables=1
returns: 12-12-1-1-String-0--[&S:con(( = 12),'1','2')]-2

*Note I just placed the same before and after [&S:OV()]. The correct result should be 12-12-1-1-String-12-12-1-1

Finally, I tested the same with the original long version of the OV function: OptionValue, but without using [#CurrentSection], I simply used the name of the measure directly (12)

Code:

[12]Measure=StringString=[&S:SI()]-[#CurrentSection]-[&S:con(([#CurrentSection] = 12),'1','2')]-[&S:cond2('([#CurrentSection] = 12)','1','2')]-[&S:OptionValue('12','Measure',nil)]-[&S:SI()]-[#CurrentSection]-[&S:con(([#CurrentSection] = 12),'1','2')]-[&S:cond2('([#CurrentSection] = 12)','1','2')]UpdateDivider=-1DynamicVariables=1
Surprisingly, this doesn't work either, the result is the same: 12-12-1-1-String-0--[&S:con(( = 12),'1','2')]-2

So, I've started changing sections, like selecting other measure/meters and the result was the same, then I tried various options with the same result, until I changed option to nil:

Code:

[12]Measure=StringString=[&S:SI()]-[#CurrentSection]-[&S:con(([#CurrentSection] = 12),'1','2')]-[&S:cond2('([#CurrentSection] = 12)','1','2')]-[&S:OptionValue('12',nil,nil)]-[&S:SI()]-[#CurrentSection]-[&S:con(([#CurrentSection] = 12),'1','2')]-[&S:cond2('([#CurrentSection] = 12)','1','2')]UpdateDivider=-1DynamicVariables=1
The result was: 12-12-1-1--12-12-1-1

So maybe the problem has more to do with GetOption and little with [#CurrentSection].

To test further, I wrote this dummy function:

Code:

function OptionValue2(section, option, resolve)  return ((SKIN:GetMeasure(section) or SKIN:GetMeter(section)) and option or '')end
I said dummy because all it does is to return 'option' if the section exists. I just did it to remove the GetOption part of the original function. It works.

Code:

[12]Measure=StringString=[&S:SI()]-[#CurrentSection]-[&S:con(([#CurrentSection] = 12),'1','2')]-[&S:cond2('([#CurrentSection] = 12)','1','2')]-[&S:OptionValue2('[#CurrentSection]','Hola',nil)]-[&S:SI()]-[#CurrentSection]-[&S:con(([#CurrentSection] = 12),'1','2')]-[&S:cond2('([#CurrentSection] = 12)','1','2')]UpdateDivider=-1DynamicVariables=1
This correctly returns: 12-12-1-1-Hola-12-12-1-1. Notice I used [#CurrentSection] on all functions this time.

Sorry for the super long post, I was typing as I was testing.

This appears to indicate that the problem is GetOption.

Conclusion: While I have no idea how, nor why, GetOption may be causing rainmeter to not be able to resolve [#CurrentSection], making it simply an empty line "".


Here's the complete lua file I used to test:

Code:

function SI(...) local I = {}; for i in (arg[1] or SKIN:GetVariable('CURRENTSECTION')):gmatch('%d+') do I[#I+1] = i end; return tostring(SKIN:ParseFormula((arg[3] or 'i'):gsub('i', I[arg[2] or #I] or '0'))) or '0' endfunction OV(...) local s = arg[1] or SKIN:GetVariable('CURRENTSECTION'); local f, v = SKIN:GetMeasure(s), SKIN:GetMeter(s); return ((f or v) and (f or v):GetOption(arg[2] or (f and 'Measure' or 'Meter'), '', arg[3]) or '') endfunction con(cond, true_str, false_str)    if cond == 0 then        return false_str    else        return true_str    endendfunction cond2(cond_str, true_str, false_str)    if SKIN:ParseFormula(SKIN:ReplaceVariables(cond_str)) == 1 then        return true_str    else        return false_str    endendfunction SectionIndex(section, occurrence, formula)  local indexes = {}  for index in section:gmatch('%d+') do table.insert(indexes, index) end  if occurrence == 'first' then occurrence = 1 elseif occurrence == 'last' then occurrence = #indexes end  return tostring(SKIN:ParseFormula(string.gsub(formula, '<x>', tostring(indexes[tonumber(occurrence)] or '0')))) or '0'endfunction OptionValue(section, option, resolve)  return ((SKIN:GetMeasure(section) or SKIN:GetMeter(section)) and (SKIN:GetMeasure(section) or SKIN:GetMeter(section)):GetOption(option, '', resolve) or '')endfunction OptionValue2(section, option, resolve)  return ((SKIN:GetMeasure(section) or SKIN:GetMeter(section)) and option or '')end
Here's the test skin

Code:

[Rainmeter]Update=-1AccurateText=1DynamicWindowSize=1BackgroundMode=2SolidColor=47,47,47,255---Measures---[S]Measure=ScriptScriptFile=#@#Script.luaUpdateDivider=-1[12]Measure=StringString=[&S:SI()]-[#CurrentSection]-[&S:con(([#CurrentSection] = 12),'1','2')]-[&S:cond2('([#CurrentSection] = 12)','1','2')]-[&S:OptionValue2('12','Hola',nil)]-[&S:SI()]-[#CurrentSection]-[&S:con(([#CurrentSection] = 12),'1','2')]-[&S:cond2('([#CurrentSection] = 12)','1','2')]UpdateDivider=-1DynamicVariables=1---Meters---[Re7su3lt5]Meter=StringFontColor=255,255,255,255MeasureName=12FontFace=ConsolasFontSize=16Padding=5,5,5,5AntiAlias=1Text=%1UpdateDivider=-1DynamicVariables=1

Statistics: Posted by RicardoTM — Yesterday, 11:33 am



Viewing all articles
Browse latest Browse all 153

Trending Articles