mirror of
https://github.com/cimgui/cimgui.git
synced 2025-08-11 04:18:29 +01:00
generator.lua: preparation of imgui_internal inclusion
This commit is contained in:
@@ -220,6 +220,7 @@ local function func_header_generate(FP)
|
|||||||
for k,v in pairs(FP.embeded_structs) do
|
for k,v in pairs(FP.embeded_structs) do
|
||||||
table.insert(outtab,"typedef "..v.." "..k..";\n")
|
table.insert(outtab,"typedef "..v.." "..k..";\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
for ttype,v in pairs(FP.templates) do
|
for ttype,v in pairs(FP.templates) do
|
||||||
for ttypein,_ in pairs(v) do
|
for ttypein,_ in pairs(v) do
|
||||||
local te = ttypein:gsub("%s","_")
|
local te = ttypein:gsub("%s","_")
|
||||||
@@ -471,12 +472,10 @@ local function cimgui_generation(parser)
|
|||||||
local hstrfile = read_data"./cimgui_template.h"
|
local hstrfile = read_data"./cimgui_template.h"
|
||||||
|
|
||||||
local outpre,outpost = parser:gen_structs_and_enums()
|
local outpre,outpost = parser:gen_structs_and_enums()
|
||||||
--parser.templates get completely defined here
|
|
||||||
--cpp2ffi.prtable(parser.templates)
|
|
||||||
|
|
||||||
local outtab = {}
|
local outtab = {}
|
||||||
generate_templates(outtab,parser.templates)
|
generate_templates(outtab,parser.templates)
|
||||||
local cstructsstr = outpre..table.concat(outtab,"")..outpost
|
local cstructsstr = outpre..table.concat(outtab,"")..outpost..(extra or "")
|
||||||
|
|
||||||
hstrfile = hstrfile:gsub([[#include "imgui_structs%.h"]],cstructsstr)
|
hstrfile = hstrfile:gsub([[#include "imgui_structs%.h"]],cstructsstr)
|
||||||
local cfuncsstr = func_header_generate(parser)
|
local cfuncsstr = func_header_generate(parser)
|
||||||
@@ -555,45 +554,54 @@ print("------------------generation with "..COMPILER.."------------------------"
|
|||||||
--local parser1 = parseImGuiHeader([[headers.h]],{[[imgui]],[[imgui_internal]],[[imstb_textedit]]})
|
--local parser1 = parseImGuiHeader([[headers.h]],{[[imgui]],[[imgui_internal]],[[imstb_textedit]]})
|
||||||
local parser1 = parseImGuiHeader([[../imgui/imgui.h]],{[[imgui]]})
|
local parser1 = parseImGuiHeader([[../imgui/imgui.h]],{[[imgui]]})
|
||||||
parser1:do_parse()
|
parser1:do_parse()
|
||||||
--table.sort(parser1.funcdefs, function(a,b) return a.cimguiname < b.cimguiname end)
|
|
||||||
--parser1:dump_alltypes()
|
|
||||||
--parser1:printItems()
|
|
||||||
--[[
|
|
||||||
for i,v in ipairs(parser1.itemsarr) do
|
|
||||||
if v.item:match"ImRect" then
|
|
||||||
print(v.re_name)
|
|
||||||
print(v.item)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
--]]
|
|
||||||
|
|
||||||
----------- add ImGuiContext from imgui_internal.h
|
----------- add ImGuiContext from imgui_internal.h
|
||||||
--[=[
|
--[=[
|
||||||
local parser1i = parseImGuiHeader([[../imgui/imgui_internal.h]],{[[imgui_internal]],[[imstb_textedit]]})
|
local parser1i = parseImGuiHeader([[../imgui/imgui_internal.h]],{[[imgui_internal]],[[imstb_textedit]]})
|
||||||
parser1i:do_parse()
|
parser1i:do_parse()
|
||||||
for i,v in ipairs(parser1i.itemsarr) do
|
local p1isten = parser1i:gen_structs_and_enums_table()
|
||||||
if v.re_name == "vardef_re" then
|
|
||||||
table.insert(parser1.itemsarr,v)
|
local needed = {ImGuiContext = {type = "ImGuiContext", kind = "structs", order = parser1i.order["ImGuiContext"]}}
|
||||||
elseif v.re_name == "enum_re" then
|
local function RecurseNeeded(Ini,IniKind)
|
||||||
table.insert(parser1.itemsarr,v)
|
for i,v in ipairs(p1isten[IniKind][Ini]) do
|
||||||
elseif v.re_name == "typedef_re" then
|
local kind = p1isten.enums[v.type] and "enums" or p1isten.structs[v.type] and "structs"
|
||||||
table.insert(parser1.itemsarr,v)
|
if kind then
|
||||||
elseif v.re_name == "struct_re" or v.re_name=="enum_re" then
|
needed[v.type] = {type = v.type, kind = kind, order = parser1i.order[v.type]}
|
||||||
if v.item:match"^[%s\n\r]*struct%s*ImGuiContext" then
|
RecurseNeeded(v.type,kind)
|
||||||
table.insert(parser1.itemsarr,v)
|
|
||||||
else
|
|
||||||
--print(v.item)
|
|
||||||
local newitem = v.item:match"(struct%s*%S+)"
|
|
||||||
print("reduced",newitem)
|
|
||||||
if newitem:match"ImPool" then
|
|
||||||
table.insert(parser1.itemsarr,{re_name="vardef_re",item=newitem..";"})
|
|
||||||
else
|
|
||||||
table.insert(parser1.itemsarr,v)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--cpp2ffi.prtable(parser1i.itemsarr)
|
|
||||||
|
RecurseNeeded("ImGuiContext","structs")
|
||||||
|
|
||||||
|
|
||||||
|
local ordered_needed = {}
|
||||||
|
for k,v in pairs(needed) do
|
||||||
|
table.insert(ordered_needed,v)
|
||||||
|
end
|
||||||
|
table.sort(ordered_needed, function(a,b) return a.order < b.order end)
|
||||||
|
|
||||||
|
for i,vv in ipairs(ordered_needed) do
|
||||||
|
print(vv.order,vv.type)
|
||||||
|
local v = parser1i.itemsarr[vv.order]
|
||||||
|
|
||||||
|
if v.item:match"^[%s\n\r]*struct%s*ImGuiContext" then
|
||||||
|
--add enum keyword where necessary
|
||||||
|
print"setting enum keyword------------------------"
|
||||||
|
local newitem = ""
|
||||||
|
for line in v.item:gmatch("([^\n]+)") do
|
||||||
|
local typen = line:match"^%s*(%S+)"
|
||||||
|
if p1isten.enums[typen] then
|
||||||
|
print("add enum",typen)
|
||||||
|
newitem = newitem.."\nenum"..line
|
||||||
|
else
|
||||||
|
newitem = newitem.."\n"..line
|
||||||
|
end
|
||||||
|
end
|
||||||
|
v.item = newitem
|
||||||
|
end
|
||||||
|
table.insert(parser1.itemsarr,v)
|
||||||
|
end
|
||||||
--]=]
|
--]=]
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
@@ -628,24 +636,7 @@ save_data("./output/typedefs_dict.lua",serializeTableF(parser1.typedefs_dict))
|
|||||||
-- assert(def.ov_cimguiname)
|
-- assert(def.ov_cimguiname)
|
||||||
-- end
|
-- end
|
||||||
-- end
|
-- end
|
||||||
------------imgui_internal.h
|
|
||||||
--[=[
|
|
||||||
--prepare parser
|
|
||||||
local parser1i = parseImGuiHeader([[../imgui/imgui_internal.h]],[[imgui_internal]])
|
|
||||||
|
|
||||||
parser1i:do_parse()
|
|
||||||
cpp2ffi.prtable(parser1i.itemsarr)
|
|
||||||
local outtab = {}
|
|
||||||
generate_templates(outtab,parser1i.templates)
|
|
||||||
|
|
||||||
local int_structs_and_enums_table = parser1i:gen_structs_and_enums_table()
|
|
||||||
outtab[#outtab +1] = "struct ImGuiContext\n{\n"
|
|
||||||
for i,v in ipairs(int_structs_and_enums_table.structs.ImGuiContext) do
|
|
||||||
outtab[#outtab +1] = " "..v.type.." "..v.name..";\n"
|
|
||||||
end
|
|
||||||
outtab[#outtab +1]="}\n"
|
|
||||||
print(table.concat(outtab))
|
|
||||||
--]=]
|
|
||||||
--=================================Now implementations
|
--=================================Now implementations
|
||||||
|
|
||||||
local parser2
|
local parser2
|
||||||
|
Reference in New Issue
Block a user