@@ -1077,7 +1077,7 @@ ${exitTreeLines.length > 0 ? exitTreeLines.join("\n").tab() : "\tpass"}
10771077 switch (constant ) {
10781078 case TInt (i ): return Std .string (i );
10791079 case TFloat (s ): return s .indexOf (" ." ) == - 1 ? ' $s .0' : s ;
1080- case TString (s ): return " \" " + StringTools . replace ( StringTools . replace ( s , " \\ " , " \\\\ " ), " \" " , " \\\" " ) + " \" " ;
1080+ case TString (s ): return stringToGDScript ( s ) ;
10811081 case TBool (b ): return b ? " true" : " false" ;
10821082 case TNull : return " null" ;
10831083 case TThis : {
@@ -1092,6 +1092,15 @@ ${exitTreeLines.length > 0 ? exitTreeLines.join("\n").tab() : "\tpass"}
10921092 return " " ;
10931093 }
10941094
1095+ function stringToGDScript (s : String ): String {
1096+ var result = StringTools .replace (s , " \\ " , " \\\\ " );
1097+ result = StringTools .replace (result , " \" " , " \\\" " );
1098+ result = StringTools .replace (result , " \t " , " \\ t" );
1099+ result = StringTools .replace (result , " \n " , " \\ n" );
1100+ result = StringTools .replace (result , " \r " , " \\ r" );
1101+ return " \" " + result + " \" " ;
1102+ }
1103+
10951104 function binopToGDScript (op : Binop , e1 : TypedExpr , e2 : TypedExpr ): String {
10961105 var gdExpr1 = compileExpression (e1 );
10971106 var gdExpr2 = compileExpression (e2 );
0 commit comments