@@ -761,11 +761,14 @@ function serialize(buffer, v)
761761 table.insert (buffer , " }" )
762762
763763 elseif vType == " string" then
764- local s = F (" %q" , v )
765- if isDebug then
766- s = s :gsub (" \\\n " , " \\ n" )
767- end
768- table.insert (buffer , s )
764+ -- @Incomplete: Add an option specifically for nice string serialization?
765+ local s = v :gsub (" [%c\128 -\255 \"\\ ]" , function (c )
766+ local str = ESCAPE_SEQUENCES [c ] or F (" \\ %03d" , c :byte ())
767+ ESCAPE_SEQUENCES [c ] = str
768+ return str
769+ end )
770+
771+ table.insert (buffer , ' "' .. s .. ' "' )
769772
770773 elseif v == math.huge then
771774 table.insert (buffer , " math.huge" )
@@ -1979,7 +1982,8 @@ local function _processFileOrString(params, isFile)
19791982 -- @Incomplete: Maybe add an option to disable this? It might be useful if
19801983 -- e.g. Lua 5.1 is used to generate Lua 5.3 code (for whatever reason).
19811984 --
1982- local mainChunk , err = loadLuaString (lua , (isFile and params .pathMeta and " @" or " " ).. pathOut )
1985+ local luaToCheck = lua :gsub (" ^#![^\n ]*" , " " )
1986+ local mainChunk , err = loadLuaString (luaToCheck , (isFile and params .pathMeta and " @" or " " ).. pathOut )
19831987 if not mainChunk then
19841988 local ln , _err = err :match ' ^.-:(%d+): (.*)'
19851989 errorOnLine (pathOut , (tonumber (ln ) or 0 ), nil , " %s" , (_err or err ))
0 commit comments