Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/premake-4.x.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Perkins <starkos@industriousone.com>2015-04-07 00:45:12 +0300
committerJason Perkins <starkos@industriousone.com>2015-04-07 00:45:12 +0300
commit1ebb231e5674285010ca1c01e88a30736cccf03e (patch)
tree32965eac098ab8dfc7a7a8f8ab1b3a14cb8885cb
parenta9141dee8f470f624574f4e7a0fadac20a83a0db (diff)
Fix #25: Premake embed fails with block comments
-rw-r--r--CHANGES.txt1
-rw-r--r--scripts/embed.lua47
2 files changed, 27 insertions, 21 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 2bb1fd1..fbb312b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -76,6 +76,7 @@
* Bug 176: Target prefix breaks GCC linking
* Improved handling of precompiled headers across toolsets
* Initial support for Visual Studio 2013 (Igor Karatayev)
+* Issue 25: Remove block comments from embedded scripts (Richard Geary)
-------
diff --git a/scripts/embed.lua b/scripts/embed.lua
index 94b7cbf..014d2c5 100644
--- a/scripts/embed.lua
+++ b/scripts/embed.lua
@@ -1,7 +1,7 @@
--
-- 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
+-- 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.
--
@@ -12,13 +12,18 @@
-- strip tabs
s = s:gsub("[\t]", "")
-
+
-- strip any CRs
s = s:gsub("[\r]", "")
-
- -- strip out comments
- s = s:gsub("\n%-%-[^\n]*", "")
-
+
+ -- strip out block comments
+ s = s:gsub("[^\"']%-%-%[%[.-%]%]", "")
+ s = s:gsub("[^\"']%-%-%[=%[.-%]=%]", "")
+ s = s:gsub("[^\"']%-%-%[==%[.-%]==%]", "")
+
+ -- strip out inline comments
+ s = s:gsub("\n%-%-[^\n]*", "\n")
+
-- escape backslashes
s = s:gsub("\\", "\\\\")
@@ -26,14 +31,14 @@
s = s:gsub("\n+", "\n")
-- strip out leading comments
- s = s:gsub("^%-%-\n", "")
+ s = s:gsub("^%-%-[^\n]*\n", "")
-- escape line feeds
s = s:gsub("\n", "\\n")
-
+
-- escape double quote marks
s = s:gsub("\"", "\\\"")
-
+
return s
end
@@ -43,14 +48,14 @@
out:write(s)
out:write(iif(continues, "\"\n", "\",\n"))
end
-
-
+
+
local function writefile(out, fname, contents)
local max = 1024
out:write("\t/* " .. fname .. " */\n")
-
- -- break up large strings to fit in Visual Studio's string length limit
+
+ -- break up large strings to fit in Visual Studio's string length limit
local start = 1
local len = contents:len()
while start <= len do
@@ -61,11 +66,11 @@
-- make sure I don't cut an escape sequence
while contents:sub(finish, finish) == "\\" do
finish = finish - 1
- end
+ end
writeline(out, contents:sub(start, finish), finish < len)
start = finish + 1
- end
+ end
out:write("\n")
end
@@ -74,23 +79,23 @@
function doembed()
-- load the manifest of script files
scripts = dofile("src/_manifest.lua")
-
+
-- main script always goes at the end
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("/* DO NOT EDIT - this file is autogenerated - see BUILD.txt */\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)
local s = stripfile("src/" .. fn)
writefile(out, fn, s)
end
-
- out:write("\t0\n};\n");
+
+ out:write("\t0\n};\n");
out:close()
end