From 2f442bebcdfdda02f37af11b870dfe1beef12401 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 10 Jan 2014 02:57:05 +0000 Subject: The post-processing after LuaSrcDiet processing is required so that the string becomes a valid C string --HG-- branch : WDS-build --- scripts/embed.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/embed.lua b/scripts/embed.lua index f80a3cb..57f1034 100644 --- a/scripts/embed.lua +++ b/scripts/embed.lua @@ -7,9 +7,22 @@ local function stripfile(fname) dofile("scripts/luasrcdiet/LuaSrcDiet.lua") - -- Now simply return the file contents after LuaSrcDiet did its job + -- Let LuaSrcDiet do its job local s,l = get_slim_luasrc(fname) - print("\ttrimmed size: ", s:len(), " down from: ", l:len()) + -- Now do some cleanup so we can write these out as C strings + -- strip any CRs + s = s:gsub("[\r]", "") + + print("\ttrimmed size: ", s:len(), " down from: ", l:len()) -- we report the "raw" length + + -- escape backslashes + s = s:gsub("\\", "\\\\") + + -- escape line feeds + s = s:gsub("\n", "\\n") + + -- escape double quote marks + s = s:gsub("\"", "\\\"") return s end -- cgit v1.2.3