Even for single-line literals like foo, this is not valid Lua: [===foo===]. The form [===[foo]===] is valid , but has problems with multi-line inputs: the linebreak backslashes end up in the string.
From what I can tell the appropriate fix here would be to simply return '[=[' + string + ']=]'; from the multiline_quote_ method and to remove the string.replace calls since "Escape sequences are not recognized when using double brackets" (found here).
However, this is my first time looking at lua. @seldomU is this along the lines of what you would expect?
I'm also not a Lua user, but I see two possible solutions to this + #3978 for Lua.
I'll use this block stack for examples:

1) Use string concatenation: generate code that looks like this:
for count = 1, 10 do
print('this is\n'..
'a\n'..
'multiline\n'..
'string')
end
This is obviously slightly slower because of concatenation, but the case of many concatenations in a loop is not something we're going to optimize for.
2) Use the \z escape sequence, as described here.
for count = 1, 10 do
print("this is \n\z
a \n\z
multiline \n\z
string")
end
Option 2 is for Lua 5.3 and up. repl.it is stuck at 5.1, but 5.3 is from 2015 so it seems relatively safe to me.
Option 2 does have the problem that ignores all leading whitespace, which means you get the same output with this code:
for count = 1, 10 do
print("this is \n\z
a \n\z
multiline \n\z
string")
end
As a result, I prefer option 1.
@seldomU You're the current authority on Lua, so let us know what you think is best.
My Lua skills consist mostly of taking Blockly generated code, feeding it into my game's interpreter and hoping for the best. So I feel well qualified for calling the shots.
I prefer Option 1 for its compatibility. I checked my interpreter (MoonSharp) as well as Roblox and both don't support Lua 5.3 yet. I'm not worried about concatenation being slightly slower.
Most helpful comment
My Lua skills consist mostly of taking Blockly generated code, feeding it into my game's interpreter and hoping for the best. So I feel well qualified for calling the shots.
I prefer Option 1 for its compatibility. I checked my interpreter (MoonSharp) as well as Roblox and both don't support Lua 5.3 yet. I'm not worried about concatenation being slightly slower.