So there is the problem with
.* vs.
.- noted above, and there is one other thing to be careful about:
Skin:
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[MeasureScript]
Measure=Script
ScriptFile=Test.lua
UpdateDivider=-1
Divider=--
Lua:
Code: Select all
function Initialize()
divider = SELF:GetOption('Divider')
divider = divider:gsub('-', '%%-')
end
function Update()
myString = 'This is line 1\n--This is comment 1--\nThis is line 2\n--This is comment 2--\nThis is line 3'
newString = myString:gsub(divider..'.-'..divider, '')
print(newString)
SKIN:Bang('!SetOption', 'MeterOne', 'Text', newString)
end
Be aware that the "-" (minus) character is a reserved character in pattern matching as it means "ungreedy zero or more characters". It is perfectly fine to use "-" in a "string", but not in a "pattern" as a literal.
To use it as a literal in a pattern, you must escape the "-" character with "%". Of course "%" is ALSO a reserved character, so you must also escape it... So you end up with divider = divider:gsub('-', '%%-')
Then my example works as expected...
1.jpg
2.jpg
Reserved (or "magic") characters in Lua pattern matching are:
() . % + - * ? [ ^ $
The meaning of "repetition characters" in pattern matching are:
Code: Select all
+ 1 or more repetitions
* 0 or more repetitions
- also 0 or more repetitions
? optional (0 or 1 occurrence)
https://www.lua.org/pil/20.2.html
It can get a bit involved with the difference between a "control character" sequence like \n that has a special meaning everywhere, and "reserved characters" which are only special in a pattern. That might be a conversation for another day.
You do not have the required permissions to view the files attached to this post.