From fdc9511bd713d791f4d0d98c5a83b4bdd212b406 Mon Sep 17 00:00:00 2001 From: sonoro1234 Date: Sat, 29 Jan 2022 18:08:57 +0100 Subject: [PATCH] cpp2ffi: simplify gen_template_typedef --- generator/cpp2ffi.lua | 11 ++++++++++- generator/generator.lua | 10 ++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index 2427f38..f108938 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -1629,7 +1629,7 @@ function M.Parser() for j=3,#strtab-1 do self:parse_struct_line(strtab[j],self.templated_structs[structname],comstab[j]) end - M.prtable(self.templated_structs[structname]) + --M.prtable(self.templated_structs[structname]) else print("skipped unnamed struct",structname) end @@ -1848,6 +1848,15 @@ function M.Parser() table.insert(self.funcdefs,v) end end + function par:gentemplatetypedef(ttype,te,newte) + --print("gentemplatetypedef",ttype,te,newte) + if not newte then return "" end + self.templates_done = self.templates_done or {} + self.templates_done[ttype] = self.templates_done[ttype] or {} + if self.templates_done[ttype][te] then return "" end + self.templates_done[ttype][te] = true + return self:gen_template_typedef(ttype,te,newte) --given by user + end return par end diff --git a/generator/generator.lua b/generator/generator.lua index b6433fb..298a017 100644 --- a/generator/generator.lua +++ b/generator/generator.lua @@ -250,14 +250,8 @@ end ----------custom ImVector templates local table_do_sorted = cpp2ffi.table_do_sorted -local function gentemplatetypedef(self,ttype,te,newte) +local function gen_template_typedef(self,ttype,te,newte) local code = {} - --print("gentemplatetypedef",ttype,te,newte) - if not newte then return "" end - self.templates_done = self.templates_done or {} - self.templates_done[ttype] = self.templates_done[ttype] or {} - if self.templates_done[ttype][te] then return "" end - self.templates_done[ttype][te] = true if ttype == "ImVector" then table.insert(code,"typedef struct ImVector_"..newte.." {int Size;int Capacity;"..te.."* Data;} ImVector_"..newte..";\n") elseif ttype == "ImPool" then @@ -379,7 +373,7 @@ local function parseImGuiHeader(header,names) parser.cname_overloads = cimgui_overloads parser.manuals = cimgui_manuals parser.UDTs = {"ImVec2","ImVec4","ImColor","ImRect"} - parser.gentemplatetypedef = gentemplatetypedef + parser.gen_template_typedef = gen_template_typedef local defines = parser:take_lines(CPRE..header,names,COMPILER)