diff --git a/cimgui.h b/cimgui.h index 43c2f2d..a43a5b1 100644 --- a/cimgui.h +++ b/cimgui.h @@ -4989,7 +4989,7 @@ CIMGUI_API void igImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[2 /////////////////////////hand written functions //no LogTextV -CIMGUI_API void igLogText(CONST char *fmt, ...); +CIMGUI_API void igLogText(const char *fmt, ...); //no appendfV CIMGUI_API void ImGuiTextBuffer_appendf(struct ImGuiTextBuffer *buffer, const char *fmt, ...); //for getting FLT_MAX in bindings diff --git a/generator/cimgui_template.h b/generator/cimgui_template.h index e46202f..d977cad 100644 --- a/generator/cimgui_template.h +++ b/generator/cimgui_template.h @@ -47,7 +47,7 @@ typedef union SDL_Event SDL_Event; /////////////////////////hand written functions //no LogTextV -CIMGUI_API void igLogText(CONST char *fmt, ...); +CIMGUI_API void igLogText(const char *fmt, ...); //no appendfV CIMGUI_API void ImGuiTextBuffer_appendf(struct ImGuiTextBuffer *buffer, const char *fmt, ...); //for getting FLT_MAX in bindings diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index 81c812b..2c231d2 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -673,14 +673,18 @@ local function CleanImU32(def) for i=1,#bb do res = res + bb[i] end return res end +local function moveptr(line) + line = line:gsub("%s*%*","%*") + line = line:gsub("%*([%w_])","%* %1") + line = line:gsub("(%(%*)%s","%1") + return line +end local function parseFunction(self,stname,itt,namespace,locat) local lineorig,comment = split_comment(itt.item) line = clean_spaces(lineorig) --move * - line = line:gsub("%s*%*","%*") - line = line:gsub("%*([%w_])","%* %1") - line = line:gsub("(%(%*)%s","%1") + line = moveptr(line) --print(line) --clean implemetation @@ -719,6 +723,21 @@ local function parseFunction(self,stname,itt,namespace,locat) error"parseFunction not getting args" end + --get manuals args and ret + local cname = self.getCname(stname,funcname, namespace) --cimguiname + local manpars = self.manuals[cname] + local ismanual + if manpars then + if type(manpars) == "boolean" then + print("warning: unable to get args and ret from "..cname) + print("did you forgot to use set_manuals? ") + else + ismanual = true + args, ret = manpars.args, manpars.ret + args = moveptr(args) + ret = moveptr(ret) + end + end local argsp = args:sub(2,-2).."," local argsTa = {} @@ -734,6 +753,8 @@ local function parseFunction(self,stname,itt,namespace,locat) argsTa[#argsTa+1] = tynam end end + + --- templates in args for i,ar in ipairs(argsTa) do --TODO several diferent templates @@ -747,7 +768,7 @@ local function parseFunction(self,stname,itt,namespace,locat) end argsTa[i] = te and code2 or ar --ar:gsub("<([%w_%*%s]+)>",te) --ImVector end - + --get typ, name and defaults local functype_re = "^%s*[%w%s%*]+%(%*%s*[%w_]+%)%([^%(%)]*%)" local functype_reex = "^(%s*[%w%s%*]+)%(%*%s*([%w_]+)%)(%([^%(%)]*%))" @@ -807,6 +828,7 @@ local function parseFunction(self,stname,itt,namespace,locat) end end + local argsArr = argsTa2 --recreate argscsinpars, call_args and signature from argsArr @@ -838,7 +860,7 @@ local function parseFunction(self,stname,itt,namespace,locat) caar = "()" signat = "()" .. (extraconst or "") end - + --if ismanual then print("manual",asp, caar, signat) end ------------------------------ if not ret and stname then --must be constructors @@ -871,6 +893,9 @@ local function parseFunction(self,stname,itt,namespace,locat) ar.default = nil end end + + --if ismanual then M.prtable(argsArr) end + defT.templated = self.typenames[stname] and true defT.namespace = namespace defT.cimguiname = cimguiname @@ -901,6 +926,7 @@ local function parseFunction(self,stname,itt,namespace,locat) -- end end defsT[cimguiname][signat] = defT + end local function itemsCount(items) print"------------items" @@ -913,8 +939,8 @@ end local function AdjustArguments(FP) for fun,defs in pairs(FP.defsT) do - --struct function but no constructors or static functions - if defs[1].stname~="" and defs[1].ret and not defs[1].is_static_function then + --struct function but no constructors or static functions or manuals + if defs[1].stname~="" and defs[1].ret and not defs[1].is_static_function and not defs[1].manual then --print("adjusting",fun) for i,def in ipairs(defs) do local empty = def.args:match("^%(%)") --no args @@ -1408,6 +1434,20 @@ function M.Parser() function par:printItems() printItems(items) end + function par:set_manuals(manuals, modulen, erase) + erase = erase or {"CIMGUI_API"} + local moddata = read_data("./"..modulen.."_template.h") + for k,v in pairs(manuals) do + local ret = moddata:match("([^%(%):,\n;]+[%*%s])%s?~?"..k.."%b()") + for i,ww in ipairs(erase) do + ret = ret:gsub(ww,"") + end + local args = moddata:match(k.."%s*(%b())") + manuals[k] = {args = args, ret = ret} + --print(k,args,ret) + end + self.manuals = manuals + end par.parseFunction = parseFunction local uniques = {} local function check_unique_typedefs(l,uniques) diff --git a/generator/generator.lua b/generator/generator.lua index 5745755..1212769 100644 --- a/generator/generator.lua +++ b/generator/generator.lua @@ -318,7 +318,8 @@ local function parseImGuiHeader(header,names) return pre..funcname end parser.cname_overloads = cimgui_overloads - parser.manuals = cimgui_manuals + --parser.manuals = cimgui_manuals + parser:set_manuals(cimgui_manuals, "cimgui") parser.skipped = cimgui_skipped parser.UDTs = {"ImVec2","ImVec4","ImColor","ImRect"} --parser.gen_template_typedef = gen_template_typedef --use auto diff --git a/generator/output/definitions.json b/generator/output/definitions.json index 879cf3b..9e2e3fe 100644 --- a/generator/output/definitions.json +++ b/generator/output/definitions.json @@ -9773,23 +9773,23 @@ ], "ImGuiTextBuffer_appendf": [ { - "args": "(ImGuiTextBuffer* self,const char* fmt,...)", + "args": "(struct ImGuiTextBuffer* buffer, const char* fmt,...)", "argsT": [ { - "name": "self", - "type": "ImGuiTextBuffer*" + "name": "buffer", + "type": "struct ImGuiTextBuffer*" }, { "name": "fmt", - "type": "const char*" + "type": " const char*" }, { "name": "...", "type": "..." } ], - "argsoriginal": "(const char* fmt,...)", - "call_args": "(fmt,...)", + "argsoriginal": "(struct ImGuiTextBuffer* buffer, const char* fmt, ...)", + "call_args": "(buffer,fmt,...)", "cimguiname": "ImGuiTextBuffer_appendf", "defaults": {}, "funcname": "appendf", @@ -9798,7 +9798,7 @@ "manual": true, "ov_cimguiname": "ImGuiTextBuffer_appendf", "ret": "void", - "signature": "(const char*,...)", + "signature": "(struct ImGuiTextBuffer*, const char*,...)", "stname": "ImGuiTextBuffer" } ], @@ -28904,7 +28904,7 @@ "type": "..." } ], - "argsoriginal": "(const char* fmt,...)", + "argsoriginal": "(const char* fmt, ...)", "call_args": "(fmt,...)", "cimguiname": "igLogText", "defaults": {}, diff --git a/generator/output/definitions.lua b/generator/output/definitions.lua index 96f890e..ca9165b 100644 --- a/generator/output/definitions.lua +++ b/generator/output/definitions.lua @@ -8225,19 +8225,19 @@ defs["ImGuiTextBuffer_append"][1]["stname"] = "ImGuiTextBuffer" defs["ImGuiTextBuffer_append"]["(const char*,const char*)"] = defs["ImGuiTextBuffer_append"][1] defs["ImGuiTextBuffer_appendf"] = {} defs["ImGuiTextBuffer_appendf"][1] = {} -defs["ImGuiTextBuffer_appendf"][1]["args"] = "(ImGuiTextBuffer* self,const char* fmt,...)" +defs["ImGuiTextBuffer_appendf"][1]["args"] = "(struct ImGuiTextBuffer* buffer, const char* fmt,...)" defs["ImGuiTextBuffer_appendf"][1]["argsT"] = {} defs["ImGuiTextBuffer_appendf"][1]["argsT"][1] = {} -defs["ImGuiTextBuffer_appendf"][1]["argsT"][1]["name"] = "self" -defs["ImGuiTextBuffer_appendf"][1]["argsT"][1]["type"] = "ImGuiTextBuffer*" +defs["ImGuiTextBuffer_appendf"][1]["argsT"][1]["name"] = "buffer" +defs["ImGuiTextBuffer_appendf"][1]["argsT"][1]["type"] = "struct ImGuiTextBuffer*" defs["ImGuiTextBuffer_appendf"][1]["argsT"][2] = {} defs["ImGuiTextBuffer_appendf"][1]["argsT"][2]["name"] = "fmt" -defs["ImGuiTextBuffer_appendf"][1]["argsT"][2]["type"] = "const char*" +defs["ImGuiTextBuffer_appendf"][1]["argsT"][2]["type"] = " const char*" defs["ImGuiTextBuffer_appendf"][1]["argsT"][3] = {} defs["ImGuiTextBuffer_appendf"][1]["argsT"][3]["name"] = "..." defs["ImGuiTextBuffer_appendf"][1]["argsT"][3]["type"] = "..." -defs["ImGuiTextBuffer_appendf"][1]["argsoriginal"] = "(const char* fmt,...)" -defs["ImGuiTextBuffer_appendf"][1]["call_args"] = "(fmt,...)" +defs["ImGuiTextBuffer_appendf"][1]["argsoriginal"] = "(struct ImGuiTextBuffer* buffer, const char* fmt, ...)" +defs["ImGuiTextBuffer_appendf"][1]["call_args"] = "(buffer,fmt,...)" defs["ImGuiTextBuffer_appendf"][1]["cimguiname"] = "ImGuiTextBuffer_appendf" defs["ImGuiTextBuffer_appendf"][1]["defaults"] = {} defs["ImGuiTextBuffer_appendf"][1]["funcname"] = "appendf" @@ -8246,9 +8246,9 @@ defs["ImGuiTextBuffer_appendf"][1]["location"] = "imgui:2709" defs["ImGuiTextBuffer_appendf"][1]["manual"] = true defs["ImGuiTextBuffer_appendf"][1]["ov_cimguiname"] = "ImGuiTextBuffer_appendf" defs["ImGuiTextBuffer_appendf"][1]["ret"] = "void" -defs["ImGuiTextBuffer_appendf"][1]["signature"] = "(const char*,...)" +defs["ImGuiTextBuffer_appendf"][1]["signature"] = "(struct ImGuiTextBuffer*, const char*,...)" defs["ImGuiTextBuffer_appendf"][1]["stname"] = "ImGuiTextBuffer" -defs["ImGuiTextBuffer_appendf"]["(const char*,...)"] = defs["ImGuiTextBuffer_appendf"][1] +defs["ImGuiTextBuffer_appendf"]["(struct ImGuiTextBuffer*, const char*,...)"] = defs["ImGuiTextBuffer_appendf"][1] defs["ImGuiTextBuffer_appendfv"] = {} defs["ImGuiTextBuffer_appendfv"][1] = {} defs["ImGuiTextBuffer_appendfv"][1]["args"] = "(ImGuiTextBuffer* self,const char* fmt,va_list args)" @@ -24514,7 +24514,7 @@ defs["igLogText"][1]["argsT"][1]["type"] = "const char*" defs["igLogText"][1]["argsT"][2] = {} defs["igLogText"][1]["argsT"][2]["name"] = "..." defs["igLogText"][1]["argsT"][2]["type"] = "..." -defs["igLogText"][1]["argsoriginal"] = "(const char* fmt,...)" +defs["igLogText"][1]["argsoriginal"] = "(const char* fmt, ...)" defs["igLogText"][1]["call_args"] = "(fmt,...)" defs["igLogText"][1]["cimguiname"] = "igLogText" defs["igLogText"][1]["defaults"] = {}