Merge pull request #834 from Blizzard/native-module-code

Allow modules to register C code too.
This commit is contained in:
Tom van Dijck 2017-06-23 14:25:14 -07:00 committed by GitHub
commit fea573561c
4 changed files with 35 additions and 4 deletions

View File

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

View File

@ -116,11 +116,13 @@
-- Generate table of embedded content.
local contentTable = {}
local nativeTable = {}
print("Compiling... ")
for mi = 1, #manifests do
local manifestName = manifests[mi]
local manifestDir = path.getdirectory(manifestName)
local moduleName = path.getbasename(manifestDir)
local baseDir = path.getdirectory(manifestDir)
local files = dofile(manifests[mi])
@ -128,6 +130,15 @@
local filename = path.join(manifestDir, files[fi])
addScript(contentTable, filename, path.getrelative(baseDir, filename))
end
-- find native code in modules.
if moduleName ~= "src" then
local nativeFile = path.join(manifestDir, 'native', moduleName .. '.c')
if os.isfile(nativeFile) then
local pretty_name = moduleName:gsub("^%l", string.upper)
table.insert(nativeTable, pretty_name)
end
end
end
addScript(contentTable, path.join(_SCRIPT_DIR, "../src/_premake_main.lua"), "src/_premake_main.lua")
@ -167,6 +178,20 @@
buffered.writeln(result, "};")
buffered.writeln(result, "")
-- write out the registerModules method.
for _, name in ipairs(nativeTable) do
buffered.writeln(result, string.format("extern void register%s(lua_State* L);", name))
end
buffered.writeln(result, "")
buffered.writeln(result, "void registerModules(lua_State* L)")
buffered.writeln(result, "{")
for _, name in ipairs(nativeTable) do
buffered.writeln(result, string.format("\tregister%s(L);", name))
end
buffered.writeln(result, "}")
buffered.writeln(result, "")
-- Write it all out. Check against the current contents of scripts.c first,
-- and only overwrite it if there are actual changes.

View File

@ -215,6 +215,11 @@ int premake_init(lua_State* L)
lua_newtable(L);
lua_setglobal(L, "premake");
#if !defined(PREMAKE_NO_BUILTIN_SCRIPTS)
/* let native modules initialize themselves */
registerModules(L);
#endif
return OKAY;
}
@ -421,7 +426,7 @@ int premake_test_file(lua_State* L, const char* filename, int searchMask)
if (path && do_locate(L, filename, path)) return OKAY;
}
#if !defined(PREMAKE_NO_BUILTIN_SCRIPTS)
#if !defined(PREMAKE_NO_BUILTIN_SCRIPTS)
if ((searchMask & TEST_EMBEDDED) != 0) {
/* Try to locate a record matching the filename */
if (premake_find_embedded_script(filename) != NULL) {
@ -431,7 +436,7 @@ int premake_test_file(lua_State* L, const char* filename, int searchMask)
return OKAY;
}
}
#endif
#endif
return !OKAY;
}

View File

@ -181,7 +181,7 @@ typedef struct
} buildin_mapping;
extern const buildin_mapping builtin_scripts[];
extern void registerModules(lua_State* L);
int premake_init(lua_State* L);
int premake_execute(lua_State* L, int argc, const char** argv, const char* script);