Browse Source

Structured native api

Krzysztof Krysiński 1 year ago
parent
commit
75d2b2a28a

+ 2 - 0
src/PixiEditor.Extensions.Wasm/native/api.h

@@ -0,0 +1,2 @@
+void attach_logger_calls();
+void attach_window_calls();

+ 3 - 21
src/PixiEditor.Extensions.Wasm/native/api_interop.c

@@ -1,15 +1,10 @@
 #include <mono-wasi/driver.h>
 #include <mono-wasi/driver.h>
 #include <string.h>
 #include <string.h>
 #include <assert.h>
 #include <assert.h>
+#include "api.h"
 
 
 MonoMethod* method_init;
 MonoMethod* method_init;
 
 
-__attribute__((import_name("log_message")))
-void log_message(const char* message, int32_t messageLength);
-
-__attribute__((import_name("create_popup_window")))
-void create_popup_window(const char* title, int32_t titleLength, const char* content, int32_t contentLength);
-
 __attribute((export_name("initialize")))
 __attribute((export_name("initialize")))
 void initialize()
 void initialize()
 {
 {
@@ -24,21 +19,8 @@ void initialize()
     assert(!exception);
     assert(!exception);
 }
 }
 
 
-void logger_log_message(MonoString* message)
-{
-    char* message_utf8 = mono_wasm_string_get_utf8(message);
-    log_message(message_utf8, strlen(message_utf8));
-}
-
-void logger_create_popup_window(MonoString* title, MonoString* content)
-{
-    char* title_utf8 = mono_wasm_string_get_utf8(title);
-    char* content_utf8 = mono_wasm_string_get_utf8(content);
-    create_popup_window(title_utf8, strlen(title_utf8), content_utf8, strlen(content_utf8));
-}
-
 void attach_internal_calls()
 void attach_internal_calls()
 {
 {
-    mono_add_internal_call("PixiEditor.Extensions.Wasm.Interop::LogMessage", logger_log_message);
-    mono_add_internal_call("PixiEditor.Extensions.Wasm.Interop::CreatePopupWindow", logger_create_popup_window);
+    attach_logger_calls();
+    attach_window_calls();
 }
 }

+ 17 - 0
src/PixiEditor.Extensions.Wasm/native/logger_api.c

@@ -0,0 +1,17 @@
+#include <mono-wasi/driver.h>
+#include <string.h>
+#include <assert.h>
+
+__attribute__((import_name("log_message")))
+void log_message(const char* message, int32_t messageLength);
+
+void logger_log_message(MonoString* message)
+{
+    char* message_utf8 = mono_wasm_string_get_utf8(message);
+    log_message(message_utf8, strlen(message_utf8));
+}
+
+void attach_logger_calls()
+{
+    mono_add_internal_call("PixiEditor.Extensions.Wasm.Interop::LogMessage", logger_log_message);
+}

+ 18 - 0
src/PixiEditor.Extensions.Wasm/native/window_api.c

@@ -0,0 +1,18 @@
+#include <mono-wasi/driver.h>
+#include <string.h>
+#include <assert.h>
+
+__attribute__((import_name("create_popup_window")))
+void create_popup_window(const char* title, int32_t titleLength, const char* content, int32_t contentLength);
+
+void logger_create_popup_window(MonoString* title, MonoString* content)
+{
+    char* title_utf8 = mono_wasm_string_get_utf8(title);
+    char* content_utf8 = mono_wasm_string_get_utf8(content);
+    create_popup_window(title_utf8, strlen(title_utf8), content_utf8, strlen(content_utf8));
+}
+
+void attach_window_calls()
+{
+    mono_add_internal_call("PixiEditor.Extensions.Wasm.Interop::CreatePopupWindow", logger_create_popup_window);
+}

+ 6 - 3
src/PixiEditor.sln

@@ -84,6 +84,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PixiEditor.Extensions.Wasm"
 EndProject
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PixiEditor.Extensions.WasmRuntime", "PixiEditor.Extensions.WasmRuntime\PixiEditor.Extensions.WasmRuntime.csproj", "{B30622ED-9177-4930-8E64-2B2352D4D8DC}"
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PixiEditor.Extensions.WasmRuntime", "PixiEditor.Extensions.WasmRuntime\PixiEditor.Extensions.WasmRuntime.csproj", "{B30622ED-9177-4930-8E64-2B2352D4D8DC}"
 EndProject
 EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", "{13DD041C-EE2D-4AF8-B43E-D7BFC7415E4D}"
+EndProject
 Global
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
 		Debug|Any CPU = Debug|Any CPU
@@ -1452,7 +1454,6 @@ Global
 		{2BDEB8C6-F22D-43EA-A309-B3387A803689} = {9A81B795-66AB-4743-9284-90565941343D}
 		{2BDEB8C6-F22D-43EA-A309-B3387A803689} = {9A81B795-66AB-4743-9284-90565941343D}
 		{8EF48E6C-8219-4EE2-87C6-5176D8D092E6} = {9A81B795-66AB-4743-9284-90565941343D}
 		{8EF48E6C-8219-4EE2-87C6-5176D8D092E6} = {9A81B795-66AB-4743-9284-90565941343D}
 		{7A12C96B-8B5C-45E1-9EF6-0B1DA7F270DE} = {9A81B795-66AB-4743-9284-90565941343D}
 		{7A12C96B-8B5C-45E1-9EF6-0B1DA7F270DE} = {9A81B795-66AB-4743-9284-90565941343D}
-		{1249EE2B-EB0D-411C-B311-53A7A22B7743} = {1E816135-76C1-4255-BE3C-BF17895A65AA}
 		{CE1C8DC9-E26B-4BBB-AB87-34054DE34814} = {E4FF4CE6-5831-450D-8006-0539353C030B}
 		{CE1C8DC9-E26B-4BBB-AB87-34054DE34814} = {E4FF4CE6-5831-450D-8006-0539353C030B}
 		{10BF4001-214C-4869-8F78-2B6BDBDC7E7D} = {68C3DA2D-D2EA-426E-A866-0019E425C816}
 		{10BF4001-214C-4869-8F78-2B6BDBDC7E7D} = {68C3DA2D-D2EA-426E-A866-0019E425C816}
 		{FA98BFA6-2E83-41C6-9102-76875B261F51} = {1E816135-76C1-4255-BE3C-BF17895A65AA}
 		{FA98BFA6-2E83-41C6-9102-76875B261F51} = {1E816135-76C1-4255-BE3C-BF17895A65AA}
@@ -1463,8 +1464,10 @@ Global
 		{8F4FFC91-BE9F-4476-A372-FBD952865F15} = {1E816135-76C1-4255-BE3C-BF17895A65AA}
 		{8F4FFC91-BE9F-4476-A372-FBD952865F15} = {1E816135-76C1-4255-BE3C-BF17895A65AA}
 		{427CE098-4B13-4E46-8C66-D924140B6CAE} = {1E816135-76C1-4255-BE3C-BF17895A65AA}
 		{427CE098-4B13-4E46-8C66-D924140B6CAE} = {1E816135-76C1-4255-BE3C-BF17895A65AA}
 		{F4436A16-9488-4BAB-B2F6-C1806278CE16} = {E4FF4CE6-5831-450D-8006-0539353C030B}
 		{F4436A16-9488-4BAB-B2F6-C1806278CE16} = {E4FF4CE6-5831-450D-8006-0539353C030B}
-		{71907779-F1D1-4AA6-BA11-E990DB089841} = {1E816135-76C1-4255-BE3C-BF17895A65AA}
-		{B30622ED-9177-4930-8E64-2B2352D4D8DC} = {1E816135-76C1-4255-BE3C-BF17895A65AA}
+		{13DD041C-EE2D-4AF8-B43E-D7BFC7415E4D} = {1E816135-76C1-4255-BE3C-BF17895A65AA}
+		{71907779-F1D1-4AA6-BA11-E990DB089841} = {13DD041C-EE2D-4AF8-B43E-D7BFC7415E4D}
+		{B30622ED-9177-4930-8E64-2B2352D4D8DC} = {13DD041C-EE2D-4AF8-B43E-D7BFC7415E4D}
+		{1249EE2B-EB0D-411C-B311-53A7A22B7743} = {13DD041C-EE2D-4AF8-B43E-D7BFC7415E4D}
 	EndGlobalSection
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {D04B4AB0-CA33-42FD-A909-79966F9255C5}
 		SolutionGuid = {D04B4AB0-CA33-42FD-A909-79966F9255C5}