mirror of
https://github.com/cimgui/cimgui.git
synced 2025-11-30 21:51:40 +00:00
cpp2ffi: gen_structs_c only used C types
This commit is contained in:
22
cimgui.h
22
cimgui.h
@@ -3820,23 +3820,14 @@ typedef union SDL_Event SDL_Event;
|
|||||||
|
|
||||||
|
|
||||||
#ifdef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
|
#ifdef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
|
||||||
typedef struct ImColor_c ImColor;
|
|
||||||
typedef struct ImRect_c ImRect;
|
|
||||||
typedef struct ImTextureRef_c ImTextureRef;
|
typedef struct ImTextureRef_c ImTextureRef;
|
||||||
typedef struct ImVec2_c ImVec2;
|
typedef struct ImVec2_c ImVec2;
|
||||||
typedef struct ImVec2i_c ImVec2i;
|
typedef struct ImVec2i_c ImVec2i;
|
||||||
typedef struct ImVec4_c ImVec4;
|
typedef struct ImVec4_c ImVec4;
|
||||||
|
typedef struct ImColor_c ImColor;
|
||||||
|
typedef struct ImRect_c ImRect;
|
||||||
#endif
|
#endif
|
||||||
#ifndef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
|
#ifndef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
|
||||||
typedef struct ImColor_c ImColor_c;
|
|
||||||
struct ImColor_c {
|
|
||||||
ImVec4 Value;
|
|
||||||
};
|
|
||||||
typedef struct ImRect_c ImRect_c;
|
|
||||||
struct ImRect_c {
|
|
||||||
ImVec2 Min;
|
|
||||||
ImVec2 Max;
|
|
||||||
};
|
|
||||||
typedef struct ImTextureRef_c ImTextureRef_c;
|
typedef struct ImTextureRef_c ImTextureRef_c;
|
||||||
struct ImTextureRef_c {
|
struct ImTextureRef_c {
|
||||||
ImTextureData* _TexData;
|
ImTextureData* _TexData;
|
||||||
@@ -3859,6 +3850,15 @@ struct ImVec4_c {
|
|||||||
float z;
|
float z;
|
||||||
float w;
|
float w;
|
||||||
};
|
};
|
||||||
|
typedef struct ImColor_c ImColor_c;
|
||||||
|
struct ImColor_c {
|
||||||
|
ImVec4_c Value;
|
||||||
|
};
|
||||||
|
typedef struct ImRect_c ImRect_c;
|
||||||
|
struct ImRect_c {
|
||||||
|
ImVec2_c Min;
|
||||||
|
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;
|
||||||
|
|||||||
@@ -1103,22 +1103,53 @@ local function get_nonPOD(FP)
|
|||||||
FP.structs_and_enums_table.nonPOD = nonPOD
|
FP.structs_and_enums_table.nonPOD = nonPOD
|
||||||
return nonPOD
|
return nonPOD
|
||||||
end
|
end
|
||||||
M.get_nonPOD = get_nonPOD
|
local function recur_calc_depth(FP, structs, k,n)
|
||||||
|
local struct = structs[k]
|
||||||
|
local n1 = n
|
||||||
|
for i,field in ipairs(struct) do
|
||||||
|
local typ = field.type:gsub("const ","")
|
||||||
|
typ = typ:gsub("*","")
|
||||||
|
if FP.nP_used[typ] then
|
||||||
|
n1 = math.max(n1,recur_calc_depth(FP, structs, typ,n+1))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return n1
|
||||||
|
end
|
||||||
local function gen_structs_c(FP)
|
local function gen_structs_c(FP)
|
||||||
local structs = FP.structs_and_enums_table.structs
|
local structs = FP.structs_and_enums_table.structs
|
||||||
|
--sort nP_used by dependencies and name
|
||||||
|
nP_used_sorted = {}
|
||||||
|
for k,v in pairs(FP.nP_used) do
|
||||||
|
nP_used_sorted[k] = recur_calc_depth(FP, structs, k, 1)
|
||||||
|
end
|
||||||
|
--M.prtable(nP_used_sorted)
|
||||||
|
local npsorted ={}
|
||||||
|
for k,n in pairs(nP_used_sorted) do insert(npsorted,k) end
|
||||||
|
table.sort(npsorted, function(a,b) return (nP_used_sorted[a] < nP_used_sorted[b]) or ((nP_used_sorted[a] == nP_used_sorted[b]) and (a<b)) end)
|
||||||
|
--M.prtable(npsorted)
|
||||||
|
--error"DEUG"
|
||||||
|
----------
|
||||||
local tabs = {}
|
local tabs = {}
|
||||||
local tabs_c = {}
|
local tabs_c = {}
|
||||||
--for k,v in pairs(FP.nP_used) do
|
--for k,v in pairs(FP.nP_used) do
|
||||||
M.table_do_sorted(FP.nP_used, function(k,v)
|
--M.table_do_sorted(FP.nP_used, function(k,v)
|
||||||
|
for _,k in ipairs(npsorted) do
|
||||||
insert(tabs,"typedef struct "..k.."_c "..k.."_c;")
|
insert(tabs,"typedef struct "..k.."_c "..k.."_c;")
|
||||||
insert(tabs_c,"typedef struct "..k.."_c "..k..";")
|
insert(tabs_c,"typedef struct "..k.."_c "..k..";")
|
||||||
insert(tabs,"struct "..k.."_c {")
|
insert(tabs,"struct "..k.."_c {")
|
||||||
local struct = structs[k]
|
local struct = structs[k]
|
||||||
for i,field in ipairs(struct) do
|
for i,field in ipairs(struct) do
|
||||||
insert(tabs," "..field.type.." "..field.name..";")
|
local typ = field.type:gsub("const ","")
|
||||||
|
typ = typ:gsub("*","")
|
||||||
|
if FP.nP_used[typ] then
|
||||||
|
local ftype = field.type:gsub(typ,typ.."_c")
|
||||||
|
insert(tabs," "..ftype.." "..field.name..";")
|
||||||
|
else
|
||||||
|
insert(tabs," "..field.type.." "..field.name..";")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
insert(tabs,"};")
|
insert(tabs,"};")
|
||||||
end)
|
end --)
|
||||||
if #tabs > 0 then
|
if #tabs > 0 then
|
||||||
insert(tabs,1,"#ifndef CIMGUI_DEFINE_ENUMS_AND_STRUCTS")
|
insert(tabs,1,"#ifndef CIMGUI_DEFINE_ENUMS_AND_STRUCTS")
|
||||||
insert(tabs,"#endif")
|
insert(tabs,"#endif")
|
||||||
|
|||||||
Reference in New Issue
Block a user