From 0190cfb117546b8075860251bdff819c2167c9a9 Mon Sep 17 00:00:00 2001 From: myk002 Date: Sun, 20 Nov 2022 17:27:14 -0800 Subject: [PATCH] ensure foo.init runs before foo.*.init --- library/Core.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index 083a6223f..836772c04 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -2000,15 +2000,21 @@ void getFilesWithPrefixAndSuffix(const std::string& folder, const std::string& p } size_t loadScriptFiles(Core* core, color_ostream& out, const vector& prefix, const std::string& folder) { - vector scriptFiles; + static const string suffix = ".init"; + vector scriptFiles; for ( size_t a = 0; a < prefix.size(); a++ ) { getFilesWithPrefixAndSuffix(folder, prefix[a], ".init", scriptFiles); } - std::sort(scriptFiles.begin(), scriptFiles.end()); + std::sort(scriptFiles.begin(), scriptFiles.end(), + [&](const string &a, const string &b) { + string a_base = a.substr(0, a.size() - suffix.size()); + string b_base = b.substr(0, b.size() - suffix.size()); + return a_base < b_base; + }); size_t result = 0; for ( size_t a = 0; a < scriptFiles.size(); a++ ) { result++; - std::string path = ""; + string path = ""; if (folder != ".") path = folder + "/"; core->loadScriptFile(out, path + scriptFiles[a], false);