It is currently April 18th, 2024, 2:41 am

[BUG/Suggestion]Replace \ with \\ when using built-in path variables in Inline Lua

Report bugs with the Rainmeter application and suggest features.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

[BUG/Suggestion]Replace \ with \\ when using built-in path variables in Inline Lua

Post by death.crafter »

I was trying to take an path as an argument for a lua function and I wanted to use [#ROOTCONFIGPATH]. But lua doesn't read single \. So if it is possible to repalce single \ by double \\ of built-in path variables before sending it to lua would be good. I know the work around but it would be good if it's done automatically.
from the Realm of Death
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: [BUG/Suggestion]Replace \ with \\ when using built-in path variables in Inline Lua

Post by death.crafter »

death.crafter wrote: June 3rd, 2021, 10:38 am I was trying to take an path as an argument for a lua function and I wanted to use [#ROOTCONFIGPATH]. But lua doesn't read single \. So if it is possible to repalce single \ by double \\ of built-in path variables before sending it to lua would be good. I know the work around but it would be good if it's done automatically.
I just wanted to bring it to the front. Is this possible?
from the Realm of Death
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [BUG/Suggestion]Replace \ with \\ when using built-in path variables in Inline Lua

Post by jsmorley »

death.crafter wrote: June 10th, 2021, 3:25 pm I just wanted to bring it to the front. Is this possible?
I'm just not sure I agree with it. Yes, there are times when you pass a string to Lua and the nature of the function you use it in sees it as an "expression" that will treat the \ character as an escape, but there are just as many times, probably a lot more, when it doesn't, and forcing in \\ would break things. It's not hard to deal with really, and I'm not sure there is a one-size-fits-all answer to this.

If you have Lua like this:

Code: Select all

function readFile(arg)

	file = io.open(arg)
	fileTxt = file:read('*all')
	file:close()
	
	return fileTxt

end
It will work perfect well with a call like [&LuaMeasure:readFile('#CURRENTPATH#myFile.txt')]. Forcing \\ into the resolution of #CURRENTPATH# before sending it to Lua would break this.
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: [BUG/Suggestion]Replace \ with \\ when using built-in path variables in Inline Lua

Post by death.crafter »

jsmorley wrote: June 10th, 2021, 3:29 pm I'm just not sure I agree with it. Yes, there are times when you pass a string to Lua and the nature of the function you use it in sees it as an "expression" that will treat the \ character as an escape, but there are just as many times, probably a lot more, when it doesn't, and forcing in \\ would break things. It's not hard to deal with really, and I'm not sure there is a one-size-fits-all answer to this.

If you have Lua like this:

Code: Select all

function readFile(arg)

	file = io.open(arg)
	fileTxt = file:read('*all')
	file:close()
	
	SKIN:Bang('!SetOption', 'MeterFile', 'Text', fileTxt)

end
It will work perfect well with a call like [&LuaMeasure:readFile('#CURRENTPATH#myFile.txt')]. Forcing \\ into the resolution of #CURRENTPATH# before sending it to Lua would break this.
Ahh I see. Actually if you look at my skin here, I have to use inline lua to take paths and configs. This is fine Ig. Thanks for the reply.
from the Realm of Death