fix: escape backslashes in embedded Wren source strings for C compilation

Add `line.replace("\\", "\\\\")` to the `wren_to_c_string.py` script so that backslashes in Wren source code (e.g., `\n`, `\r`, `\x1b`) are properly escaped when embedded as C string literals. This fixes incorrect escape sequences in `io.wren.inc` and `repl.wren.inc` that caused runtime failures when reading line separators and rendering REPL output.
This commit is contained in:
Josh Goebel
2021-05-21 23:09:05 +00:00
parent b22f1ab185
commit c1b97522dd
3 changed files with 21 additions and 20 deletions
+1
View File
@@ -24,6 +24,7 @@ static const char* {1}ModuleSource =
def wren_to_c_string(input_path, wren_source_lines, module):
wren_source = ""
for line in wren_source_lines:
line = line.replace("\\", "\\\\")
line = line.replace('"', "\\\"")
line = line.replace("\n", "\\n\"")
if wren_source: wren_source += "\n"