mirror of
https://github.com/cimgui/cimgui.git
synced 2025-08-14 05:38:29 +01:00
some generator.lua cleaning
This commit is contained in:
@@ -139,11 +139,7 @@ local prepro = {
|
||||
[ "IMGUI_DISABLE_OBSOLETE_FUNCTIONS" ]=false,
|
||||
},
|
||||
}
|
||||
--only one case is true
|
||||
local function prepro_boolifBAK(line)
|
||||
local ma = line:match("#ifndef%s+IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT") or line:match("#ifndef%s+ImTextureID")
|
||||
return not (ma==nil)
|
||||
end
|
||||
|
||||
local function prepro_boolif(pre,cond)
|
||||
local conds = prepro[pre]
|
||||
assert(conds,pre.." has no conds-----------------------------")
|
||||
@@ -1065,14 +1061,11 @@ local function gen_structs_and_enums_table(cdefs)
|
||||
return outtab, typedefs_dict
|
||||
end
|
||||
|
||||
local function generate_templates(code,templates,typedefs)
|
||||
local function generate_templates(code,templates)
|
||||
for k,v in pairs(templates) do
|
||||
--[[typedef struct ImVector{int Size;int Capacity;void* Data;} ImVector;]]
|
||||
local te = k:gsub("%s","_")
|
||||
te = te:gsub("%*","Ptr")
|
||||
--table.insert(code,"typedef struct ImVector_"..te.." {int Size;int Capacity;"..k.."* Data;} ImVector_"..te..";\n")
|
||||
table.insert(code,"typedef struct ImVector_"..te.." {int Size;int Capacity;"..k.."* Data;} ImVector_"..te..";\n")
|
||||
--table.insert(typedefs,"typedef struct ImVector_"..te.." ImVector_"..te..";\n")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1088,7 +1081,6 @@ local function gen_structs_and_enums(cdefs,templates)
|
||||
local innerstructs = {}
|
||||
local typedefs_table = {}
|
||||
local typedefs_dict = {}
|
||||
local linetypedefs = 1 --math.huge
|
||||
local outtab = {}
|
||||
-- Output the file
|
||||
--table.insert(outtab,"/////////////// BEGIN AUTOGENERATED SEGMENT\n")
|
||||
@@ -1118,7 +1110,7 @@ local function gen_structs_and_enums(cdefs,templates)
|
||||
if structnames[#structnames] == "ImVector" then
|
||||
if line:match(struct_closing_re) then
|
||||
table.insert(outtab,[[typedef struct ImVector{int Size;int Capacity;void* Data;} ImVector;]].."\n")
|
||||
generate_templates(outtab,templates,typedefs_table)
|
||||
generate_templates(outtab,templates)
|
||||
structnames[#structnames] = nil
|
||||
end
|
||||
break -- dont write
|
||||
@@ -1134,7 +1126,6 @@ local function gen_structs_and_enums(cdefs,templates)
|
||||
if #structnames < 2 then -- not inner
|
||||
if line:match("typedef") and line:match("ImDrawIdx") then --save typedefs of ImDrawIdx
|
||||
table.insert(typedefs_table,line..";\n")
|
||||
--linetypedefs = math.min(linetypedefs,#outtab)
|
||||
break
|
||||
end
|
||||
if (#structnames > 0) then
|
||||
@@ -1148,7 +1139,6 @@ local function gen_structs_and_enums(cdefs,templates)
|
||||
local struct_closed_name = line:match(struct_closed_re)
|
||||
if struct_closed_name then
|
||||
table.insert(typedefs_table,"typedef struct "..struct_closed_name.." "..struct_closed_name..";\n")
|
||||
--linetypedefs = math.min(linetypedefs,#outtab)
|
||||
typedefs_dict[struct_closed_name] = "struct "..struct_closed_name
|
||||
end
|
||||
end
|
||||
@@ -1165,7 +1155,6 @@ local function gen_structs_and_enums(cdefs,templates)
|
||||
local structname = structnames[#structnames]
|
||||
--st[#st + 1] = string.format("typedef struct %s %s;\n",structname,structname)
|
||||
table.insert(typedefs_table,string.format("typedef struct %s %s;\n",structname,structname))
|
||||
--linetypedefs = math.min(linetypedefs,#outtab)
|
||||
typedefs_dict[structname] = "struct "..structname
|
||||
structnames[#structnames] = nil
|
||||
end
|
||||
@@ -1173,7 +1162,6 @@ local function gen_structs_and_enums(cdefs,templates)
|
||||
local structname = structnames[#structnames]
|
||||
--table.insert(outtab,"typedef struct "..structname.." "..structname..";\n")
|
||||
table.insert(typedefs_table,"typedef struct "..structname.." "..structname..";\n")
|
||||
--linetypedefs = math.min(linetypedefs,#outtab)
|
||||
typedefs_dict[structname] = "struct "..structname
|
||||
structnames[#structnames] = nil
|
||||
end
|
||||
@@ -1193,9 +1181,10 @@ local function gen_structs_and_enums(cdefs,templates)
|
||||
for i,l in ipairs(typedefs_table) do
|
||||
if not uniques[l] then
|
||||
uniques[l] = true
|
||||
table.insert(outtab,linetypedefs,l)
|
||||
table.insert(outtab,1,l)
|
||||
end
|
||||
end
|
||||
--if templates then generate_templates(outtab,templates) end
|
||||
local cstructsstr = table.concat(outtab)
|
||||
cstructsstr = cstructsstr:gsub("\n+","\n") --several empty lines to one empty line
|
||||
return cstructsstr, typedefs_dict
|
||||
@@ -1451,11 +1440,11 @@ local function DefsByStruct(FP)
|
||||
for fun,defs in pairs(FP.defsT) do
|
||||
local stname = defs[1].stname
|
||||
structs[stname] = structs[stname] or {}
|
||||
table.insert(structs[stname],fun)
|
||||
end
|
||||
for st,funs in pairs(struct) do
|
||||
struct[st] = table.sort(funs)
|
||||
table.insert(structs[stname],defs)--fun)
|
||||
end
|
||||
-- for st,funs in pairs(struct) do
|
||||
-- struct[st] = table.sort(funs)
|
||||
-- end
|
||||
FP.defsBystruct = struct
|
||||
end
|
||||
local function AdjustArguments(FP)
|
||||
@@ -1557,7 +1546,7 @@ local ovstr = pFP:compute_overloads()
|
||||
AdjustArguments(pFP)
|
||||
ADDnonUDT(pFP)
|
||||
ADDdestructors(pFP)
|
||||
--DefsByStruct(pFP)
|
||||
|
||||
save_data("./output/overloads.txt",ovstr)
|
||||
typedefs_dict2 = cimgui_generation("",pSTP,pFP)
|
||||
--check arg detection failure if no name in function declaration
|
||||
@@ -1565,6 +1554,7 @@ check_arg_detection(pFP.defsT,typedefs_dict2)
|
||||
|
||||
|
||||
----------save fundefs in definitions.lua for using in bindings
|
||||
--DefsByStruct(pFP)
|
||||
set_defines(pFP.defsT)
|
||||
save_data("./output/definitions.lua",serializeTable("defs",pFP.defsT),"\nreturn defs")
|
||||
|
||||
|
Reference in New Issue
Block a user