Merge pull request #861 from Blizzard/binary-embed
Allow embedding of binary resources.
This commit is contained in:
commit
dce5e604dc
@ -144,7 +144,7 @@
|
|||||||
{
|
{
|
||||||
"*.txt", "**.lua",
|
"*.txt", "**.lua",
|
||||||
"src/**.h", "src/**.c",
|
"src/**.h", "src/**.c",
|
||||||
"modules/**.h", "modules/**.c",
|
"modules/**"
|
||||||
}
|
}
|
||||||
|
|
||||||
excludes
|
excludes
|
||||||
|
@ -67,7 +67,9 @@
|
|||||||
|
|
||||||
local function addScript(result, filename, name, data)
|
local function addScript(result, filename, name, data)
|
||||||
if not data then
|
if not data then
|
||||||
if _OPTIONS["bytecode"] then
|
if not path.hasextension(filename, ".lua") then
|
||||||
|
data = loadScript(filename)
|
||||||
|
elseif _OPTIONS["bytecode"] then
|
||||||
verbosef("Compiling... " .. filename)
|
verbosef("Compiling... " .. filename)
|
||||||
local output = path.replaceextension(filename, ".luac")
|
local output = path.replaceextension(filename, ".luac")
|
||||||
local res, err = os.compile(filename, output);
|
local res, err = os.compile(filename, output);
|
||||||
|
@ -92,6 +92,11 @@ static const luaL_Reg os_functions[] = {
|
|||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const luaL_Reg premake_functions[] = {
|
||||||
|
{ "getEmbeddedResource", premake_getEmbeddedResource },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
static const luaL_Reg string_functions[] = {
|
static const luaL_Reg string_functions[] = {
|
||||||
{ "endswith", string_endswith },
|
{ "endswith", string_endswith },
|
||||||
{ "hash", string_hash },
|
{ "hash", string_hash },
|
||||||
@ -168,6 +173,7 @@ int premake_init(lua_State* L)
|
|||||||
{
|
{
|
||||||
const char* value;
|
const char* value;
|
||||||
|
|
||||||
|
luaL_register(L, "premake", premake_functions);
|
||||||
luaL_register(L, "criteria", criteria_functions);
|
luaL_register(L, "criteria", criteria_functions);
|
||||||
luaL_register(L, "debug", debug_functions);
|
luaL_register(L, "debug", debug_functions);
|
||||||
luaL_register(L, "path", path_functions);
|
luaL_register(L, "path", path_functions);
|
||||||
@ -215,10 +221,6 @@ int premake_init(lua_State* L)
|
|||||||
os_getcwd(L);
|
os_getcwd(L);
|
||||||
lua_setglobal(L, "_WORKING_DIR");
|
lua_setglobal(L, "_WORKING_DIR");
|
||||||
|
|
||||||
/* start the premake namespace */
|
|
||||||
lua_newtable(L);
|
|
||||||
lua_setglobal(L, "premake");
|
|
||||||
|
|
||||||
#if !defined(PREMAKE_NO_BUILTIN_SCRIPTS)
|
#if !defined(PREMAKE_NO_BUILTIN_SCRIPTS)
|
||||||
/* let native modules initialize themselves */
|
/* let native modules initialize themselves */
|
||||||
registerModules(L);
|
registerModules(L);
|
||||||
@ -650,3 +652,20 @@ int premake_load_embedded_script(lua_State* L, const char* filename)
|
|||||||
/* Load the chunk */
|
/* Load the chunk */
|
||||||
return luaL_loadbuffer(L, (const char*)chunk->bytecode, chunk->length, filename);
|
return luaL_loadbuffer(L, (const char*)chunk->bytecode, chunk->length, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Give the lua runtime raw access to embedded files.
|
||||||
|
*/
|
||||||
|
int premake_getEmbeddedResource(lua_State* L)
|
||||||
|
{
|
||||||
|
const char* filename = luaL_checkstring(L, 1);
|
||||||
|
const buildin_mapping* chunk = premake_find_embedded_script(filename);
|
||||||
|
if (chunk == NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_pushlstring(L, (const char*)chunk->bytecode, chunk->length);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
@ -143,6 +143,7 @@ int os_uuid(lua_State* L);
|
|||||||
int os_writefile_ifnotequal(lua_State* L);
|
int os_writefile_ifnotequal(lua_State* L);
|
||||||
int os_touchfile(lua_State* L);
|
int os_touchfile(lua_State* L);
|
||||||
int os_compile(lua_State* L);
|
int os_compile(lua_State* L);
|
||||||
|
int premake_getEmbeddedResource(lua_State* L);
|
||||||
int string_endswith(lua_State* L);
|
int string_endswith(lua_State* L);
|
||||||
int string_hash(lua_State* L);
|
int string_hash(lua_State* L);
|
||||||
int string_sha1(lua_State* L);
|
int string_sha1(lua_State* L);
|
||||||
|
Reference in New Issue
Block a user