diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index 8826cad..29f5e67 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -936,6 +936,18 @@ function M.Parser() function par.get_manuals(def) return par.manuals[def.ov_cimguiname] or par.manuals[def.cimguiname] end + function par:take_lines(cmd_line,names,compiler) + local pipe,err = io.popen(cmd_line,"r") + if not pipe then + error("could not execute COMPILER "..err) + end + local defines = {} + for line,loca,loca2 in M.location(pipe,names,defines,compiler) do + self:insert(line, tostring(loca)..":"..tostring(loca2)) + end + pipe:close() + return defines + end function par:do_parse() self:parseItems() self:gen_structs_and_enums() diff --git a/generator/generator.lua b/generator/generator.lua index 66b5825..ed51d88 100644 --- a/generator/generator.lua +++ b/generator/generator.lua @@ -367,30 +367,8 @@ local function parseImGuiHeader(header,names) parser.manuals = cimgui_manuals parser.UDTs = {"ImVec2","ImVec4","ImColor","ImRect"} - local pipe,err = io.popen(CPRE..header,"r") + local defines = parser:take_lines(CPRE..header,names,COMPILER) - if not pipe then - error("could not execute COMPILER "..err) - end - - local iterator = cpp2ffi.location - - --[[ - local tableo = {} - local line - repeat - line =pipe:read"*l" - table.insert(tableo,line) - until not line - cpp2ffi.save_data("cdefs1.lua",table.concat(tableo,"\n")) - --]] - for line,loca,loca2 in iterator(pipe,names,{},COMPILER) do - parser:insert(line, tostring(loca)..":"..tostring(loca2)) - --table.insert(tableo,line) - --print(loca,loca2) - end - --cpp2ffi.save_data("cdefs1.lua",table.concat(tableo)) - pipe:close() return parser end --generation @@ -464,20 +442,9 @@ if #implementations > 0 then extra_includes = extra_includes .. include_cmd .. inc .. " " end end + + local defines = parser2:take_lines(CPRE..extra_defines..extra_includes..source, {locati}, COMPILER) - local pipe,err = io.popen(CPRE..extra_defines..extra_includes..source,"r") - - if not pipe then - error("could not get file: "..err) - end - - local iterator = cpp2ffi.location - - for line,locat,linenum in iterator(pipe,{locati},{},COMPILER) do - --local line, comment = split_comment(line) - parser2:insert(line,tostring(locat)..":"..tostring(linenum)) - end - pipe:close() end parser2:do_parse()