lua-users home
lua-l archive

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




On 23/11/16 06:22 PM, David Given wrote:
I want to write out strings to a file and read them back in again, in an
ASCII-safe way. I'm writing them out with string.format("%q"), because
it's cheap and easy[*], but now I need to read them back in again.

Actually going through the string and parsing the escapes seems like a
lot of work. A faster but much scarier alternative is to wrap the string
with 'return (<string>' and compile and execute it in a restricted
environment.

Given that the interpreter already contains code to safely turn an
escaped string into a Lua string, there must be a better way --- what is it?


It's usually called "someone else". https://github.com/SoniEx2/Stuff/blob/master/lua/String.lua

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.