Compare commits

..

2 Commits

Author SHA1 Message Date
sonoro1234
22bcd46a7c update README.md 2025-11-10 14:08:08 +01:00
sonoro1234
c4b7680882 cpp2ffi: genConversion take care of ptr to nonPOD fields, avoid infinite recursion on gen_structs_c 2025-11-10 13:53:03 +01:00
5 changed files with 23 additions and 12 deletions

View File

@@ -17,6 +17,10 @@ Notes:
* 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. * 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.
* Current overloaded function names can be found in (https://github.com/cimgui/cimgui/blob/master/generator/output/overloads.txt) * Current overloaded function names can be found in (https://github.com/cimgui/cimgui/blob/master/generator/output/overloads.txt)
#changes
* 10/11/2025: Functions returning and taking as argument no POD structs is now doing a conversion internally to allow ARM64 compilation.
# compilation # compilation
* clone * clone
@@ -60,7 +64,8 @@ Notes:
* retref : is set if original return type is a reference. (will be a pointer in cimgui) * retref : is set if original return type is a reference. (will be a pointer in cimgui)
* argsT : an array of collections (each one with type: argument type and name: the argument name, when the argument is a function pointer also ret: return type and signature: the function signature) * argsT : an array of collections (each one with type: argument type and name: the argument name, when the argument is a function pointer also ret: return type and signature: the function signature)
* args : a string of argsT concatenated and separated by commas * args : a string of argsT concatenated and separated by commas
* call_args : a string with the argument names separated by commas for calling imgui function * call_args_old : a string with the argument names separated by commas for calling imgui function
* call_args : call_args_old with conversion added.
* defaults : a collection in which key is argument name and value is the default value. * defaults : a collection in which key is argument name and value is the default value.
* manual : will be true if this function is hand-written (not generated) * manual : will be true if this function is hand-written (not generated)
* skipped : will be true if this function is not generated (and not hand-written) * skipped : will be true if this function is not generated (and not hand-written)
@@ -70,7 +75,7 @@ Notes:
* realdestructor : is set if the function is a destructor for a class * realdestructor : is set if the function is a destructor for a class
* templated : is set if the function belongs to a templated class (ImVector) * templated : is set if the function belongs to a templated class (ImVector)
* templatedgen: is set if the function belongs to a struct generated from template (ImVector_ImWchar) * templatedgen: is set if the function belongs to a struct generated from template (ImVector_ImWchar)
* nonUDT : if present the original function was returning a user defined type so that signature has been changed to accept a pointer to the UDT as first argument. * nonUDT : if present the original function was returning a user defined type.
* location : name of the header file and linenumber this function comes from. (imgui:000, internal:123, imgui_impl_xxx:123) * location : name of the header file and linenumber this function comes from. (imgui:000, internal:123, imgui_impl_xxx:123)
* is_static_function : is setted when it is an struct static function. * is_static_function : is setted when it is an struct static function.
### structs_and_enums description ### structs_and_enums description
@@ -91,7 +96,6 @@ Notes:
* use whatever method is in ImGui c++ namespace in the original [imgui.h](https://github.com/ocornut/imgui/blob/master/imgui.h) by prepending `ig` * use whatever method is in ImGui c++ namespace in the original [imgui.h](https://github.com/ocornut/imgui/blob/master/imgui.h) by prepending `ig`
* methods have the same parameter list and return values (where possible) * methods have the same parameter list and return values (where possible)
* functions that belong to a struct have an extra first argument with a pointer to the struct. * functions that belong to a struct have an extra first argument with a pointer to the struct.
* where a function returns UDT (user defined type) by value some compilers complain so the function is generated accepting a pointer to the UDT type as the first argument (or second if belongs to a struct).
* constructors return pointer to struct and has been named Struct_name_Struct_name * constructors return pointer to struct and has been named Struct_name_Struct_name
# usage with backends # usage with backends

View File

@@ -3818,7 +3818,6 @@ struct SDL_Window;
typedef union SDL_Event SDL_Event; typedef union SDL_Event SDL_Event;
#endif // CIMGUI_DEFINE_ENUMS_AND_STRUCTS #endif // CIMGUI_DEFINE_ENUMS_AND_STRUCTS
#ifdef CIMGUI_DEFINE_ENUMS_AND_STRUCTS #ifdef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
typedef struct ImTextureRef_c ImTextureRef; typedef struct ImTextureRef_c ImTextureRef;
typedef struct ImVec2_c ImVec2; typedef struct ImVec2_c ImVec2;
@@ -3860,6 +3859,8 @@ struct ImRect_c {
ImVec2_c Max; ImVec2_c Max;
}; };
#endif #endif
#ifndef CIMGUI_DEFINE_ENUMS_AND_STRUCTS #ifndef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
typedef struct ImGuiTextFilter::ImGuiTextRange ImGuiTextRange; typedef struct ImGuiTextFilter::ImGuiTextRange ImGuiTextRange;
typedef ImStb::STB_TexteditState STB_TexteditState; typedef ImStb::STB_TexteditState STB_TexteditState;

View File

@@ -49,6 +49,7 @@ struct SDL_Window;
typedef union SDL_Event SDL_Event; typedef union SDL_Event SDL_Event;
#endif // CIMGUI_DEFINE_ENUMS_AND_STRUCTS #endif // CIMGUI_DEFINE_ENUMS_AND_STRUCTS
PLACE_STRUCTS_C
#include "auto_funcs.h" #include "auto_funcs.h"

View File

@@ -1104,12 +1104,13 @@ local function get_nonPOD(FP)
return nonPOD return nonPOD
end end
local function recur_calc_depth(FP, structs, k,n) local function recur_calc_depth(FP, structs, k,n)
--print("recur_calc_depth",k,n)
local struct = structs[k] local struct = structs[k]
local n1 = n local n1 = n
for i,field in ipairs(struct) do for i,field in ipairs(struct) do
local typ = field.type:gsub("const ","") local typ = field.type:gsub("const ","")
typ = typ:gsub("*","") typ = typ:gsub("*","")
if FP.nP_used[typ] then if k~=typ and FP.nP_used[typ] then
n1 = math.max(n1,recur_calc_depth(FP, structs, typ,n+1)) n1 = math.max(n1,recur_calc_depth(FP, structs, typ,n+1))
end end
end end
@@ -1163,12 +1164,16 @@ local function gen_structs_c(FP)
return table.concat(tabs_c,"\n").."\n"..table.concat(tabs,"\n") return table.concat(tabs_c,"\n").."\n"..table.concat(tabs,"\n")
--return table.concat(tabs,"\n") --return table.concat(tabs,"\n")
end end
local function gen_field_conversion(tab, struct, FP, prefix) local function gen_field_conversion(tab, struct, FP, to,prefix)
prefix = prefix or "" prefix = prefix or ""
local structs = FP.structs_and_enums_table.structs local structs = FP.structs_and_enums_table.structs
for i,field in ipairs(struct) do for i,field in ipairs(struct) do
local ftype = field.type:gsub("*","")
if FP.nP_used[field.type] then if FP.nP_used[field.type] then
gen_field_conversion(tab, structs[field.type],FP, prefix..field.name..".") gen_field_conversion(tab, structs[field.type],FP, to,prefix..field.name..".")
elseif FP.nP_used[ftype] then
local ftypec = field.type:gsub(ftype,not to and (ftype.."_c") or ftype)
insert(tab, " dest."..prefix..field.name.." = reinterpret_cast<"..ftypec..">(src."..prefix..field.name..");")
else else
insert(tab," dest."..prefix..field.name.." = src."..prefix..field.name..";") insert(tab," dest."..prefix..field.name.." = src."..prefix..field.name..";")
end end
@@ -1183,14 +1188,14 @@ local function genConversions(FP)
insert(convers,"{") insert(convers,"{")
insert(convers," "..k.." dest;") insert(convers," "..k.." dest;")
local struct = structs[k] local struct = structs[k]
gen_field_conversion(convers,struct,FP) gen_field_conversion(convers,struct,FP, true)
insert(convers," return dest;") insert(convers," return dest;")
insert(convers,"}") insert(convers,"}")
insert(convers,"static inline "..k.."_c ConvertFromCPP_"..k.."(const "..k.."& src)") insert(convers,"static inline "..k.."_c ConvertFromCPP_"..k.."(const "..k.."& src)")
insert(convers,"{") insert(convers,"{")
insert(convers," "..k.."_c dest;") insert(convers," "..k.."_c dest;")
local struct = structs[k] local struct = structs[k]
gen_field_conversion(convers,struct,FP) gen_field_conversion(convers,struct,FP, false)
insert(convers," return dest;") insert(convers," return dest;")
insert(convers,"}") insert(convers,"}")
end) end)
@@ -3128,8 +3133,8 @@ local function func_header_generate(FP)
--outtabf = M.header_subs_nonPOD(FP,outtabf) --outtabf = M.header_subs_nonPOD(FP,outtabf)
local cfuncsstr = table.concat(outtab)..outtabf local cfuncsstr = table.concat(outtab)..outtabf
cfuncsstr = cfuncsstr:gsub("\n+","\n") --several empty lines to one empty line cfuncsstr = cfuncsstr:gsub("\n+","\n") --several empty lines to one empty line
local structs_c = FP:gen_structs_c()
return structs_c..cfuncsstr return cfuncsstr
end end
M.func_header_generate = func_header_generate M.func_header_generate = func_header_generate

View File

@@ -286,7 +286,6 @@ local function cimgui_generation(parser)
local tdt = parser:generate_templates() local tdt = parser:generate_templates()
--local cstructsstr = "\n//7777estio es outpre\n"..outpre.."\n///////////////tdt\n"..tdt.."\n////////////////////outpost\n"..outpost
local cstructsstr = outpre..tdt..outpost local cstructsstr = outpre..tdt..outpost
if gdefines.IMGUI_HAS_DOCK then if gdefines.IMGUI_HAS_DOCK then
@@ -307,6 +306,7 @@ local function cimgui_generation(parser)
cstructsstr = colapse_defines(cstructsstr, "IMGUI_ENABLE_FREETYPE") cstructsstr = colapse_defines(cstructsstr, "IMGUI_ENABLE_FREETYPE")
hstrfile = hstrfile:gsub([[#include "imgui_structs%.h"]],cstructsstr) hstrfile = hstrfile:gsub([[#include "imgui_structs%.h"]],cstructsstr)
hstrfile = hstrfile:gsub([[PLACE_STRUCTS_C]],parser:gen_structs_c())
local cfuncsstr = func_header_generate(parser) local cfuncsstr = func_header_generate(parser)
cfuncsstr = colapse_defines(cfuncsstr, "IMGUI_ENABLE_FREETYPE") cfuncsstr = colapse_defines(cfuncsstr, "IMGUI_ENABLE_FREETYPE")
hstrfile = hstrfile:gsub([[#include "auto_funcs%.h"]],cfuncsstr) hstrfile = hstrfile:gsub([[#include "auto_funcs%.h"]],cfuncsstr)