Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Got string with single backslashes (!) in Lua that need to be escaped or replaced - How to?

In Adobe Lightroom a Plug-in is written in Lua. In an attempt to teach myself Lua I am working myself through the SDK producing own Plug-ins. Now I came accross a situation where I am getting a string from a table named 'images' like this:

images[1] = "d:\Windows\Temp\LREXPORT\NK119542.tif"

But of course Lua does not like those unescaped backslashes at all. The content of this table varies depending on the user action. I am thinking of a solution to grab that string and manipulate it for further processing.

Correct strings would be:

newimages = "d:/Windows/Temp/LREXPORT/NK119542.tif"
newimages = "d:\\Windows\\Temp\\LREXPORT\\NK119542.tif"

Went through lots of posts and online tutorials but sorry, I was not able to figure this one out. Hope there is a solution, thanks for replies.

like image 675
snahl Avatar asked Sep 13 '25 05:09

snahl


1 Answers

You can delimit your string with [[ and ]]:

Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> s = '\n'
> print(s)


> s = [[\n]]
> print(s)
\n
like image 74
cjorssen Avatar answered Sep 15 '25 06:09

cjorssen