Merge pull request #861 from Blizzard/binary-embed

Allow embedding of binary resources.
This commit is contained in:
Tom van Dijck 2017-08-07 09:26:32 -07:00 committed by GitHub
commit dce5e604dc
4 changed files with 28 additions and 6 deletions

View File

@ -144,7 +144,7 @@
{
"*.txt", "**.lua",
"src/**.h", "src/**.c",
"modules/**.h", "modules/**.c",
"modules/**"
}
excludes

View File

@ -67,7 +67,9 @@
local function addScript(result, filename, name, data)
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)
local output = path.replaceextension(filename, ".luac")
local res, err = os.compile(filename, output);

View File

@ -92,6 +92,11 @@ static const luaL_Reg os_functions[] = {
{ NULL, NULL }
};
static const luaL_Reg premake_functions[] = {
{ "getEmbeddedResource", premake_getEmbeddedResource },
{ NULL, NULL }
};
static const luaL_Reg string_functions[] = {
{ "endswith", string_endswith },
{ "hash", string_hash },
@ -168,6 +173,7 @@ int premake_init(lua_State* L)
{
const char* value;
luaL_register(L, "premake", premake_functions);
luaL_register(L, "criteria", criteria_functions);
luaL_register(L, "debug", debug_functions);
luaL_register(L, "path", path_functions);
@ -215,10 +221,6 @@ int premake_init(lua_State* L)
os_getcwd(L);
lua_setglobal(L, "_WORKING_DIR");
/* start the premake namespace */
lua_newtable(L);
lua_setglobal(L, "premake");
#if !defined(PREMAKE_NO_BUILTIN_SCRIPTS)
/* let native modules initialize themselves */
registerModules(L);
@ -650,3 +652,20 @@ int premake_load_embedded_script(lua_State* L, const char* filename)
/* Load the chunk */
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;
}

View File

@ -143,6 +143,7 @@ int os_uuid(lua_State* L);
int os_writefile_ifnotequal(lua_State* L);
int os_touchfile(lua_State* L);
int os_compile(lua_State* L);
int premake_getEmbeddedResource(lua_State* L);
int string_endswith(lua_State* L);
int string_hash(lua_State* L);
int string_sha1(lua_State* L);