Skip to content

Commit 1743198

Browse files
committed
Fix native constructor function imports
1 parent 8e3caa1 commit 1743198

File tree

2 files changed

+43
-34
lines changed

2 files changed

+43
-34
lines changed

src/CodeGenerator/Program.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ static void Main(string[] args)
207207
string comment = null;
208208

209209
string structName = val["stname"].ToString();
210+
bool isConstructor = val.Value<bool>("constructor");
211+
if (isConstructor)
212+
{
213+
returnType = structName + "*";
214+
}
210215

211216
return new OverloadDefinition(
212217
exportedName,
@@ -216,7 +221,7 @@ static void Main(string[] args)
216221
returnType,
217222
structName,
218223
comment,
219-
enums);
224+
isConstructor);
220225
}).Where(od => od != null).ToArray();
221226

222227
return new FunctionDefinition(name, overloads);
@@ -361,8 +366,10 @@ static void Main(string[] args)
361366
continue;
362367
}
363368

364-
if (overload.FriendlyName == overload.StructName)
369+
if (overload.IsConstructor)
365370
{
371+
// TODO: Emit a static function on the type that invokes the native constructor.
372+
// Also, add a "Dispose" function or similar.
366373
continue;
367374
}
368375

@@ -636,7 +643,7 @@ private static void EmitOverload(
636643
preCallLines.Add($" }}");
637644
preCallLines.Add($" int {nativeArgName}_offset = Util.GetUtf8({textToEncode}, {nativeArgName}, {correctedIdentifier}_byteCount);");
638645
preCallLines.Add($" {nativeArgName}[{nativeArgName}_offset] = 0;");
639-
646+
640647
if (!hasDefault)
641648
{
642649
preCallLines.Add("}");
@@ -1126,6 +1133,7 @@ class OverloadDefinition
11261133
public string StructName { get; }
11271134
public bool IsMemberFunction { get; }
11281135
public string Comment { get; }
1136+
public bool IsConstructor { get; }
11291137

11301138
public OverloadDefinition(
11311139
string exportedName,
@@ -1135,7 +1143,7 @@ public OverloadDefinition(
11351143
string returnType,
11361144
string structName,
11371145
string comment,
1138-
EnumDefinition[] enums)
1146+
bool isConstructor)
11391147
{
11401148
ExportedName = exportedName;
11411149
FriendlyName = friendlyName;
@@ -1145,6 +1153,7 @@ public OverloadDefinition(
11451153
StructName = structName;
11461154
IsMemberFunction = structName != "ImGui";
11471155
Comment = comment;
1156+
IsConstructor = isConstructor;
11481157
}
11491158
}
11501159

src/ImGui.NET/Generated/ImGuiNative.gen.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace ImGuiNET
77
public static unsafe partial class ImGuiNative
88
{
99
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
10-
public static extern void CustomRect_CustomRect();
10+
public static extern CustomRect* CustomRect_CustomRect();
1111
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
1212
public static extern byte CustomRect_IsPacked(CustomRect* self);
1313
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
@@ -667,25 +667,25 @@ public static unsafe partial class ImGuiNative
667667
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ImColor_HSV_nonUDT2")]
668668
public static extern ImColor ImColor_HSV(ImColor* self, float h, float s, float v, float a);
669669
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
670-
public static extern void ImColor_ImColor();
670+
public static extern ImColor* ImColor_ImColor();
671671
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
672-
public static extern void ImColor_ImColorInt(int r, int g, int b, int a);
672+
public static extern ImColor* ImColor_ImColorInt(int r, int g, int b, int a);
673673
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
674-
public static extern void ImColor_ImColorU32(uint rgba);
674+
public static extern ImColor* ImColor_ImColorU32(uint rgba);
675675
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
676-
public static extern void ImColor_ImColorFloat(float r, float g, float b, float a);
676+
public static extern ImColor* ImColor_ImColorFloat(float r, float g, float b, float a);
677677
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
678-
public static extern void ImColor_ImColorVec4(Vector4 col);
678+
public static extern ImColor* ImColor_ImColorVec4(Vector4 col);
679679
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
680680
public static extern void ImColor_SetHSV(ImColor* self, float h, float s, float v, float a);
681681
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
682-
public static extern void ImDrawCmd_ImDrawCmd();
682+
public static extern ImDrawCmd* ImDrawCmd_ImDrawCmd();
683683
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
684684
public static extern void ImDrawData_Clear(ImDrawData* self);
685685
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
686686
public static extern void ImDrawData_DeIndexAllBuffers(ImDrawData* self);
687687
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
688-
public static extern void ImDrawData_ImDrawData();
688+
public static extern ImDrawData* ImDrawData_ImDrawData();
689689
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
690690
public static extern void ImDrawData_ScaleClipRects(ImDrawData* self, Vector2 sc);
691691
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
@@ -745,7 +745,7 @@ public static unsafe partial class ImGuiNative
745745
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ImDrawList_GetClipRectMin_nonUDT2")]
746746
public static extern Vector2 ImDrawList_GetClipRectMin(ImDrawList* self);
747747
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
748-
public static extern void ImDrawList_ImDrawList(IntPtr shared_data);
748+
public static extern ImDrawList* ImDrawList_ImDrawList(IntPtr shared_data);
749749
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
750750
public static extern void ImDrawList_PathArcTo(ImDrawList* self, Vector2 centre, float radius, float a_min, float a_max, int num_segments);
751751
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
@@ -815,7 +815,7 @@ public static unsafe partial class ImGuiNative
815815
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
816816
public static extern void ImFont_GrowIndex(ImFont* self, int new_size);
817817
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
818-
public static extern void ImFont_ImFont();
818+
public static extern ImFont* ImFont_ImFont();
819819
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
820820
public static extern byte ImFont_IsLoaded(ImFont* self);
821821
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
@@ -875,13 +875,13 @@ public static unsafe partial class ImGuiNative
875875
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
876876
public static extern void ImFontAtlas_GetTexDataAsRGBA32(ImFontAtlas* self, byte** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel);
877877
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
878-
public static extern void ImFontAtlas_ImFontAtlas();
878+
public static extern ImFontAtlas* ImFontAtlas_ImFontAtlas();
879879
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
880880
public static extern byte ImFontAtlas_IsBuilt(ImFontAtlas* self);
881881
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
882882
public static extern void ImFontAtlas_SetTexID(ImFontAtlas* self, IntPtr id);
883883
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
884-
public static extern void ImFontConfig_ImFontConfig();
884+
public static extern ImFontConfig* ImFontConfig_ImFontConfig();
885885
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
886886
public static extern void ImFontGlyphRangesBuilder_AddChar(ImFontGlyphRangesBuilder* self, ushort c);
887887
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
@@ -893,15 +893,15 @@ public static unsafe partial class ImGuiNative
893893
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
894894
public static extern byte ImFontGlyphRangesBuilder_GetBit(ImFontGlyphRangesBuilder* self, int n);
895895
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
896-
public static extern void ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder();
896+
public static extern ImFontGlyphRangesBuilder* ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder();
897897
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
898898
public static extern void ImFontGlyphRangesBuilder_SetBit(ImFontGlyphRangesBuilder* self, int n);
899899
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
900900
public static extern void ImGuiInputTextCallbackData_DeleteChars(ImGuiInputTextCallbackData* self, int pos, int bytes_count);
901901
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
902902
public static extern byte ImGuiInputTextCallbackData_HasSelection(ImGuiInputTextCallbackData* self);
903903
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
904-
public static extern void ImGuiInputTextCallbackData_ImGuiInputTextCallbackData();
904+
public static extern ImGuiInputTextCallbackData* ImGuiInputTextCallbackData_ImGuiInputTextCallbackData();
905905
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
906906
public static extern void ImGuiInputTextCallbackData_InsertChars(ImGuiInputTextCallbackData* self, int pos, byte* text, byte* text_end);
907907
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
@@ -911,21 +911,21 @@ public static unsafe partial class ImGuiNative
911911
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
912912
public static extern void ImGuiIO_ClearInputCharacters(ImGuiIO* self);
913913
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
914-
public static extern void ImGuiIO_ImGuiIO();
914+
public static extern ImGuiIO* ImGuiIO_ImGuiIO();
915915
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
916916
public static extern void ImGuiListClipper_Begin(ImGuiListClipper* self, int items_count, float items_height);
917917
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
918918
public static extern void ImGuiListClipper_End(ImGuiListClipper* self);
919919
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
920-
public static extern void ImGuiListClipper_ImGuiListClipper(int items_count, float items_height);
920+
public static extern ImGuiListClipper* ImGuiListClipper_ImGuiListClipper(int items_count, float items_height);
921921
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
922922
public static extern byte ImGuiListClipper_Step(ImGuiListClipper* self);
923923
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
924-
public static extern void ImGuiOnceUponAFrame_ImGuiOnceUponAFrame();
924+
public static extern ImGuiOnceUponAFrame* ImGuiOnceUponAFrame_ImGuiOnceUponAFrame();
925925
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
926926
public static extern void ImGuiPayload_Clear(ImGuiPayload* self);
927927
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
928-
public static extern void ImGuiPayload_ImGuiPayload();
928+
public static extern ImGuiPayload* ImGuiPayload_ImGuiPayload();
929929
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
930930
public static extern byte ImGuiPayload_IsDataType(ImGuiPayload* self, byte* type);
931931
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
@@ -963,7 +963,7 @@ public static unsafe partial class ImGuiNative
963963
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
964964
public static extern void ImGuiStorage_SetVoidPtr(ImGuiStorage* self, uint key, void* val);
965965
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
966-
public static extern void ImGuiStyle_ImGuiStyle();
966+
public static extern ImGuiStyle* ImGuiStyle_ImGuiStyle();
967967
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
968968
public static extern void ImGuiStyle_ScaleAllSizes(ImGuiStyle* self, float scale_factor);
969969
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
@@ -979,7 +979,7 @@ public static unsafe partial class ImGuiNative
979979
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
980980
public static extern byte* ImGuiTextBuffer_end(ImGuiTextBuffer* self);
981981
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
982-
public static extern void ImGuiTextBuffer_ImGuiTextBuffer();
982+
public static extern ImGuiTextBuffer* ImGuiTextBuffer_ImGuiTextBuffer();
983983
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
984984
public static extern void ImGuiTextBuffer_reserve(ImGuiTextBuffer* self, int capacity);
985985
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
@@ -991,25 +991,25 @@ public static unsafe partial class ImGuiNative
991991
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
992992
public static extern byte ImGuiTextFilter_Draw(ImGuiTextFilter* self, byte* label, float width);
993993
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
994-
public static extern void ImGuiTextFilter_ImGuiTextFilter(byte* default_filter);
994+
public static extern ImGuiTextFilter* ImGuiTextFilter_ImGuiTextFilter(byte* default_filter);
995995
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
996996
public static extern byte ImGuiTextFilter_IsActive(ImGuiTextFilter* self);
997997
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
998998
public static extern byte ImGuiTextFilter_PassFilter(ImGuiTextFilter* self, byte* text, byte* text_end);
999999
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
1000-
public static extern void ImVec2_ImVec2();
1000+
public static extern Vector2* ImVec2_ImVec2();
10011001
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
1002-
public static extern void ImVec2_ImVec2Float(float _x, float _y);
1002+
public static extern Vector2* ImVec2_ImVec2Float(float _x, float _y);
10031003
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
1004-
public static extern void ImVec4_ImVec4();
1004+
public static extern Vector4* ImVec4_ImVec4();
10051005
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
1006-
public static extern void ImVec4_ImVec4Float(float _x, float _y, float _z, float _w);
1006+
public static extern Vector4* ImVec4_ImVec4Float(float _x, float _y, float _z, float _w);
10071007
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
1008-
public static extern void Pair_PairInt(uint _key, int _val_i);
1008+
public static extern Pair* Pair_PairInt(uint _key, int _val_i);
10091009
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
1010-
public static extern void Pair_PairFloat(uint _key, float _val_f);
1010+
public static extern Pair* Pair_PairFloat(uint _key, float _val_f);
10111011
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
1012-
public static extern void Pair_PairPtr(uint _key, void* _val_p);
1012+
public static extern Pair* Pair_PairPtr(uint _key, void* _val_p);
10131013
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
10141014
public static extern byte* TextRange_begin(TextRange* self);
10151015
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
@@ -1019,8 +1019,8 @@ public static unsafe partial class ImGuiNative
10191019
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
10201020
public static extern void TextRange_split(TextRange* self, byte separator, ImVector* @out);
10211021
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
1022-
public static extern void TextRange_TextRange();
1022+
public static extern TextRange* TextRange_TextRange();
10231023
[DllImport("cimgui", CallingConvention = CallingConvention.Cdecl)]
1024-
public static extern void TextRange_TextRangeStr(byte* _b, byte* _e);
1024+
public static extern TextRange* TextRange_TextRangeStr(byte* _b, byte* _e);
10251025
}
10261026
}

0 commit comments

Comments
 (0)