It is currently April 26th, 2024, 5:02 pm

[BUG] Inline lua weird escape behavior

Report bugs with the Rainmeter application and suggest features.
User avatar
Yincognito
Rainmeter Sage
Posts: 7171
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.
Since the square brackets are not feasible at this moment from native Rainmeter, I thought of sharing another workaround that you can use for now in this case...

LUA:

Code: Select all

function Test(p)
  p = p:gsub('[%s%|]*$','')
  print(p)
  print(('的笑容'):gsub('[的笑容]','#'))
  return true
end
INI:

Code: Select all

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

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

---Measures---

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

---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
A bit of a hack, but anyway: you provide Rainmeter/Lua enough characters to "eat" at the end of the string parameter used in the function, by adding a | |-like variable to it, as long as you like or need. When in Lua, chars will be eaten from the end of the string due to the multibyte Chinese characters (which, by the way, are actually 3 bytes in length each, see the last print() in the function), but if your CharsToEat string is long enough, no chars from the main string will get lost. Then, you apply a gsub() to the result, deleting the leftovers at the end of the string - largely made of spaces and | - to get the correct result:
LuaStrings.jpg
It's not as elegant or foolproof as the first workaround, but it's a possibility that allows you to use inline syntax freely, assuming you add that variable to any possible string that might have such multibyte characters.
You do not have the required permissions to view the files attached to this post.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth