Sorry for the delay, as it really was a one minute job (I already had a personal version of the function using the #CURRENTSECTION#, "last" occurrence and "x" defaults if nil-s were passed as arguments, just not while using a variable number of arguments) - here are both...While I'm a bit impatient, I can wait until you publish it
Longer names, default values, no variable number of arguments versions of SectionIndex() amd OptionValue(), for reference and clarity:
Code:
function SectionIndex(section, occurrence, formula) local I = {}; for i in (section or SKIN:GetVariable('CURRENTSECTION')):gmatch('%d+') do I[#I + 1] = i end return tostring(SKIN:ParseFormula((formula or 'index'):gsub('index', I[occurrence or #I] 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 '')end
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 '') end
Code:
[Rainmeter]Update=1000AccurateText=1DynamicWindowSize=1BackgroundMode=2SolidColor=47,47,47,255---Measures---[S]Measure=ScriptScriptFile=#@#Script.luaUpdateDivider=-1[Num8ber94]Measure=CalcFormula=(7+3)UpdateDivider=-1DynamicVariables=1---Meters---[Re7su3lt5]Meter=StringFontColor=255,255,255,255FontFace=ConsolasFontSize=16Padding=5,5,5,5AntiAlias=1Text=Section Name = #CURRENTSECTION##CRLF#Section Index = [&S:SI()]#CRLF#Option Value = [&S:OV()];Text=Section Name = #CURRENTSECTION##CRLF#Option Value = [&S:OV()]#CRLF#Section Index = [&S:SI()]UpdateDivider=-1DynamicVariables=1
- 0 to 3 arguments can be used in both
- in the long version I used 'index' and in the short version I used 'i' instead of the previous '<x>' used in the 3rd aka the formula argument
- one can omit successive arguments e.g. SI('A'), but preceding arguments must be set to nil instead of omitting them e.g. SI(nil,nil,'i')
Bug:
- if you comment the 1st Text line in the meter and uncomment the 2nd Text line, the SI() result will be 0 instead of 5 (can you confirm?)
Statistics: Posted by Yincognito — Yesterday, 5:32 pm