1From 439e2effe1cc372925daf6d5c28569663ffb93ed Mon Sep 17 00:00:00 2001
2From: Tadeo Kondrak <me@tadeo.ca>
3Date: Mon, 25 Jan 2021 11:17:44 -0700
4Subject: [PATCH] Call weak function to allow adding preloaded plugins after
5 compile
6
7---
8 src/core/vscore.cpp | 19 +++++++++++++++++++
9 src/core/vscore.h | 5 +++++
10 2 files changed, 24 insertions(+)
11
12diff --git a/src/core/vscore.cpp b/src/core/vscore.cpp
13index f8e69062..4ce4c623 100644
14--- a/src/core/vscore.cpp
15+++ b/src/core/vscore.cpp
16@@ -1791,6 +1791,20 @@ void VSCore::destroyFilterInstance(VSNode *node) {
17 freeDepth--;
18 }
19
20+extern "C" {
21+void __attribute__((weak)) VSLoadPluginsNix(void (*load)(void *data, const char *path), void *data);
22+
23+struct VSLoadPluginsNixCallbackData {
24+ VSCore *core;
25+ const char *filter;
26+};
27+
28+static void VSLoadPluginsNixCallback(void *data, const char *path) {
29+ auto callbackData = static_cast<VSLoadPluginsNixCallbackData *>(data);
30+ callbackData->core->loadAllPluginsInPath(path, callbackData->filter);
31+}
32+}
33+
34 VSCore::VSCore(int flags) :
35 numFilterInstances(1),
36 numFunctionInstances(0),
37@@ -1918,6 +1932,11 @@ VSCore::VSCore(int flags) :
38 } // If neither exists, an empty string will do.
39 #endif
40
41+ if (VSLoadPluginsNix != nullptr) {
42+ VSLoadPluginsNixCallbackData data{this, filter.c_str()};
43+ VSLoadPluginsNix(VSLoadPluginsNixCallback, &data);
44+ }
45+
46 VSMap *settings = readSettings(configFile);
47 const char *error = vs_internal_vsapi.mapGetError(settings);
48 if (error) {
49diff --git a/src/core/vscore.h b/src/core/vscore.h
50index 2ce0f56b..2982b133 100644
51--- a/src/core/vscore.h
52+++ b/src/core/vscore.h
53@@ -985,6 +985,9 @@ public:
54 std::string getV3ArgString() const;
55 };
56
57+extern "C" {
58+static void VSLoadPluginsNixCallback(void *data, const char *path);
59+}
60
61 struct VSPlugin {
62 friend struct VSPluginFunction;
63@@ -1140,6 +1143,8 @@ public:
64
65 explicit VSCore(int flags);
66 void freeCore();
67+
68+ friend void VSLoadPluginsNixCallback(void *data, const char *path);
69 };
70
71 #endif // VSCORE_H
72--
732.32.0
74