lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, Jun 4, 2010 at 11:01 PM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>> Hmm, I must be slow. I can't figure out how to convert a string with represented control characters into a string with actual control characters.
>>
>> E.g.:
>>
>> local input = [[ line 1\nline2 ]]
>>
>> str:gsub("\\(.)", '\%1') -- doesn't work
>
> control={n="\n", r="\r"} -- fill as needed
> str:gsub("\\(.)", control)
>

What about using loadstring?

----
local input = [[line1\nline2]]
local output = loadstring("return \"" .. input .. "\"")()
----

~Jonathan