It is currently August 12th, 2022, 7:27 pm

[BUG] Inline lua weird escape behavior

Report bugs with the Rainmeter application and suggest features.
User avatar
Jax
Posts: 93
Joined: June 7th, 2021, 11:46 am

[BUG] Inline lua weird escape behavior

Post by Jax »

Not sure how to put the issue into words... here's the code to test the issue:

Test.ini

Code: Select all

[Variables]
Sec.SaveLocation=C:\Users\Super Idol的笑容\Documents\Rainmeter\Skins\ValliStart\@Resources\Vars.inc 

[Dum]
Meter=String

[Func]
Measure=Script
ScriptFile=#@#Scripts\Func.lua
DynamicVariables=1
OnUpdateAction=[!Log "#Sec.SaveLocation#"][!Log "[&Func:Test([==[#Sec.SaveLocation#]==])]"][!CommandMEasure Func "Test2([[#Sec.SaveLocation#]])"]
#@#Scripts\Func.lua

Code: Select all

function Test(p)
    print(p)
    return p
end

function Test2(p)
    print(p)
end
Outut
unknown.png
Output for all 4 is expected to be identical, but the bang calling the function inline seems to be malfunctioning
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 14458
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: [BUG] Inline lua weird escape behavior

Post by balala »

Jax wrote: March 8th, 2022, 1:44 pm Output for all 4 is expected to be identical, but the bang calling the function inline seems to be malfunctioning
No, it is working for me. I get four proper messages in the log.
What I suppose you should check is the encoding of all files involved in this skin. Check the encoding of those files accordingly to this and this.
User avatar
Yincognito
Rainmeter Sage
Posts: 4778
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG] Inline lua weird escape behavior

Post by Yincognito »

Jax wrote: March 8th, 2022, 1:44 pm Not sure how to put the issue into words... here's the code to test the issue:

Test.ini

Code: Select all

[Variables]
Sec.SaveLocation=C:\Users\Super Idol的笑容\Documents\Rainmeter\Skins\ValliStart\@Resources\Vars.inc 

[Dum]
Meter=String

[Func]
Measure=Script
ScriptFile=#@#Scripts\Func.lua
DynamicVariables=1
OnUpdateAction=[!Log "#Sec.SaveLocation#"][!Log "[&Func:Test([==[#Sec.SaveLocation#]==])]"][!CommandMEasure Func "Test2([[#Sec.SaveLocation#]])"]
#@#Scripts\Func.lua

Code: Select all

function Test(p)
    print(p)
    return p
end

function Test2(p)
    print(p)
end
Outut
unknown.png
Output for all 4 is expected to be identical, but the bang calling the function inline seems to be malfunctioning
I don't think native Rainmeter supports all ways to write a string in Lua, especially the [[somestring]] or [=[somesting]=] variants since it conflicts with Rainmeter's own [SectionVariable] parsing, so you'd want to use single quotes to pass your string to Lua, and of course, encode the .lua file using something like USC-2 LE BOM in Notepad++:

Code: Select all

OnUpdateAction=[!Log "[&Func:Test('#Sec.SaveLocation#')]"][!CommandMeasure Func "Test2('#Sec.SaveLocation#')"]
LuaStrings.jpg
This won't return 0 as before, but it seems it will eat the last 6 chars (rs.inc) from the value of the variable. I'm not sure why that happens, though escaping the \ character in the path using either \\ or / in the variable seems to produce the right output for the [!CommandMeasure ...] part.

Until the devs have their say on this and fix it if it's a bug, you can use the same syntax as above in native Rainmeter, and something like this in Lua:

Code: Select all

function Test(p)
    print(SKIN:ReplaceVariables('#Sec.SaveLocation#'))
    return SKIN:ReplaceVariables('#Sec.SaveLocation#')
end

function Test2(p)
    print(SKIN:ReplaceVariables('#Sec.SaveLocation#'))
end
You do not have the required permissions to view the files attached to this post.
Last edited by Yincognito on March 8th, 2022, 4:27 pm, edited 1 time in total.
User avatar
Yincognito
Rainmeter Sage
Posts: 4778
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG] Inline lua weird escape behavior

Post by Yincognito »

balala wrote: March 8th, 2022, 3:47 pm No, it is working for me. I get four proper messages in the log.
What I suppose you should check is the encoding of all files involved in this skin. Check the encoding of those files accordingly to this and this.
Are you sure the last 6 characters from the variable (rs.inc) are not missing in your case? Cause it happens for me, even though the encoding is (I think) correct... :???:
User avatar
balala
Rainmeter Sage
Posts: 14458
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: [BUG] Inline lua weird escape behavior

Post by balala »

Yincognito wrote: March 8th, 2022, 4:08 pm Are you sure the last 6 characters from the variable (rs.inc) are not missing in your case?
No, I think they are not:
Log.png
You do not have the required permissions to view the files attached to this post.
User avatar
Yincognito
Rainmeter Sage
Posts: 4778
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG] Inline lua weird escape behavior

Post by Yincognito »

balala wrote: March 8th, 2022, 4:32 pm No, I think they are not:
Log.png
Ok, but you're not even using the Chinese characters (i.e. 的笑容) the OP is using, because that's the whole issue is about, see a related thread here as well... :confused: For your personal path (or mine, for that matter) the issue obviously doesn't happen, since those are lower byte characters, however, doing:

LUA:

Code: Select all

function Test(p)
    print(p)
    return p
end

function Test2(p)
    print(p)
end
INI:

Code: Select all

[Variables]
Sec.SaveLocation=C:\Users\Super Idol的笑容\Documents\Rainmeter\Skins\ValliStart\@Resources\Vars.inc

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=47,47,47,255

---Measures---

[Func]
Measure=Script
ScriptFile=#@#Scripts\Func.lua
DynamicVariables=1
UpdateDivider=-1
OnUpdateAction=[!Log "[&Func:Test('#Sec.SaveLocation#')]"][!CommandMeasure Func "Test2('#Sec.SaveLocation#')"]

---Meters---

[MeterTest]
Meter=String
FontFace=Consolas
FontColor=255,255,255,255
Padding=5,5,5,5
FontSize=16
AntiAlias=1
Text="Func = #Sec.SaveLocation#"
UpdateDivider=-1
DynamicVariables=1
yields:
LuaStrings.jpg
Anyway, I think I know why this happens. Judging by the post here, these are multibyte characters, and unsurprisingly the number of missing characters at the end (6) is equal to the 3 Chinese characters multiplied by 2 (I'm guessing, the difference between the 4 bytes needed by each one of them and the "supported" less number of bytes by Rainmeter / Lua, probably 2). So basically, each such character will "eat" 2 characters from the end of the string, resulting in incorrect results. That's probably the case for the related plugin issue in the other thread, by the way.

For the record, the issue happens even for characters like :
LuaStrings2.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 14458
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: [BUG] Inline lua weird escape behavior

Post by balala »

Yincognito wrote: March 8th, 2022, 4:52 pm Ok, but you're not even using the Chinese characters (i.e. 的笑容) the OP is using,
No, I don't and won't even...
User avatar
Jax
Posts: 93
Joined: June 7th, 2021, 11:46 am

Re: [BUG] Inline lua weird escape behavior

Post by Jax »

Yincognito wrote: March 8th, 2022, 4:07 pm

I don't think native Rainmeter supports all ways to write a string in Lua, especially the [[somestring]] or [=[somesting]=] variants since it conflicts with Rainmeter's own [SectionVariable] parsing, so you'd want to use single quotes to pass your string to Lua, and of course, encode the .lua file using something like USC-2 LE BOM in Notepad++:

Code: Select all

OnUpdateAction=[!Log "[&Func:Test('#Sec.SaveLocation#')]"][!CommandMeasure Func "Test2('#Sec.SaveLocation#')"]
LuaStrings.jpg
This won't return 0 as before, but it seems it will eat the last 6 chars (rs.inc) from the value of the variable. I'm not sure why that happens, though escaping the \ character in the path using either \\ or / in the variable seems to produce the right output for the [!CommandMeasure ...] part.

Until the devs have their say on this and fix it if it's a bug, you can use the same syntax as above in native Rainmeter, and something like this in Lua:

Code: Select all

function Test(p)
 print(SKIN:ReplaceVariables('#Sec.SaveLocation#'))
 return SKIN:ReplaceVariables('#Sec.SaveLocation#')
end

function Test2(p)
 print(SKIN:ReplaceVariables('#Sec.SaveLocation#'))
end
Yes. The missing rs.inc is exactly what happens to me when I use single quotes, which is why I resorted to using double square brackets, but Rainmeter treated them as measure values, which returned 0.
User avatar
Yincognito
Rainmeter Sage
Posts: 4778
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG] Inline lua weird escape behavior

Post by Yincognito »

balala wrote: March 8th, 2022, 6:42 pm No, I don't and won't even...
Really? Why? :jawdrop
I mean, you do what you want, but to see if a problem exists, one needs to replicate the same conditions that lead to the problem's appearance - after all, it's only about copy pasting the said variable in the skin, you don't have to change your account to that or something like this. :confused:

Anyway, thanks for making the test and sharing the results, as always. ;-)
User avatar
Yincognito
Rainmeter Sage
Posts: 4778
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: [BUG] Inline lua weird escape behavior

Post by Yincognito »

Jax wrote: March 8th, 2022, 11:54 pm Yes. The missing rs.inc is exactly what happens to me when I use single quotes, which is why I resorted to using double square brackets, but Rainmeter treated them as measure values, which returned 0.
Yeah, you can use those double square brackets within Lua without problems, just not in Rainmeter, for obvious reasons. I'll explore this further, maybe I'll find something else that may be useful in this case.