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

embed.lua « scripts - github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d7a43e4a1623f3ae0820d07297b75b6cc6b45c70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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