3 ms·
Try running this in a repl and tell me what you get, OP: string.format('%q', 'hi\n')
by jhatemyjob 2y ago
Try running this in a repl and tell me what you get, OP:
string.format('%q', 'hi\n')
- myrmidon 2y agoIf you insinuate that %q obviates the need for ldump then you are wrong. There is not even significant overlap in what they do; all that %q does is sufficiently escape Lua strings so the interpreter can read them back. It does not serialize functions nor even tables in any shape or form. edit: Sorry for being unreasonably harsh after misunderstanding your message.
- girvel 2y agoI actually thought the comment was about ldump implementation: it uses %q to serialize strings, and it may not be a reliable way.
- girvel 2y agoOn my machine it produces an equivalent string, although differently formatted. It seems that ldump preserves all special characters (`"\a\b\f\n\r\t\v\\\"\'"`), although I will need to test in on all supported versions.
- jhatemyjob 2y agoAh, you know what, you're right. It's an equivalent string for me too: "hi\ " I didn't know Lua treated \ before newlines like that. That's cool! I made a similar Lua serialization library for myself and was using a chain of `string.match` calls to escape my strings. Now I can make it way simpler. Lol. Thanks