Me neither, however Google is my (and probably yours as well) friend!SilverAzide wrote: ↑February 2nd, 2022, 9:23 pm Wow! I had no idea you could get file sizes that way!
It is currently September 10th, 2024, 4:54 pm
File size problem in lua
-
- Rainmeter Sage
- Posts: 16513
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: File size problem in lua
-
- Developer
- Posts: 2726
- Joined: November 24th, 2011, 1:42 am
- Location: Utah
Re: File size problem in lua
You are correct, this is a parsing problem, specifically with the nesting syntax.SilverAzide wrote: ↑January 31st, 2022, 5:46 pm So, in short, this isn't a file size problem in Lua, it is a parsing problem in Rainmeter.
When the parser searches for section variables within brackets and doesn't find a variable, the parser starts again after the ending bracket - totally skipping any other section variables before that previous ending bracket.
The parsing function basically does this: Find the first ending bracket, then from that position, reverse find the starting bracket. This usually finds the inner-most section variable. However, if the inner most brackets do not represent a variable, the next starting point for the parser is after that first ending bracket.
The problem is, after it finds the next ending bracket and when it searches again for the starting bracket, it should start BEFORE that last occurrence of the staring bracket.
Here's a basic breakdown:
Code: Select all
"^" means the next occurrence of the ending bracket
"|" means the next occurrence of the starting bracket (reverse find from ending bracket)
First pass:
[&Script:Function([3].png)] Other Text [MeasureName]
| ^
Result of first pass: No substitutions. Variable evaluated: "3" (doesn't exist)
Second pass:
[&Script:Function([3].png)] Other Text [MeasureName]
| ^
Result of second pass: No Substitutions. Variable evaluted: "3].png)" (obviously doesn't exist)
Third pass:
[&Script:Function([3].png)] Other Text [MeasureName]
| ^
Result of third pass: Substitution occurs (if it exists). Variable evaluated: MeasureName (if it exists)
Hopefully that makes.
This hasn't come up before since skins are usually carefully crafted with respect to brackets, since they represent section names.
I will attempt to fix this parsing issue shortly, but it might not solve all the issues. For instance, in this case, if there was a measure named [3], then that measure's value would replace [3], even though the skin author meant to reference an actual file that contained [3] in it, like File[3].png (which is a totally valid filename). I am not sure how best to stop the parsing of section names when it is not desired.
-Brian
-
- Rainmeter Sage
- Posts: 2734
- Joined: March 23rd, 2015, 5:26 pm
Re: File size problem in lua
Wow... this seems a somewhat insurmountable problem! Best of luck on this challenge!
-
- Rainmeter Sage
- Posts: 8069
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: File size problem in lua
I'll use this thread instead of creating another one, taking advantage that you'll be working on this issue, and ask: is there any way to combine Lua's inline syntax with the section variable parameters? I'm thinking of something like:
Code: Select all
[&MS_Script_Timer:td:/100]
If it's not possible yet, can it be reasonably easily implemented, since you're working on such related parsing? I'll take a no for an answer, I just wanted to find out if such a syntax combination is possible or not.
EDIT2: In the end I managed to fit everything as desired without shortening stuff, but I'd still be interested if the above is possible, out of curiosity.
Last edited by Yincognito on February 3rd, 2022, 5:23 pm, edited 1 time in total.
-
- Rainmeter Sage
- Posts: 8069
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: File size problem in lua
Besides the few solutions and ideas already provided - including yours - here's another one:
Script.lua:
Code: Select all
function Function(variable)
variable = variable:gsub('&%S-;', {['['] = '[', [']'] = ']'})
return variable
end
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
---Measures---
[FileName]
Measure=String
String=[3].png
Substitute="[":"[","]":"]"
UpdateDivider=-1
[Script]
Measure=Script
ScriptFile=#@#Script.lua
UpdateDivider=-1
---Meters---
[MeterTest]
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
Text="Script = [&Script:Function('[&FileName]')]"
UpdateDivider=-1
DynamicVariables=1
Using something similar to magic quotes but for brackets, regex escaping but for brackets, or a new section variable parameter designed for this purpose are some options. Unfortunately, none of them work at this time, but luckily this is not a no alternative situation, as already mentioned in this thread. Even 'lame' alternatives, like SilverAzide said, can still get the expected result.
-
- Rainmeter Sage
- Posts: 16513
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: File size problem in lua
Ok, let's see how will this work. Thank you for all your work.
-
- Rainmeter Sage
- Posts: 16513
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: File size problem in lua
To be honest don't really realize what are you trying to tell me with this code. The skin doesn't return the size of the file, or am I just missing something?Yincognito wrote: ↑February 3rd, 2022, 1:33 pm Besides the few solutions and ideas already provided - including yours - here's another one:
-
- Rainmeter Sage
- Posts: 8069
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: File size problem in lua
As I said in the same reply...
The issue is more or less about square brackets in an inline Lua string. The fact that you encountered it while working to get a file's size is not that relevant to the problem at hand. That being said, I am indeed at fault of not making my code suit yours - pardon my lazyness. I guess I hoped you could adapt the code yourself to your case, if that was needed (but then you found a feasible solution already, so I skipped that).Yincognito wrote: ↑February 3rd, 2022, 1:33 pmI used Brian's simplified syntax above, instead of your specific example.
In other words, all you need to do to make it work is to add a substitute like mentioned to your file name measure(s) and then convert the "encoded" parts back into brackets in Lua using a similar gsub() ...
-
- Rainmeter Sage
- Posts: 16513
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: File size problem in lua
Right, now makes sense. Thank you for the suggestion, even if in meantime, as you saw, I switched to another solution. But it's good to see all the help we can get here.Yincognito wrote: ↑February 3rd, 2022, 3:02 pm As I said in the same reply...
The issue is more or less about square brackets in an inline Lua string. The fact that you encountered it while working to get a file's size is not that relevant to the problem at hand. That being said, I am indeed at fault of not making my code suit yours - pardon my lazyness. I guess I hoped you could adapt the code yourself to your case, if that was needed (but then you found a feasible solution already, so I skipped that).
In other words, all you need to do to make it work is to add a substitute like mentioned to your file name measure(s) and then convert the "encoded" parts back into brackets in Lua using a similar gsub() ...
-
- Rainmeter Sage
- Posts: 8069
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: File size problem in lua
Indeed - no problem. Whatever solution works for your case, it is the right one. Just thought of offering alternatives, even though I'm sure SilverAzide already described in words what I just wrote. Of course, the "encoding" doesn't have to be the HTML one, any encoding would work, as long as it doesn't "conflict" (i.e. is less likely to be part of) actual filenames. My favorite way to avoid such resemblances is to use the zero width space character (aka [\x200B]) somewhere in the said "encoding", as that is very unlikely to be found in any normal text, including paths or filenames.