From 4dd81d0c08c4e30a14377624d563534b9a2de698 Mon Sep 17 00:00:00 2001 From: Damien Courtois Date: Sun, 16 Aug 2015 22:05:33 +0200 Subject: [PATCH 1/2] added support for preloading user modules --- scripts/embed.lua | 21 +++++++++++++++++++++ src/_premake_main.lua | 10 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/scripts/embed.lua b/scripts/embed.lua index 444d1b93..9c2356aa 100644 --- a/scripts/embed.lua +++ b/scripts/embed.lua @@ -111,6 +111,17 @@ end end +-- Try to look for _user_modules.lua files in the _MAIN_SCRIPT_DIR folder +-- and it subfolders. If we find at least one, add the _embedded_user_modules.lua +-- entry. + + local userModuleFiles = {} + userModuleFiles = table.join(userModuleFiles, os.matchfiles(path.join(_MAIN_SCRIPT_DIR, "**/_user_modules.lua"))) + userModuleFiles = table.join(userModuleFiles, os.matchfiles(path.join(_MAIN_SCRIPT_DIR, "_user_modules.lua"))) + if #userModuleFiles > 0 then + table.insert(result, '\t"src/_embedded_user_modules.lua",') + end + table.insert(result, '\t"src/_premake_main.lua",') table.insert(result, '\t"src/_manifest.lua",') table.insert(result, '\t"src/_modules.lua",') @@ -136,6 +147,16 @@ end end +-- Write he user modules. + + if #userModuleFiles > 0 then + local userModules = {} + for _, userModuleFile in ipairs(userModuleFiles) do + userModules = table.join(userModules, dofile(userModuleFile)) + end + appendScript(result, "return {" .. table.implode(userModules, "\\\"", "\\\"", ",\\n") .. "}") + end + appendScript(result, loadScript(path.join(_SCRIPT_DIR, "../src/_premake_main.lua"))) appendScript(result, loadScript(path.join(_SCRIPT_DIR, "../src/_manifest.lua"))) appendScript(result, loadScript(path.join(_SCRIPT_DIR, "../src/_modules.lua"))) diff --git a/src/_premake_main.lua b/src/_premake_main.lua index 527687ed..db245b62 100644 --- a/src/_premake_main.lua +++ b/src/_premake_main.lua @@ -17,6 +17,16 @@ end +-- Adds optional user scripts + + do + local chunk, err = loadfile("_embedded_user_modules.lua") + if chunk then + modules = table.join(modules, chunk()) + end + end + + -- Create namespaces for myself local p = premake From 86a14e34913ad78e901ab96bdad69ee6e7898ecf Mon Sep 17 00:00:00 2001 From: Damien Courtois Date: Mon, 24 Aug 2015 18:08:43 +0200 Subject: [PATCH 2/2] support for user modules now only in the embed action --- scripts/embed.lua | 35 +++++++++++++---------------------- src/_premake_main.lua | 10 ---------- 2 files changed, 13 insertions(+), 32 deletions(-) diff --git a/scripts/embed.lua b/scripts/embed.lua index 9c2356aa..7e79bf3c 100644 --- a/scripts/embed.lua +++ b/scripts/embed.lua @@ -90,6 +90,11 @@ local mask = path.join(_MAIN_SCRIPT_DIR, "**/_manifest.lua") local manifests = os.matchfiles(mask) +-- Find all of the _user_modules.lua files within the project + + local userModuleFiles = {} + userModuleFiles = table.join(userModuleFiles, os.matchfiles(path.join(_MAIN_SCRIPT_DIR, "**/_user_modules.lua"))) + userModuleFiles = table.join(userModuleFiles, os.matchfiles(path.join(_MAIN_SCRIPT_DIR, "_user_modules.lua"))) -- Generate an index of the script file names. Script names are stored -- relative to the directory containing the manifest, i.e. the main @@ -111,17 +116,6 @@ end end --- Try to look for _user_modules.lua files in the _MAIN_SCRIPT_DIR folder --- and it subfolders. If we find at least one, add the _embedded_user_modules.lua --- entry. - - local userModuleFiles = {} - userModuleFiles = table.join(userModuleFiles, os.matchfiles(path.join(_MAIN_SCRIPT_DIR, "**/_user_modules.lua"))) - userModuleFiles = table.join(userModuleFiles, os.matchfiles(path.join(_MAIN_SCRIPT_DIR, "_user_modules.lua"))) - if #userModuleFiles > 0 then - table.insert(result, '\t"src/_embedded_user_modules.lua",') - end - table.insert(result, '\t"src/_premake_main.lua",') table.insert(result, '\t"src/_manifest.lua",') table.insert(result, '\t"src/_modules.lua",') @@ -147,19 +141,16 @@ end end --- Write he user modules. - - if #userModuleFiles > 0 then - local userModules = {} - for _, userModuleFile in ipairs(userModuleFiles) do - userModules = table.join(userModules, dofile(userModuleFile)) - end - appendScript(result, "return {" .. table.implode(userModules, "\\\"", "\\\"", ",\\n") .. "}") - end - appendScript(result, loadScript(path.join(_SCRIPT_DIR, "../src/_premake_main.lua"))) appendScript(result, loadScript(path.join(_SCRIPT_DIR, "../src/_manifest.lua"))) - appendScript(result, loadScript(path.join(_SCRIPT_DIR, "../src/_modules.lua"))) + +-- Write the list of modules + + local modules = dofile("../src/_modules.lua") + for _, userModules in ipairs(userModuleFiles) do + modules = table.join(modules, dofile(userModules)) + end + appendScript(result, "return {" .. table.implode(modules, "\\\"", "\\\"", ",\\n") .. "}") table.insert(result, "\tNULL") table.insert(result, "};") diff --git a/src/_premake_main.lua b/src/_premake_main.lua index db245b62..527687ed 100644 --- a/src/_premake_main.lua +++ b/src/_premake_main.lua @@ -17,16 +17,6 @@ end --- Adds optional user scripts - - do - local chunk, err = loadfile("_embedded_user_modules.lua") - if chunk then - modules = table.join(modules, chunk()) - end - end - - -- Create namespaces for myself local p = premake