Skip to content

Commit

Permalink
Fix String array marshal type. (#8)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Krixtalx and jcant0n authored Oct 17, 2024
1 parent 6e42bb7 commit b2958db
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Generator/Common/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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*":
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions Generator/Evergine.Bindings.Imgui/Generated/Funtions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion Generator/Evergine.Bindings.Imgui/Generated/Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions Generator/ImguiGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b2958db

Please sign in to comment.