From b2958db4abf433e081045c0b82baaea2e7f06d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20Collado?= <42522226+Krixtalx@users.noreply.github.com> Date: Thu, 17 Oct 2024 14:05:27 +0200 Subject: [PATCH] Fix String array marshal type. (#8) * Fix String array marshal type. Some changes from running generator with previous commits. * Fix bool* -> byte* * Restored all native libraries. * Minor fix in a variable name. --------- Co-authored-by: jcant0n --- Generator/Common/Helpers.cs | 4 ++-- .../Evergine.Bindings.Imgui/Generated/Funtions.cs | 7 +++---- Generator/Evergine.Bindings.Imgui/Generated/Structs.cs | 2 +- Generator/ImguiGen/Program.cs | 10 +++++----- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Generator/Common/Helpers.cs b/Generator/Common/Helpers.cs index 75e593c..40ca8b1 100644 --- a/Generator/Common/Helpers.cs +++ b/Generator/Common/Helpers.cs @@ -100,7 +100,7 @@ private static string ConvertToBasicTypes(string type, Family family) return "byte"; } case "bool*": - return "bool*"; + return "byte*"; case "char*": return "byte*"; case "const char*": @@ -176,7 +176,7 @@ private static string ConvertToBasicTypes(string type, Family family) switch (family) { case Family.param: - return "[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPUTF8Str)] string[]"; + return "[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] string[]"; case Family.ret: return "string[]"; case Family.field: diff --git a/Generator/Evergine.Bindings.Imgui/Generated/Funtions.cs b/Generator/Evergine.Bindings.Imgui/Generated/Funtions.cs index 35a158b..58585e1 100644 --- a/Generator/Evergine.Bindings.Imgui/Generated/Funtions.cs +++ b/Generator/Evergine.Bindings.Imgui/Generated/Funtions.cs @@ -488,8 +488,7 @@ public static unsafe partial class ImguiNative public static extern bool ImGuiStorage_GetBool(ImGuiStorage* self, uint key, [MarshalAs(UnmanagedType.I1)] bool default_val); [DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)] - [return:MarshalAs(UnmanagedType.I1)] - public static extern bool ImGuiStorage_GetBoolRef(ImGuiStorage* self, uint key, [MarshalAs(UnmanagedType.I1)] bool default_val); + public static extern byte* ImGuiStorage_GetBoolRef(ImGuiStorage* self, uint key, [MarshalAs(UnmanagedType.I1)] bool default_val); [DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)] public static extern float ImGuiStorage_GetFloat(ImGuiStorage* self, uint key, float default_val); @@ -760,7 +759,7 @@ public static unsafe partial class ImguiNative [DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)] - public static extern bool igCombo_Str_arr([MarshalAs(UnmanagedType.LPUTF8Str)] string label, int* current_item, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPUTF8Str)] string[] items, int items_count, int popup_max_height_in_items); + public static extern bool igCombo_Str_arr([MarshalAs(UnmanagedType.LPUTF8Str)] string label, int* current_item, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] string[] items, int items_count, int popup_max_height_in_items); [DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)] @@ -1320,7 +1319,7 @@ public static unsafe partial class ImguiNative [DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)] - public static extern bool igListBox_Str_arr([MarshalAs(UnmanagedType.LPUTF8Str)] string label, int* current_item, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPUTF8Str)] string[] items, int items_count, int height_in_items); + public static extern bool igListBox_Str_arr([MarshalAs(UnmanagedType.LPUTF8Str)] string label, int* current_item, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] string[] items, int items_count, int height_in_items); [DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)] diff --git a/Generator/Evergine.Bindings.Imgui/Generated/Structs.cs b/Generator/Evergine.Bindings.Imgui/Generated/Structs.cs index 2226ecb..1f453e2 100644 --- a/Generator/Evergine.Bindings.Imgui/Generated/Structs.cs +++ b/Generator/Evergine.Bindings.Imgui/Generated/Structs.cs @@ -1933,7 +1933,7 @@ public bool GetBool(uint key, [MarshalAs(UnmanagedType.I1)] bool default_val = t return ImguiNative.ImGuiStorage_GetBool(self, key, default_val); } - public bool GetBoolRef(uint key, [MarshalAs(UnmanagedType.I1)] bool default_val = true) + public byte* GetBoolRef(uint key, [MarshalAs(UnmanagedType.I1)] bool default_val = true) { return ImguiNative.ImGuiStorage_GetBoolRef(self, key, default_val); } diff --git a/Generator/ImguiGen/Program.cs b/Generator/ImguiGen/Program.cs index bca1407..72dea13 100644 --- a/Generator/ImguiGen/Program.cs +++ b/Generator/ImguiGen/Program.cs @@ -14,18 +14,18 @@ static void Main(string[] args) string @namespace = "Imgui"; string libraryName = "cimgui"; - var implotVersion = Specification.FromFiles(structs_and_enums_json, definitions_json); + var imguiVersion = Specification.FromFiles(structs_and_enums_json, definitions_json); - if (implotVersion != null) + if (imguiVersion != null) { // Enums - CSCodeWriter.WriteEnums(outputPath, @namespace, implotVersion); + CSCodeWriter.WriteEnums(outputPath, @namespace, imguiVersion); // Structs - CSCodeWriter.WriteStructs(outputPath, @namespace, implotVersion); + CSCodeWriter.WriteStructs(outputPath, @namespace, imguiVersion); // Functions - CSCodeWriter.WriteFuntions(outputPath, @namespace, libraryName, implotVersion); + CSCodeWriter.WriteFuntions(outputPath, @namespace, libraryName, imguiVersion); // Delegates CSCodeWriter.WriteInlineDelegates(outputPath, @namespace);