It is currently March 29th, 2024, 5:14 am
Using Regex to escape variables
-
- Posts: 660
- Joined: June 25th, 2015, 7:02 pm
- Location: The Sky, USA
Re: Using Regex to escape variables
But it's clearly not doing that. In my example I used !WriteKeyValue to write escaped variables, and when I reloaded the file, the variables had been written without the escape characters.
-
- Developer
- Posts: 22628
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Using Regex to escape variables
Ah.. Ok.
Skin:
Lua:
And what you then get in the skin:
So don't escape anything. They are seen as literal strings by Lua, and when used in a [SectionVariable] in the !WriteKeyValue bang, that is AFTER everything has been "resolved", and they will still be treated as literal strings. Of course if you want to "use" what you are writing to the file, to then "resolve" the variables where they are used, you will have to !Refresh the skin.
Skin:
Code: Select all
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
[Variables]
[Lua]
Measure=Script
ScriptFile=Test.lua
UpdateDivider=-1
[MeasureSet]
Measure=Calc
OnUpdateAction=[!WriteKeyValue Variables myOtherVar "[Lua]"]
DynamicVariables=1
UpdateDivider=-1
[MeterOne]
Meter=String
MeasureName=Lua
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Code: Select all
function Initialize()
end
function Update()
myVar = 'contentMarginRight=((#bgWidth# + #bgOffset#) - #contentMarginAbs# - 1)'
return myVar
end
Code: Select all
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
[Variables]
myOtherVar=contentMarginRight=((#bgWidth# + #bgOffset#) - #contentMarginAbs# - 1)
[Lua]
Measure=Script
ScriptFile=Test.lua
UpdateDivider=-1
[MeasureSet]
Measure=Calc
OnUpdateAction=[!WriteKeyValue Variables myOtherVar "[Lua]"]
DynamicVariables=1
UpdateDivider=-1
[MeterOne]
Meter=String
MeasureName=Lua
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
You do not have the required permissions to view the files attached to this post.
-
- Posts: 660
- Joined: June 25th, 2015, 7:02 pm
- Location: The Sky, USA
Re: Using Regex to escape variables
Refreshing isn't an issue, it already does that anyway.
My problem with your approach is that the !WriteKeyValue bangs need to happen from within the LUA script. The script parses both the backup file and the suite's file with ReadINI, then goes through the backup file's table, seeing if those options exist in the suite's file. If it does, then it performs a !WriteKeyValue bang to copy the value from the backup file into the suite's file. I don't see any non-convoluted way to do this using the script as a section variable.
My problem with your approach is that the !WriteKeyValue bangs need to happen from within the LUA script. The script parses both the backup file and the suite's file with ReadINI, then goes through the backup file's table, seeing if those options exist in the suite's file. If it does, then it performs a !WriteKeyValue bang to copy the value from the backup file into the suite's file. I don't see any non-convoluted way to do this using the script as a section variable.
-
- Developer
- Posts: 22628
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Using Regex to escape variables
What if you did:raiguard wrote:Refreshing isn't an issue, it already does that anyway.
My problem with your approach is that the !WriteKeyValue bangs need to happen from within the LUA script. The script parses both the backup file and the suite's file with ReadINI, then goes through the backup file's table, seeing if those options exist in the suite's file. If it does, then it performs a !WriteKeyValue bang to copy the value from the backup file into the suite's file. I don't see any non-convoluted way to do this using the script as a section variable.
Skin:
Code: Select all
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
[Variables]
[Lua]
Measure=Script
ScriptFile=Test.lua
UpdateDivider=-1
[MeterOne]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=[Lua]
DynamicVariables=1
Code: Select all
function Initialize()
end
function Update()
myVar = 'contentMarginRight=((#bgWidth# + #bgOffset#) - #contentMarginAbs# - 1)'
myVar = myVar:gsub( '#(.-)#', '#\*%1\*#')
SKIN:Bang('!WriteKeyValue', 'Variables', 'myVar', myVar)
return myVar
end
Code: Select all
[Variables]
myVar=contentMarginRight=((#bgWidth# + #bgOffset#) - #contentMarginAbs# - 1)
-
- Posts: 660
- Joined: June 25th, 2015, 7:02 pm
- Location: The Sky, USA
Re: Using Regex to escape variables
Awesome, sorry for getting so heated in that argument. That regex you used will work nicely, but it doesn't support nested variables syntax. That's not a problem though, because I have yet to actually use them anywhere but in Inline LUA. Anyway, thanks again.
-
- Developer
- Posts: 22628
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Using Regex to escape variables
I didn't see you as heated, just pointed. That's perfectly fine, I tend to be the same way.raiguard wrote:Awesome, sorry for getting so heated in that argument. That regex you used will work nicely, but it doesn't support nested variables syntax. That's not a problem though, because I have yet to actually use them anywhere but in Inline LUA. Anyway, thanks again.
Using gsub to escape nested variables and section variables might take some thought...
-
- Posts: 660
- Joined: June 25th, 2015, 7:02 pm
- Location: The Sky, USA
Re: Using Regex to escape variables
EDIT: Nevermind, it consistently does it with the keys as well.
So on a related note, I just noticed that the ReadINI function is dropping leading S'es. Sometimes it will on the keys, but it does it consistently on commands.
For example, I have lots of variables that begin with "show". Occasionally, it will drop all of the S'es in show in an entire file, but it doesn't always do it. For the commands, if I have something like test=sally, it will always end up as test=ally in the table. Is there a mistake in the regex somewhere?
So on a related note, I just noticed that the ReadINI function is dropping leading S'es. Sometimes it will on the keys, but it does it consistently on commands.
Code: Select all
function ReadIni(inputfile)
local file = assert(io.open(inputfile, 'r'), 'Unable to open ' .. inputfile)
local tbl, section = {}
local num = 0
for line in file:lines() do
num = num + 1
if not line:match('^%s-;') then
local key, command = line:match('^([^=]+)=(.+)')
if line:match('^%s-%[.+') then
section = line:match('^%s-%[([^%]]+)'):lower()
if not tbl[section] then tbl[section] = {} end
elseif key and command and section then
tbl[section][key:lower():match('^s*(%S*)%s*$')] = command:match('^s*(.-)%s*$'):gsub('#(.-)#', '#\*%1\*#')
elseif #line > 0 and section and not key or command then
print(num .. ': Invalid property or value.')
end
end
end
if not section then print('No sections found in ' .. inputfile) end
file:close()
return tbl
end
-
- Developer
- Posts: 22628
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Using Regex to escape variables
Might be. I think we need smurfier to weigh in on this, he wrote that code snippet.
-
- Posts: 571
- Joined: February 28th, 2011, 3:20 pm
- Location: Vienna, Austria
Re: Using Regex to escape variables
While waiting for smurfier could you try the following:
In the ReadINI function replace the %s with a space character.
As you can capture every character with the percent sign in LUA, maybe one (or more) of the %s will be treated not as a space but as the character s.
In the ReadINI function replace the %s with a space character.
As you can capture every character with the percent sign in LUA, maybe one (or more) of the %s will be treated not as a space but as the character s.
-
- Rainmeter Sage
- Posts: 2588
- Joined: March 23rd, 2015, 5:26 pm
Re: Using Regex to escape variables
I'm no good at regex, but is there a couple missing "%" signs in this line:raiguard wrote:For example, I have lots of variables that begin with "show". Occasionally, it will drop all of the S'es in show in an entire file, but it doesn't always do it. For the commands, if I have something like test=sally, it will always end up as test=ally in the table. Is there a mistake in the regex somewhere?
tbl[section][key:lower():match('^s*(%S*)%s*$')] = command:match('^s*(.-)%s*$'):gsub('#(.-)#', '#\*%1\*#')
Is this suppose to be...?
tbl[section][key:lower():match('^[color=#FF0000]%[/color]s*(%S*)%s*$')] = command:match('^[color=#FF0000]%[/color]s*(.-)%s*$'):gsub('#(.-)#', '#\*%1\*#')