cpp2ffi: embeded_enums typedef generation (for ImGuizmo) and gen_structs_and_enums keeps strings (to avoid running twice)

This commit is contained in:
Victor Bombi
2020-08-29 14:28:17 +02:00
parent b6bc895d01
commit a68f4a93ae
2 changed files with 12 additions and 4 deletions

View File

@@ -1006,6 +1006,7 @@ function M.Parser()
local outtabpre = {} local outtabpre = {}
local typedefs_table = {} local typedefs_table = {}
self.inerstructs = {} self.inerstructs = {}
self.embeded_enums = {}
--first typedefs --first typedefs
for i,it in ipairs(itemsarr) do for i,it in ipairs(itemsarr) do
@@ -1031,6 +1032,7 @@ function M.Parser()
table.insert(outtab,itnsp.item) table.insert(outtab,itnsp.item)
elseif itnsp.re_name == "enum_re" then elseif itnsp.re_name == "enum_re" then
local enumname, enumbody = itnsp.item:match"^%s*enum%s+([^%s;{}]+)[%s\n\r]*(%b{})" local enumname, enumbody = itnsp.item:match"^%s*enum%s+([^%s;{}]+)[%s\n\r]*(%b{})"
self.embeded_enums[enumname] = namespace.."::"..enumname
table.insert(outtab,"\ntypedef enum ".. enumbody..enumname..";") table.insert(outtab,"\ntypedef enum ".. enumbody..enumname..";")
end end
end end
@@ -1073,7 +1075,9 @@ function M.Parser()
end end
--check arg detection failure if no name in function declaration --check arg detection failure if no name in function declaration
check_arg_detection(self.defsT,self.typedefs_dict) check_arg_detection(self.defsT,self.typedefs_dict)
return table.concat(outtabpre,""),table.concat(outtab,"") local outtabprest, outtabst = table.concat(outtabpre,""),table.concat(outtab,"")
self.structs_and_enums = {outtabprest, outtabst}
return outtabprest, outtabst
end end
----------- -----------
function par:parse_struct_line(line,outtab) function par:parse_struct_line(line,outtab)
@@ -1689,7 +1693,11 @@ 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 k,v in pairs(FP.embeded_enums) do
table.insert(outtab,"typedef "..v.." "..k..";\n")
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","_")

View File

@@ -226,7 +226,7 @@ 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.structs_and_enums[1],parser.structs_and_enums[2]
parser.templates.ImVector.T = nil parser.templates.ImVector.T = nil
cpp2ffi.prtable(parser.templates) cpp2ffi.prtable(parser.templates)
cpp2ffi.prtable(parser.typenames) cpp2ffi.prtable(parser.typenames)
@@ -426,7 +426,7 @@ if #implementations > 0 then
-- save ./cimgui_impl.h -- save ./cimgui_impl.h
local cfuncsstr = func_header_impl_generate(parser2) local cfuncsstr = func_header_impl_generate(parser2)
local cstructstr1,cstructstr2 = parser2:gen_structs_and_enums() local cstructstr1,cstructstr2 = parser2.structs_and_enums[1], parser2.structs_and_enums[2]
save_data("./output/cimgui_impl.h",cstructstr1,cstructstr2,cfuncsstr) save_data("./output/cimgui_impl.h",cstructstr1,cstructstr2,cfuncsstr)
----------save fundefs in impl_definitions.lua for using in bindings ----------save fundefs in impl_definitions.lua for using in bindings