diff options
author | starkos <unknown> | 2009-07-16 19:20:15 +0400 |
---|---|---|
committer | starkos <unknown> | 2009-07-16 19:20:15 +0400 |
commit | 29fcfa20fa4bed957c411a53beab80e1cbda05d2 (patch) | |
tree | caf0d690da84d1cb2a49cfff942d361dfe32e7ab /scripts/embed.lua | |
parent | 3a91df1c9c03a1c60cfda901d2065ed32fbaf8ad (diff) |
Started a release script
Diffstat (limited to 'scripts/embed.lua')
-rw-r--r-- | scripts/embed.lua | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/scripts/embed.lua b/scripts/embed.lua new file mode 100644 index 0000000..d7a43e4 --- /dev/null +++ b/scripts/embed.lua @@ -0,0 +1,61 @@ +-- +-- Embed the Lua scripts into src/host/scripts.c as static data buffers. +-- I embed the actual scripts, rather than Lua bytecodes, because the +-- bytecodes are not portable to different architectures, which causes +-- issues in Mac OS X Universal builds. +-- + + local function embedfile(out, fname) + local f = io.open(fname) + local s = f:read("*a") + f:close() + + -- strip tabs + s = s:gsub("[\t]", "") + + -- strip any CRs + s = s:gsub("[\r]", "") + + -- strip out comments + s = s:gsub("\n%-%-[^\n]*", "") + + -- escape backslashes + s = s:gsub("\\", "\\\\") + + -- strip duplicate line feeds + s = s:gsub("\n+", "\n") + + -- strip out leading comments + s = s:gsub("^%-%-\n", "") + + -- escape line feeds + s = s:gsub("\n", "\\n") + + -- escape double quote marks + s = s:gsub("\"", "\\\"") + + out:write("\t\"") + out:write(s) + out:write("\",\n") + end + + + function doembed() + -- load the manifest of script files + scripts = dofile("src/_manifest.lua") + table.insert(scripts, "_premake_main.lua") + + -- open scripts.c and write the file header + local out = io.open("src/host/scripts.c", "w+b") + out:write("/* Premake's Lua scripts, as static data buffers for release mode builds */\n") + out:write("/* To regenerate this file, run: premake4 embed */ \n\n") + out:write("const char* builtin_scripts[] = {\n") + + for i,fn in ipairs(scripts) do + print(fn) + s = embedfile(out, "src/"..fn) + end + + out:write("\t0\n};\n"); + out:close() + end |