From eee47a982eca1508e7d6dfb7cd005cf5392473e0 Mon Sep 17 00:00:00 2001 From: sonoro1234 Date: Tue, 4 Aug 2026 20:48:40 +0200 Subject: [PATCH] cpp2ffi: add VARGS0 to variadic struct functions, dont return on void return --- README.md | 3 ++- cimgui.cpp | 24 ++++++++++++------------ generator/cpp2ffi.lua | 26 ++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 270f4b4..5b97ed8 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ History: Initially cimgui was developed by Stephan Dilly as hand-written code but lately turned into an auto-generated version by sonoro1234 in order to keep up with imgui more easily (letting the user select the desired branch and commit) Notes: -* currently this wrapper is based on version [1.92.9 of Dear ImGui with internal api] +* currently this wrapper is based on version [1.92.9b of Dear ImGui with internal api] * only functions, structs and enums from imgui.h (an optionally imgui_internal.h) are wrapped. * if you are interested in imgui backends you should look [LuaJIT-ImGui](https://github.com/sonoro1234/LuaJIT-ImGui) project. * All naming is algorithmic except for those names that were coded in cimgui_overloads table (https://github.com/cimgui/cimgui/blob/master/generator/generator.lua#L60). In the official version this table is empty. @@ -108,6 +108,7 @@ Notes: * [LuaJIT-ImGui](https://github.com/sonoro1234/LuaJIT-ImGui) * [cimgui-go](https://github.com/AllenDang/cimgui-go) * [Hexa.NET.ImGui](https://github.com/HexaEngine/Hexa.NET.ImGui) +* [EvergineTeam/ImGui](https://github.com/EvergineTeam/ImGui.Net) * [dear-imgui-rs](https://github.com/Latias94/dear-imgui-rs) * [CImGui.jl](https://github.com/Gnimuc/CImGui.jl) * [ImGui.NET](https://github.com/mellinoe/ImGui.NET) diff --git a/cimgui.cpp b/cimgui.cpp index fa5440a..eeadfec 100644 --- a/cimgui.cpp +++ b/cimgui.cpp @@ -663,7 +663,7 @@ CIMGUI_API void igText(const char* fmt,...) #ifdef CIMGUI_VARGS0 CIMGUI_API void igText0(const char* fmt) { - return igText(fmt); + igText(fmt); } #endif CIMGUI_API void igTextV(const char* fmt,va_list args) @@ -680,7 +680,7 @@ CIMGUI_API void igTextColored(const ImVec4_c col,const char* fmt,...) #ifdef CIMGUI_VARGS0 CIMGUI_API void igTextColored0(const ImVec4_c col,const char* fmt) { - return igTextColored(col,fmt); + igTextColored(col,fmt); } #endif CIMGUI_API void igTextColoredV(const ImVec4_c col,const char* fmt,va_list args) @@ -697,7 +697,7 @@ CIMGUI_API void igTextDisabled(const char* fmt,...) #ifdef CIMGUI_VARGS0 CIMGUI_API void igTextDisabled0(const char* fmt) { - return igTextDisabled(fmt); + igTextDisabled(fmt); } #endif CIMGUI_API void igTextDisabledV(const char* fmt,va_list args) @@ -714,7 +714,7 @@ CIMGUI_API void igTextWrapped(const char* fmt,...) #ifdef CIMGUI_VARGS0 CIMGUI_API void igTextWrapped0(const char* fmt) { - return igTextWrapped(fmt); + igTextWrapped(fmt); } #endif CIMGUI_API void igTextWrappedV(const char* fmt,va_list args) @@ -731,7 +731,7 @@ CIMGUI_API void igLabelText(const char* label,const char* fmt,...) #ifdef CIMGUI_VARGS0 CIMGUI_API void igLabelText0(const char* label,const char* fmt) { - return igLabelText(label,fmt); + igLabelText(label,fmt); } #endif CIMGUI_API void igLabelTextV(const char* label,const char* fmt,va_list args) @@ -748,7 +748,7 @@ CIMGUI_API void igBulletText(const char* fmt,...) #ifdef CIMGUI_VARGS0 CIMGUI_API void igBulletText0(const char* fmt) { - return igBulletText(fmt); + igBulletText(fmt); } #endif CIMGUI_API void igBulletTextV(const char* fmt,va_list args) @@ -1261,7 +1261,7 @@ CIMGUI_API void igSetTooltip(const char* fmt,...) #ifdef CIMGUI_VARGS0 CIMGUI_API void igSetTooltip0(const char* fmt) { - return igSetTooltip(fmt); + igSetTooltip(fmt); } #endif CIMGUI_API void igSetTooltipV(const char* fmt,va_list args) @@ -1282,7 +1282,7 @@ CIMGUI_API void igSetItemTooltip(const char* fmt,...) #ifdef CIMGUI_VARGS0 CIMGUI_API void igSetItemTooltip0(const char* fmt) { - return igSetItemTooltip(fmt); + igSetItemTooltip(fmt); } #endif CIMGUI_API void igSetItemTooltipV(const char* fmt,va_list args) @@ -1519,7 +1519,7 @@ CIMGUI_API void igLogText(const char* fmt,...) #ifdef CIMGUI_VARGS0 CIMGUI_API void igLogText0(const char* fmt) { - return igLogText(fmt); + igLogText(fmt); } #endif CIMGUI_API void igLogTextV(const char* fmt,va_list args) @@ -1884,7 +1884,7 @@ CIMGUI_API void igDebugLog(const char* fmt,...) #ifdef CIMGUI_VARGS0 CIMGUI_API void igDebugLog0(const char* fmt) { - return igDebugLog(fmt); + igDebugLog(fmt); } #endif CIMGUI_API void igDebugLogV(const char* fmt,va_list args) @@ -3195,7 +3195,7 @@ CIMGUI_API void igImFormatStringToTempBuffer(const char** out_buf,const char** o #ifdef CIMGUI_VARGS0 CIMGUI_API void igImFormatStringToTempBuffer0(const char** out_buf,const char** out_buf_end,const char* fmt) { - return igImFormatStringToTempBuffer(out_buf,out_buf_end,fmt); + igImFormatStringToTempBuffer(out_buf,out_buf_end,fmt); } #endif CIMGUI_API void igImFormatStringToTempBufferV(const char** out_buf,const char** out_buf_end,const char* fmt,va_list args) @@ -5944,7 +5944,7 @@ CIMGUI_API void igTextAligned(float align_x,float size_x,const char* fmt,...) #ifdef CIMGUI_VARGS0 CIMGUI_API void igTextAligned0(float align_x,float size_x,const char* fmt) { - return igTextAligned(align_x,size_x,fmt); + igTextAligned(align_x,size_x,fmt); } #endif CIMGUI_API void igTextAlignedV(float align_x,float size_x,const char* fmt,va_list args) diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index fbac6b2..acbf855 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -3929,7 +3929,9 @@ local function ImGui_f_implementation(def) table.insert(outtab, "#ifdef CIMGUI_VARGS0\n") table.insert(outtab, "CIMGUI_API".." "..def.ret.." "..def.ov_cimguiname.."0"..paramListWithoutDots(def.args).."\n") table.insert(outtab, "{\n") - table.insert(outtab, " return "..def.ov_cimguiname..paramListWithoutDots(def.call_args_old)..";\n") + local returnword = "return " + if def.ret=="void" then returnword = "" end + table.insert(outtab, " "..returnword..def.ov_cimguiname..paramListWithoutDots(def.call_args_old)..";\n") table.insert(outtab, "}\n") table.insert(outtab, "#endif\n") elseif def.nonUDT then @@ -3976,6 +3978,16 @@ local function struct_f_implementation(def) if def.ret~="void" then table.insert(outtab," return ret;\n") end + table.insert(outtab,"}\n") + -- For variadic functions we add a function implementation with zero argumets, for compatibility with languages such as C#. + table.insert(outtab, "#ifdef CIMGUI_VARGS0\n") + table.insert(outtab, "CIMGUI_API".." "..def.ret.." "..def.ov_cimguiname.."0"..paramListWithoutDots(def.args).."\n") + table.insert(outtab, "{\n") + local returnword = "return " + if def.ret=="void" then returnword = "" end + table.insert(outtab, " "..returnword..def.ov_cimguiname.."(self,"..paramListWithoutDots(def.call_args_old):sub(2,-1)..";\n") + table.insert(outtab, "}\n") + table.insert(outtab, "#endif\n") elseif def.nonUDT then if def.nonUDT == 1 then --table.insert(outtab," *pOut = self->"..def.funcname..def.call_args..";\n") @@ -3991,10 +4003,12 @@ local function struct_f_implementation(def) insert(outtab," static auto opq = "..ptret.."self->"..def.funcname..def.call_args..";\n") insert(outtab," return &opq;\n") end + table.insert(outtab,"}\n") else --standard struct table.insert(outtab," return "..ptret.."self->"..def.funcname..def.call_args..";\n") + table.insert(outtab,"}\n") end - table.insert(outtab,"}\n") + return table.concat(outtab, "") end local function func_implementation(FP) @@ -4107,7 +4121,6 @@ local function func_header_generate_funcs(FP) local outtab = {} for _,t in ipairs(FP.funcdefs) do - if t.cimguiname then local cimf = FP.defsT[t.cimguiname] local def = cimf[t.signature] @@ -4119,7 +4132,6 @@ local function func_header_generate_funcs(FP) local manual = FP.get_manuals(def) if not custom and not manual and not def.templated and not FP.get_skipped(def) --and not (FP.opaque_structs[def.stname] and not def.is_static_function) then - local addcoment = "" --def.comment or "" local empty = def.args:match("^%(%)") --no args if def.constructor then @@ -4143,6 +4155,12 @@ local function func_header_generate_funcs(FP) end else table.insert(outtab,"CIMGUI_API "..ret.." "..def.ov_cimguiname..def.args..";"..addcoment.."\n") + if def.isvararg then + -- For variadic functions we add a function implementation with zero argumets, for compatibility with languages such as C#. + table.insert(outtab, "#ifdef CIMGUI_VARGS0\n") + table.insert(outtab, "CIMGUI_API".." "..ret.." "..def.ov_cimguiname.."0"..paramListWithoutDots(def.args)..";\n") + table.insert(outtab, "#endif\n") + end end end end