Browse Source

Change auto.lua to create plaintext instead of hex code.

vrld 14 years ago
parent
commit
08259a4a0e

+ 1 - 1
src/love.cpp

@@ -286,7 +286,7 @@ int main(int argc, char ** argv)
 	}
 	}
 
 
 	// Boot
 	// Boot
-	if (luaL_loadbuffer(L, (const char *)love::boot_lua, sizeof(love::boot_lua), "boot.lua") == 0)
+	if (luaL_loadbuffer(L, love::boot_lua.c_str(), love::boot_lua.size(), "boot.lua") == 0)
 		lua_call(L, 0, 0);
 		lua_call(L, 0, 0);
 
 
 	lua_close(L);
 	lua_close(L);

+ 1 - 1
src/modules/audio/wrap_Audio.cpp

@@ -305,7 +305,7 @@ namespace audio
 
 
 		luax_register_module(L, w);
 		luax_register_module(L, w);
 
 
-		if (luaL_loadbuffer(L, (const char *)audio_lua, sizeof(audio_lua), "audio.lua") == 0)
+		if (luaL_loadbuffer(L, audio_lua.c_str(), audio_lua.size(), "audio.lua") == 0)
 			lua_call(L, 0, 0);
 			lua_call(L, 0, 0);
 
 
 		return 0;
 		return 0;

+ 1 - 1
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -1050,7 +1050,7 @@ namespace opengl
 
 
 		luax_register_module(L, w);
 		luax_register_module(L, w);
 
 
-		if (luaL_loadbuffer(L, (const char *)graphics_lua, sizeof(graphics_lua), "graphics.lua") == 0)
+		if (luaL_loadbuffer(L, graphics_lua.c_str(), graphics_lua.size(), "graphics.lua") == 0)
 			lua_call(L, 0, 0);
 			lua_call(L, 0, 0);
 
 
 		return 0;
 		return 0;

+ 1 - 31
src/scripts/audio.lua.h

@@ -22,37 +22,7 @@ namespace love
 {
 {
 
 
 // [audio.lua]
 // [audio.lua]
-const unsigned char audio_lua[] = 
-{
-	0x66,0x75,0x6E,0x63,0x74,0x69,0x6F,0x6E,0x20,0x6C,0x6F,0x76,0x65,0x2E,0x61,
-	0x75,0x64,0x69,0x6F,0x2E,0x6E,0x65,0x77,0x53,0x6F,0x75,0x72,0x63,0x65,0x28,
-	0x61,0x2C,0x20,0x62,0x29,0x20,0x69,0x66,0x20,0x74,0x79,0x70,0x65,0x28,0x61,
-	0x29,0x20,0x3D,0x3D,0x20,0x22,0x73,0x74,0x72,0x69,0x6E,0x67,0x22,0x20,0x74,
-	0x68,0x65,0x6E,0x20,0x61,0x20,0x3D,0x20,0x6C,0x6F,0x76,0x65,0x2E,0x66,0x69,
-	0x6C,0x65,0x73,0x79,0x73,0x74,0x65,0x6D,0x2E,0x6E,0x65,0x77,0x46,0x69,0x6C,
-	0x65,0x28,0x61,0x29,0x20,0x65,0x6E,0x64,0x20,0x69,0x66,0x20,0x74,0x79,0x70,
-	0x65,0x28,0x61,0x29,0x20,0x3D,0x3D,0x20,0x22,0x75,0x73,0x65,0x72,0x64,0x61,
-	0x74,0x61,0x22,0x20,0x74,0x68,0x65,0x6E,0x20,0x69,0x66,0x20,0x61,0x3A,0x74,
-	0x79,0x70,0x65,0x4F,0x66,0x28,0x22,0x46,0x69,0x6C,0x65,0x22,0x29,0x20,0x74,
-	0x68,0x65,0x6E,0x20,0x61,0x20,0x3D,0x20,0x6C,0x6F,0x76,0x65,0x2E,0x73,0x6F,
-	0x75,0x6E,0x64,0x2E,0x6E,0x65,0x77,0x44,0x65,0x63,0x6F,0x64,0x65,0x72,0x28,
-	0x61,0x29,0x20,0x65,0x6E,0x64,0x20,0x69,0x66,0x20,0x61,0x3A,0x74,0x79,0x70,
-	0x65,0x4F,0x66,0x28,0x22,0x44,0x65,0x63,0x6F,0x64,0x65,0x72,0x22,0x29,0x20,
-	0x74,0x68,0x65,0x6E,0x20,0x69,0x66,0x20,0x62,0x20,0x3D,0x3D,0x20,0x22,0x73,
-	0x74,0x61,0x74,0x69,0x63,0x22,0x20,0x74,0x68,0x65,0x6E,0x20,0x61,0x20,0x3D,
-	0x20,0x6C,0x6F,0x76,0x65,0x2E,0x73,0x6F,0x75,0x6E,0x64,0x2E,0x6E,0x65,0x77,
-	0x53,0x6F,0x75,0x6E,0x64,0x44,0x61,0x74,0x61,0x28,0x61,0x29,0x20,0x65,0x6E,
-	0x64,0x20,0x72,0x65,0x74,0x75,0x72,0x6E,0x20,0x6C,0x6F,0x76,0x65,0x2E,0x61,
-	0x75,0x64,0x69,0x6F,0x2E,0x6E,0x65,0x77,0x53,0x6F,0x75,0x72,0x63,0x65,0x31,
-	0x28,0x61,0x29,0x20,0x65,0x6E,0x64,0x20,0x69,0x66,0x20,0x61,0x3A,0x74,0x79,
-	0x70,0x65,0x4F,0x66,0x28,0x22,0x53,0x6F,0x75,0x6E,0x64,0x44,0x61,0x74,0x61,
-	0x22,0x29,0x20,0x74,0x68,0x65,0x6E,0x20,0x72,0x65,0x74,0x75,0x72,0x6E,0x20,
-	0x6C,0x6F,0x76,0x65,0x2E,0x61,0x75,0x64,0x69,0x6F,0x2E,0x6E,0x65,0x77,0x53,
-	0x6F,0x75,0x72,0x63,0x65,0x31,0x28,0x61,0x29,0x20,0x65,0x6E,0x64,0x20,0x65,
-	0x6E,0x64,0x20,0x65,0x72,0x72,0x6F,0x72,0x28,0x22,0x4E,0x6F,0x20,0x6D,0x61,
-	0x74,0x63,0x68,0x69,0x6E,0x67,0x20,0x6F,0x76,0x65,0x72,0x6C,0x6F,0x61,0x64,
-	0x22,0x29,0x20,0x65,0x6E,0x64,
-};
+const std::string audio_lua = "function love.audio.newSource(a, b) if type(a) == \"string\" then a = love.filesystem.newFile(a) end if type(a) == \"userdata\" then if a:typeOf(\"File\") then a = love.sound.newDecoder(a) end if a:typeOf(\"Decoder\") then if b == \"static\" then a = love.sound.newSoundData(a) end return love.audio.newSource1(a) end if a:typeOf(\"SoundData\") then return love.audio.newSource1(a) end end error(\"No matching overload\") end";
 // [/audio.lua]
 // [/audio.lua]
 
 
 } // love
 } // love

+ 11 - 52
src/scripts/auto.lua

@@ -13,7 +13,7 @@ function auto(name)
 	local cpp_name = name .. "_lua"
 	local cpp_name = name .. "_lua"
 
 
 	-- Read source Lua file
 	-- Read source Lua file
-	local src_file = io.open(src, "rb")
+	local src_file = assert(io.open(src, "rb"))
 	local src_data = src_file:read("*a")
 	local src_data = src_file:read("*a")
 	-- remove comments
 	-- remove comments
 	src_data = src_data:gsub("%-%-%[%[.-%-%-%]%]", ""):gsub("%-%-.-\n", "")
 	src_data = src_data:gsub("%-%-%[%[.-%-%-%]%]", ""):gsub("%-%-.-\n", "")
@@ -22,64 +22,23 @@ function auto(name)
 	local src_len = #src_data
 	local src_len = #src_data
 	src_file:close()
 	src_file:close()
 
 
-	local lines = {}
-	local line = {}
-	table.insert(lines, line)
-
-	for i=1,src_len do
-		table.insert(line, string.byte(src_data, i))
-		if math.mod(i, max_width) == 0 then
-			line = {}
-			table.insert(lines, line)
-		end
-	end
-
-	local src_output = "const unsigned char "..cpp_name.."[] = \n{\n"
-
-	for i,line in ipairs(lines) do
-		local concat = {}
-		for j,b in ipairs(line) do
-			table.insert(concat, string.format("0x%02X,", b))
-		end
-		src_output = src_output .. "\t" .. table.concat(concat, "").."\n"
-	end
-
-	src_output = src_output .. "};"
-
-	local include = true
-
-	-- Read dst
-	local dst_lines = {}
-	for line in io.lines(dst) do
-
-		if line == "// ["..src.."]" then
-			include = false
-			table.insert(dst_lines, line)
-			table.insert(dst_lines, src_output)
-		end
-
-		if line == "// [/"..src.."]" then
-			include = true
-		end
-
-		if include then
-			table.insert(dst_lines, line)
-		end
-	end
-
-	local tmp_data = table.concat(dst_lines, "\n")
+	src_data = string.format("const std::string %s = %q;", cpp_name, src_data)
 
 
 	-- Overwrite the old file only if they are different.
 	-- Overwrite the old file only if they are different.
-	local dst_file = io.open(dst, "rb")
+	local dst_file = assert(io.open(dst, "r"))
 	dst_data = dst_file:read("*a")
 	dst_data = dst_file:read("*a")
 	dst_file:close()
 	dst_file:close()
 
 
-	if tmp_data == dst_data then
+	local header, content, footer = dst_data:match('^(.-)(const.-%b"";)(.-)$')
+	assert(header and content and footer, "error parsing header/content/footer")
+
+	if content == src_data then
 		print(name .. ": no change")
 		print(name .. ": no change")
 	else
 	else
-
-		local dst_file = io.open(dst, "wb")
-		dst_file:write(tmp_data)
+		local dst_file = assert(io.open(dst, "wb"))
+		dst_file:write(header)
+		dst_file:write(src_data)
+		dst_file:write(footer)
 		dst_file:close()
 		dst_file:close()
 
 
 		print(name .. ": updated")
 		print(name .. ": updated")

File diff suppressed because it is too large
+ 0 - 1966
src/scripts/boot.lua.h


File diff suppressed because it is too large
+ 0 - 6002
src/scripts/graphics.lua.h


Some files were not shown because too many files changed in this diff