From ce239ed53f28f7e113fe639b98fca72ea3a02b27 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Fri, 29 Jan 2021 18:52:22 +0100 Subject: [PATCH 01/12] cpp2ffi: overload naming char* -> Chpt (was Str) avoids clash with ImStr - > Str --- generator/cpp2ffi.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index 478e777..37c24e2 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -487,7 +487,7 @@ local function typetoStr(typ) typ = typ:gsub("unsigned%s","u") typ = typ:gsub("const%s","")--"c") typ = typ:gsub("%s+","_") - typ = typ:gsub("charPtr","Str") + typ = typ:gsub("charPtr","Chpt") typ = typ:gsub("int","Int") typ = typ:gsub("bool","Bool") typ = typ:gsub("float","Float") From a9928295dbdd7d4ed3e18ef328e8fa0cc67eb951 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Sat, 30 Jan 2021 14:37:34 +0100 Subject: [PATCH 02/12] generator: keep IMGUI_HAS_IMSTR definition --- generator/generator.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/generator/generator.lua b/generator/generator.lua index 670a419..a9cd1ce 100644 --- a/generator/generator.lua +++ b/generator/generator.lua @@ -313,6 +313,9 @@ local function cimgui_generation(parser) if gdefines.IMGUI_HAS_DOCK then cstructsstr = cstructsstr.."\n#define IMGUI_HAS_DOCK 1\n" end + if gdefines.IMGUI_HAS_IMSTR then + cstructsstr = cstructsstr.."\n#define IMGUI_HAS_IMSTR 1\n" + end hstrfile = hstrfile:gsub([[#include "imgui_structs%.h"]],cstructsstr) local cfuncsstr = func_header_generate(parser) @@ -333,13 +336,13 @@ end -------------------------------------------------------- --get imgui.h version and IMGUI_HAS_DOCK-------------------------- --get some defines wont work for cl ---------------- -gdefines = get_defines{"IMGUI_VERSION","FLT_MAX","FLT_MIN","IMGUI_HAS_DOCK"} +gdefines = get_defines{"IMGUI_VERSION","FLT_MAX","FLT_MIN","IMGUI_HAS_DOCK","IMGUI_HAS_IMSTR"} --this will work for cl local pipe,err = io.open("../imgui/imgui.h","r") if not pipe then error("could not open file:"..err) end -local imgui_version,has_dock +local imgui_version,has_dock,has_imstr while true do local line = pipe:read"*l" if not line then break end @@ -349,11 +352,15 @@ while true do if not has_dock then has_dock = line:match([[#define%s+IMGUI_HAS_DOCK]])--%s*(".+")]]) end - if imgui_version and has_dock then break end + if not has_imstr then + has_imstr = line:match([[#define%s+IMGUI_HAS_IMSTR]])--%s*(".+")]]) + end + if imgui_version and has_dock and has_imstr then break end end pipe:close() if has_dock then gdefines.IMGUI_HAS_DOCK = true end +if has_imstr then gdefines.IMGUI_HAS_IMSTR = true end cimgui_header = cimgui_header:gsub("XXX",imgui_version) if INTERNAL_GENERATION then @@ -369,6 +376,7 @@ if gdefines.IMGUI_HAS_DOCK then ]] end +print("IMGUI_HAS_IMSTR",gdefines.IMGUI_HAS_IMSTR) print("IMGUI_HAS_DOCK",gdefines.IMGUI_HAS_DOCK) print("IMGUI_VERSION",imgui_version) From a64de2e303c7cc322082993e11800943a1608ea9 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Sat, 30 Jan 2021 19:29:25 +0100 Subject: [PATCH 03/12] cpp2ffi: add ADDIMSTR_S function for making const char* versions of ImStr arguments --- generator/cpp2ffi.lua | 66 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index 37c24e2..1ea45fd 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -769,6 +769,70 @@ local function AdjustArguments(FP) end end end +local function ADDIMSTR_S(FP) + local defsT = FP.defsT + local newcdefs = {} + for numcdef,t in ipairs(FP.funcdefs) do + newcdefs[#newcdefs+1] = t + if t.cimguiname then + local cimf = defsT[t.cimguiname] + local defT = cimf[t.signature] + + --if isIMSTR return generate _S version + local isIMSTR = false + for i,arg in ipairs(defT.argsT) do + if arg.type == "ImStr" or arg.type == "const ImStr" then isIMSTR=true;break end + end + --if defT.ret=="ImVec2" or defT.ret=="ImVec4" or defT.ret=="ImColor" then + --if isIMSTR then print(t.cimguiname,defT.ov_cimguiname,defT.argsoriginal,"isIMSTR") end + if isIMSTR then + --passing as a pointer arg + local defT2 = {} + --first strings + for k,v in pairs(defT) do + defT2[k] = v + end + --then argsT table + defT2.argsT = {} + for k,v in ipairs(defT.argsT) do + local typ = (v.type == "ImStr" or v.type == "const ImStr") and "const char*" or v.type + table.insert(defT2.argsT,{type=typ,name=v.name}) + end + defT2.args = defT.args:gsub("const ImStr","const char*") + defT2.args = defT2.args:gsub("ImStr","const char*") + --recreate call_args for wrapping into ImStr + local caar + if #defT.argsT > 0 then + caar = "(" + for i,v in ipairs(defT.argsT) do + local name = v.type == "ImStr" and "ImStr("..v.name..")" or v.name + if v.ret then --function pointer + caar = caar .. name .. "," + else + local callname = v.reftoptr and "*"..name or name + caar = caar .. callname .. "," + end + end + caar = caar:sub(1,-2)..")" + else + caar = "()" + end + defT2.call_args = caar + ------------------ + defT2.signature = defT.signature:gsub("ImStr","const char*").."_S" + defT2.ov_cimguiname = (defT2.ov_cimguiname or defT2.cimguiname).."_S" + defT2.isIMSTR_S = 1 + + --replace + cimf[#cimf+1] = defT2 + cimf[defT2.signature] = defT2 + newcdefs[#newcdefs+1] = {stname=t.stname,funcname=t.funcname,args=defT2.args,signature=defT2.signature,cimguiname=defT2.cimguiname,ret =defT2.ret} + end + else print("not cimguiname in");M.prtable(t) + end + end + FP.funcdefs = newcdefs +end local function ADDnonUDT(FP) local defsT = FP.defsT --local newcdefs = {} @@ -1525,8 +1589,10 @@ function M.Parser() end) --print(numoverloaded, "overloaded") table.insert(strt,string.format("%d overloaded",numoverloaded)) + ADDIMSTR_S(self) AdjustArguments(self) ADDnonUDT(self) + --ADDdestructors(self) self.overloadstxt = table.concat(strt,"\n") end From afdbb6b79904c667e7eba2e3149a3abe9b2a0e05 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Sat, 30 Jan 2021 19:31:14 +0100 Subject: [PATCH 04/12] test and backend_test prepared for IMGUI_HAS_IMSTR --- backend_test/main.c | 8 +++++++- test/main.c | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/backend_test/main.c b/backend_test/main.c index f405d08..c7525dc 100644 --- a/backend_test/main.c +++ b/backend_test/main.c @@ -11,7 +11,13 @@ #include #include - +#ifdef IMGUI_HAS_IMSTR +#define igBegin igBegin_S +#define igSliderFloat igSliderFloat_S +#define igCheckbox igCheckbox_S +#define igColorEdit3 igColorEdit3_S +#define igButton igButton_S +#endif SDL_Window *window = NULL; diff --git a/test/main.c b/test/main.c index 0a9d0c5..b7c7f1f 100644 --- a/test/main.c +++ b/test/main.c @@ -2,6 +2,11 @@ #include #include "../cimgui.h" +#ifdef IMGUI_HAS_IMSTR +#define igBegin igBegin_S +#define igSliderFloat igSliderFloat_S +#endif + int main(void) { assert(igDebugCheckVersionAndDataLayout(igGetVersion(), sizeof(ImGuiIO), sizeof(ImGuiStyle), From 383ebf3a7abd97748ae9017f99dc9c6c0f8db750 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Mon, 1 Feb 2021 13:05:55 +0100 Subject: [PATCH 05/12] cpp2ffi: ADDiMSTR_S before overload naming and copy defaults, overload_Algo improvement --- generator/cpp2ffi.lua | 79 +++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 25 deletions(-) diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index 1ea45fd..d49934a 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -414,14 +414,13 @@ local function parseItems(txt,linenumdict, itparent, dumpit) end M.parseItems = parseItems local function name_overloadsAlgo(v) + local aa = {} local bb = {} local done = {} local maxnum = 0 for i,t in ipairs(v) do bb[i] = "" - --local signature = t.signature:sub(2,-2) -- without parenthesis - --inside parenthesis local signature = t.signature:match("%b()") signature = signature:sub(2,-2) --add const function @@ -430,47 +429,52 @@ local function name_overloadsAlgo(v) end aa[i] = {} local num = 1 - --for typec in t.signature:gmatch(".-([^,%(%s]+)[,%)]") do - --for typec in t.signature:gmatch(".-([^,%(]+)[,%)]") do - --for typec in signature:gmatch(".-([^,]+),?") do for typec in signature:gsub("(%(.-%))", function(x) return x:gsub(",","\0") end):gmatch(".-([^,]+),?") do - --typec = typec:gsub aa[i][num] = typec:gsub("%z+", ",") num = num + 1 end num = num - 1 maxnum = (num > maxnum) and num or maxnum end - + for l=1,maxnum do local keys = {} local diferent = true local equal = true for i=1,#v do aa[i][l] = aa[i][l] or "nil" - keys[aa[i][l]] = 1 + (aa[i][l] and keys[aa[i][l]] or 0) + keys[aa[i][l]] = 1 + (keys[aa[i][l]] or 0) if not done[i] then - for j=i+1,#v do - if not done[j] then - if aa[i][l] == aa[j][l] then - diferent = false - else - equal = false + for j=i+1,#v do + if not done[j] then + if aa[i][l] == aa[j][l] then + diferent = false + else + equal = false + end + end end - end - end end end if not equal then -- not all the same for i=1,#v do if not done[i] then bb[i] = bb[i]..(aa[i][l]=="nil" and "" or aa[i][l]) - if keys[aa[i][l]] == 1 then - done[i] = true - end + -- if keys[aa[i][l]] == 1 then + -- done[i] = true + -- end end end end + --test done + for i=1,#v do + done[i] = true + for j=1,#v do + if i~=j and bb[i]==bb[j] then + done[i] = false + end + end + end end --avoid empty postfix which will be reserved to generic for i,v in ipairs(bb) do if v=="" then bb[i]="Nil" end end @@ -797,6 +801,11 @@ local function ADDIMSTR_S(FP) for k,v in ipairs(defT.argsT) do local typ = (v.type == "ImStr" or v.type == "const ImStr") and "const char*" or v.type table.insert(defT2.argsT,{type=typ,name=v.name}) + end + --defaults table + defT2.defaults = {} + for k,v in pairs(defT.defaults) do + defT2.defaults[k] = v end defT2.args = defT.args:gsub("const ImStr","const char*") defT2.args = defT2.args:gsub("ImStr","const char*") @@ -817,16 +826,26 @@ local function ADDIMSTR_S(FP) else caar = "()" end - defT2.call_args = caar + defT2.call_args = caar:gsub("ImStr%(([^%(%)]+)%)","%1") ------------------ - defT2.signature = defT.signature:gsub("ImStr","const char*").."_S" - defT2.ov_cimguiname = (defT2.ov_cimguiname or defT2.cimguiname).."_S" + defT2.signature = defT.signature:gsub("ImStr","const char*") --.."_S" + --defT2.ov_cimguiname = (defT2.ov_cimguiname or defT2.cimguiname).."_S" defT2.isIMSTR_S = 1 - - --replace + -- check there is not an equal version in imgui_stname + local doadd = true + for i,dd in ipairs(cimf) do + if dd.signature == defT2.signature then + doadd = false; + print("skip _S addition",defT2.cimguiname) + break + end + end + --add _S version + if doadd then cimf[#cimf+1] = defT2 cimf[defT2.signature] = defT2 newcdefs[#newcdefs+1] = {stname=t.stname,funcname=t.funcname,args=defT2.args,signature=defT2.signature,cimguiname=defT2.cimguiname,ret =defT2.ret} + end end else print("not cimguiname in");M.prtable(t) end @@ -1555,6 +1574,7 @@ function M.Parser() for k,v in pairs(self.alltypes) do print(k, typetoStr(k) ) end end function par:compute_overloads() + ADDIMSTR_S(self) local strt = {} local numoverloaded = 0 self.alltypes = {} @@ -1570,6 +1590,15 @@ function M.Parser() for i,t in ipairs(v) do --take overloaded name from manual table or algorythm t.ov_cimguiname = self.getCname_overload(t.stname,t.funcname,t.signature,t.namespace) or k..typetoStr(post[i]) + --check ... + if( t.ov_cimguiname:match"%.%.%.") then + print("... in ov",t.ov_cimguiname) + for i,dd in ipairs(v) do + print(dd.signature,post[i]) + end + error"Bad check ..." + end + --if t.isIMSTR_S then t.ov_cimguiname = t.ov_cimguiname .. "_S" end table.insert(strt,string.format("%d\t%s\t%s %s",i,t.ret,t.ov_cimguiname,t.signature)) --M.prtable(typesc[i],post) end @@ -1589,7 +1618,7 @@ function M.Parser() end) --print(numoverloaded, "overloaded") table.insert(strt,string.format("%d overloaded",numoverloaded)) - ADDIMSTR_S(self) + --ADDIMSTR_S(self) AdjustArguments(self) ADDnonUDT(self) From a48009b0628988367fa249b23775860407478621 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Mon, 1 Feb 2021 13:06:53 +0100 Subject: [PATCH 06/12] test and backend_test modifications for IMGUI_HAS_IMSTR --- backend_test/main.c | 10 +++++----- test/main.c | 7 +++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/backend_test/main.c b/backend_test/main.c index c7525dc..b786ed8 100644 --- a/backend_test/main.c +++ b/backend_test/main.c @@ -12,11 +12,11 @@ #include #ifdef IMGUI_HAS_IMSTR -#define igBegin igBegin_S -#define igSliderFloat igSliderFloat_S -#define igCheckbox igCheckbox_S -#define igColorEdit3 igColorEdit3_S -#define igButton igButton_S +#define igBegin igBeginChpt +#define igSliderFloat igSliderFloatChpt +#define igCheckbox igCheckboxChpt +#define igColorEdit3 igColorEdit3Chpt +#define igButton igButtonChpt #endif SDL_Window *window = NULL; diff --git a/test/main.c b/test/main.c index b7c7f1f..c722c18 100644 --- a/test/main.c +++ b/test/main.c @@ -3,8 +3,11 @@ #include "../cimgui.h" #ifdef IMGUI_HAS_IMSTR -#define igBegin igBegin_S -#define igSliderFloat igSliderFloat_S +#define igBegin igBeginChpt +#define igSliderFloat igSliderFloatChpt +#define igCheckbox igCheckboxChpt +#define igColorEdit3 igColorEdit3Chpt +#define igButton igButtonChpt #endif int main(void) From c57efd953fb087dabdb629e0017540fc10df58d4 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Mon, 1 Feb 2021 13:29:54 +0100 Subject: [PATCH 07/12] cpp2ffi: dont expect const ImStr --- generator/cpp2ffi.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index d49934a..2f38ae7 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -785,7 +785,7 @@ local function ADDIMSTR_S(FP) --if isIMSTR return generate _S version local isIMSTR = false for i,arg in ipairs(defT.argsT) do - if arg.type == "ImStr" or arg.type == "const ImStr" then isIMSTR=true;break end + if arg.type == "ImStr" then isIMSTR=true;break end end --if defT.ret=="ImVec2" or defT.ret=="ImVec4" or defT.ret=="ImColor" then --if isIMSTR then print(t.cimguiname,defT.ov_cimguiname,defT.argsoriginal,"isIMSTR") end @@ -799,7 +799,7 @@ local function ADDIMSTR_S(FP) --then argsT table defT2.argsT = {} for k,v in ipairs(defT.argsT) do - local typ = (v.type == "ImStr" or v.type == "const ImStr") and "const char*" or v.type + local typ = v.type == "ImStr" and "const char*" or v.type table.insert(defT2.argsT,{type=typ,name=v.name}) end --defaults table @@ -807,7 +807,6 @@ local function ADDIMSTR_S(FP) for k,v in pairs(defT.defaults) do defT2.defaults[k] = v end - defT2.args = defT.args:gsub("const ImStr","const char*") defT2.args = defT2.args:gsub("ImStr","const char*") --recreate call_args for wrapping into ImStr local caar From 2838c0317af1c4051343b17c041ca863a3a51a15 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Tue, 2 Feb 2021 16:00:33 +0100 Subject: [PATCH 08/12] cpp2ffi: changes for name prefixing the const char* versions of ImStr --- generator/cpp2ffi.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index 2f38ae7..b5b0697 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -813,7 +813,7 @@ local function ADDIMSTR_S(FP) if #defT.argsT > 0 then caar = "(" for i,v in ipairs(defT.argsT) do - local name = v.type == "ImStr" and "ImStr("..v.name..")" or v.name + local name = v.name --v.type == "ImStr" and "ImStr("..v.name..")" or v.name --wrap if v.ret then --function pointer caar = caar .. name .. "," else @@ -825,10 +825,10 @@ local function ADDIMSTR_S(FP) else caar = "()" end - defT2.call_args = caar:gsub("ImStr%(([^%(%)]+)%)","%1") + defT2.call_args = caar --:gsub("ImStr%(([^%(%)]+)%)","%1") --unwrap ------------------ defT2.signature = defT.signature:gsub("ImStr","const char*") --.."_S" - --defT2.ov_cimguiname = (defT2.ov_cimguiname or defT2.cimguiname).."_S" + defT2.ov_cimguiname = "S"..defT2.ov_cimguiname defT2.isIMSTR_S = 1 -- check there is not an equal version in imgui_stname local doadd = true @@ -1573,7 +1573,7 @@ function M.Parser() for k,v in pairs(self.alltypes) do print(k, typetoStr(k) ) end end function par:compute_overloads() - ADDIMSTR_S(self) + --ADDIMSTR_S(self) local strt = {} local numoverloaded = 0 self.alltypes = {} @@ -1617,7 +1617,7 @@ function M.Parser() end) --print(numoverloaded, "overloaded") table.insert(strt,string.format("%d overloaded",numoverloaded)) - --ADDIMSTR_S(self) + ADDIMSTR_S(self) AdjustArguments(self) ADDnonUDT(self) From 9ac7cd93e1c576ed27b8608e5946a213becbf419 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Tue, 2 Feb 2021 18:36:02 +0100 Subject: [PATCH 09/12] test, backend_test adapt to new naming --- backend_test/main.c | 10 +++++----- test/main.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/backend_test/main.c b/backend_test/main.c index b786ed8..6ad52df 100644 --- a/backend_test/main.c +++ b/backend_test/main.c @@ -12,11 +12,11 @@ #include #ifdef IMGUI_HAS_IMSTR -#define igBegin igBeginChpt -#define igSliderFloat igSliderFloatChpt -#define igCheckbox igCheckboxChpt -#define igColorEdit3 igColorEdit3Chpt -#define igButton igButtonChpt +#define igBegin SigBegin +#define igSliderFloat SigSliderFloat +#define igCheckbox SigCheckbox +#define igColorEdit3 SigColorEdit3 +#define igButton SigButton #endif SDL_Window *window = NULL; diff --git a/test/main.c b/test/main.c index c722c18..468835f 100644 --- a/test/main.c +++ b/test/main.c @@ -3,11 +3,11 @@ #include "../cimgui.h" #ifdef IMGUI_HAS_IMSTR -#define igBegin igBeginChpt -#define igSliderFloat igSliderFloatChpt -#define igCheckbox igCheckboxChpt -#define igColorEdit3 igColorEdit3Chpt -#define igButton igButtonChpt +#define igBegin SigBegin +#define igSliderFloat SigSliderFloat +#define igCheckbox SigCheckbox +#define igColorEdit3 SigColorEdit3 +#define igButton SigButton #endif int main(void) From bc708a092d5c4a617ddf6738ae6777ef3b1cfd16 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Wed, 3 Feb 2021 10:20:02 +0100 Subject: [PATCH 10/12] cpp2ffi: char* -> Str, ImStr -> STR for backward compability --- generator/cpp2ffi.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index b5b0697..2d4f848 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -491,12 +491,13 @@ local function typetoStr(typ) typ = typ:gsub("unsigned%s","u") typ = typ:gsub("const%s","")--"c") typ = typ:gsub("%s+","_") - typ = typ:gsub("charPtr","Chpt") + typ = typ:gsub("charPtr","Str") typ = typ:gsub("int","Int") typ = typ:gsub("bool","Bool") typ = typ:gsub("float","Float") typ = typ:gsub("uInt","Uint") typ = typ:gsub("ImGui","") + typ = typ:gsub("ImStr","STR") typ = typ:gsub("Im","") typ = typ:gsub("[<>]","") return typ From 6aa3f1decd0d7c9f76781cf673a46250423592d4 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Thu, 4 Feb 2021 17:05:55 +0100 Subject: [PATCH 11/12] cpp2ffi: const char* versions of ImStr take now a postfix _Strv --- generator/cpp2ffi.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index 2d4f848..42f5a92 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -829,7 +829,7 @@ local function ADDIMSTR_S(FP) defT2.call_args = caar --:gsub("ImStr%(([^%(%)]+)%)","%1") --unwrap ------------------ defT2.signature = defT.signature:gsub("ImStr","const char*") --.."_S" - defT2.ov_cimguiname = "S"..defT2.ov_cimguiname + defT2.ov_cimguiname = defT2.ov_cimguiname .. "_Strv" defT2.isIMSTR_S = 1 -- check there is not an equal version in imgui_stname local doadd = true From 2638737f2cc06937425a04316bf891e26e782435 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Fri, 5 Feb 2021 18:04:22 +0100 Subject: [PATCH 12/12] cpp2ffi: parse_enum_value drop outer () (ImGuizmo needed it) --- generator/cpp2ffi.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index 42f5a92..7edd2e5 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -165,8 +165,11 @@ local function parse_enum_value(value, allenums,dontpost) --already in allenums if allenums[clean(value)] then return allenums[clean(value)] end --must be several and operators - --precedence order (hope not ()) - assert(not value:match("[%(%)]")) + ------------precedence order (hope not ()) + --first drop outer () + value = value:gsub("^(%()",""):gsub("(%))$","") + assert(not value:match("[%(%)]"),value) + local several,seps = strsplit(value,"([<>&|~%+]+)") --M.prtable(value,several,seps) assert(#seps+1==#several) @@ -182,6 +185,9 @@ local function parse_enum_value(value, allenums,dontpost) local val2 = clean(several[i+1]) if allenums[val1] then val1 = allenums[val1] end if allenums[val2] then val2 = allenums[val2] end + --clean 1u + if type(val1)=="string" then val1 = val1:gsub("(%d)(u)$","%1") end + if type(val2)=="string" then val2 = val2:gsub("(%d)(u)$","%1") end --for getting numbers from "1ULL" if type(val1)=="string" then val1 = loadstring("return "..val1)() end if type(val2)=="string" then val2 = loadstring("return "..val2)() end @@ -1598,9 +1604,7 @@ function M.Parser() end error"Bad check ..." end - --if t.isIMSTR_S then t.ov_cimguiname = t.ov_cimguiname .. "_S" end table.insert(strt,string.format("%d\t%s\t%s %s",i,t.ret,t.ov_cimguiname,t.signature)) - --M.prtable(typesc[i],post) end --check not two names are equal (produced by bad cimguiname_overload) for i=1,#v-1 do