From e2c64a1808512ac7c18b7e2402224e04f0d25523 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Mon, 24 Aug 2020 20:02:35 +0200 Subject: [PATCH] cpp2ffi: add json parsing for typedef struct inside namespace (STB_TexteditState) --- generator/cpp2ffi.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index 1b68abb..615d894 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -951,6 +951,11 @@ function M.Parser() if derived then print(stname,"derived from",derived) end + --try to get name from typedef structs + if not stname and stru:match("typedef struct") then + stname = stru:match("%b{}%s*(%S+)%s*;") + end + if not stname then print(stru) error"could not get stname" @@ -1186,6 +1191,28 @@ function M.Parser() end end end + + --get structs in namespace + for i,it in ipairs(itemsarr) do + if it.re_name == "namespace_re" then + local nsp = it.item:match("%b{}"):sub(2,-2) + local namespace = it.item:match("namespace%s+(%S+)") + local nspparr,itemsnsp = parseItems(nsp, nil, it.locat ) + for insp,itnsp in ipairs(nspparr) do + if itnsp.re_name == "struct_re" or itnsp.re_name == "typedef_st_re" then + local cleanst,structname,strtab = self:clean_struct(itnsp.item, itnsp.locat) + if structname and not self.typenames[structname] then + outtab.structs[structname] = {} + outtab.locations[structname] = itnsp.locat + self.order[structname]=i + for j=3,#strtab-1 do + self:parse_struct_line(strtab[j],outtab.structs[structname]) + end + end + end + end + end + end --inner_structs for i,it in ipairs(self.inerstructs) do