Compare commits

...

5 Commits

Author SHA1 Message Date
sonoro1234
9bffa7632f cpp2ffi: post skipped functions 2026-06-11 12:42:33 +02:00
sonoro1234
e2c1d90128 cpp2ffi: better printing and add const return when :: appears 2026-06-11 12:24:01 +02:00
sonoro1234
64fcbf194b cpp2ffi: explicit str_subst 2026-06-10 19:21:37 +02:00
sonoro1234
fced8c3451 README.md: more update bindings list 2026-06-10 11:52:57 +02:00
sonoro1234
7388e030e8 README.md: update bindings list 2026-06-10 11:23:33 +02:00
2 changed files with 64 additions and 17 deletions

View File

@@ -106,10 +106,14 @@ Notes:
# example bindings based on cimgui
* [LuaJIT-ImGui](https://github.com/sonoro1234/LuaJIT-ImGui)
* [cimgui-go](https://github.com/AllenDang/cimgui-go)
* [Hexa.NET.ImGui](https://github.com/HexaEngine/Hexa.NET.ImGui)
* [dear-imgui-rs](https://github.com/Latias94/dear-imgui-rs)
* [CImGui.jl](https://github.com/Gnimuc/CImGui.jl)
* [ImGui.NET](https://github.com/mellinoe/ImGui.NET)
* [Zig-ImGui](https://github.com/SpexGuy/Zig-ImGui)
* [nimgl/imgui](https://github.com/nimgl/imgui)
* [kotlin-imgui](https://github.com/Dominaezzz/kotlin-imgui)
* [CImGui.jl](https://github.com/Gnimuc/CImGui.jl)
* [odin-imgui](https://github.com/ThisDrunkDane/odin-imgui)
* [DerelictImgui](https://github.com/Extrawurst/DerelictImgui)
* [BindBC-CimGui](https://github.com/MrcSnm/bindbc-cimgui)

View File

@@ -776,8 +776,16 @@ local function parseFunction(self,stname,itt,namespace,locat)
return
end
local ret = line:match("([^%(%):,]+[%*%s])%s?~?[_%w]+%b()")
local rettt = line:match("(.+[%*%s])%s?~?[_%w]+%b()")
--if rettt and rettt:match"::" then print("rettt",rettt,ret);error"debug" end
--if ret~=rettt then print("++++++++ret~=rettt",ret,rettt) end
if rettt and rettt:match"^const" and not ret:match"^const" then
ret = "const "..ret
print("++++++++++++add const",ret)
end
--local ret = line:match("(.+[%*%s])%s?~?[_%w]+%b()")
--local funcname, args = line:match("(~?[_%w]+)%s*(%b())")
local funcname, args, extraconst = line:match("(~?[_%w]+)%s*(%b())(.*)")
@@ -1384,7 +1392,9 @@ local function header_subs_nonPOD(FP,txt)
return txt
end
M.header_subs_nonPOD = header_subs_nonPOD
local function get_std_function(ar)
local function get_std_function(ar,def)
print("get_std_function",ar.template_orig)
print(" from",def.ov_cimguiname)
local skip = false
local ty=ar.template_orig:gsub(ar.name,"")
ty = ty:match("std::function(%b<>)")
@@ -1402,12 +1412,14 @@ local function get_std_function(ar)
local argsT2 = {}
local noname_counter = 0
for i,v in ipairs(argsT) do
local typ, name = v:match("(.+)%s+(%w+)")
print(" arg",i,v)
local typ, name = v:match("^(.+)%s+(%w*)$")
if not name then
typ = v
noname_counter = noname_counter + 1
name = "noname" .. noname_counter
end
print(" ",typ,name)
argsT2[i] = {type=typ,name=name}
end
--get conversions
@@ -1423,6 +1435,9 @@ local function get_std_function(ar)
elseif v.type:match("std::") then
skip = true
else
print(" get_std_function found type",v.type)
-- require"anima.utils"
-- prtable(ar)
end
argsT3[i] = {type=typ or v.type,conv=conv,name=v.name}
end
@@ -1461,10 +1476,12 @@ local function get_std_function(ar)
return caar,asp,skip
end
local function ADDnonUDT(FP)
print"===================ADDnonUDT==================================="
local nonPOD = get_nonPOD(FP)
get_nonPODused(FP)
for k,defs in pairs(FP.defsT) do
for i, def in ipairs(defs) do
--print(" ADDnonUDT",def.ov_cimguiname,def.ret)
local skip = nil
--ret
local rets = (def.ret or ""):gsub("const ","")
@@ -1495,6 +1512,7 @@ local function ADDnonUDT(FP)
end
--return std:: -> skip function
elseif def.stdret then -- not std::string
print("skip",def.stdret,"on return")
skip = true
end
--args
@@ -1527,7 +1545,7 @@ local function ADDnonUDT(FP)
caar = caar .. "std::string("..name.."),"
asp = asp .. "const char* "..v.name..","
elseif v.type:match"std::function" then
local ca2,asp2,skip2 = get_std_function(v)
local ca2,asp2,skip2 = get_std_function(v,def)
caar = caar .. ca2..","
asp = asp .. asp2..","
if skip2 then skip = true end
@@ -1565,6 +1583,7 @@ local function ADDnonUDT(FP)
asp = "()"
end
if skip then
print("-------ADDnonUDT skips",def.ov_cimguiname)
def.skipped = skip
FP.skipped[def.ov_cimguiname] = true
else
@@ -1574,6 +1593,10 @@ local function ADDnonUDT(FP)
end
end
end
if next(FP.skipped) then
print(" =======skipped functions=====")
M.prtable(FP.skipped)
end
end
local function ADDnonUDT_OLD(FP)
local nonPOD = get_nonPOD(FP)
@@ -1642,6 +1665,9 @@ local function ADDnonUDT_OLD(FP)
end
local function ADDdestructors(FP)
print"======================================================="
print"==============ADDdestructors========================="
print"======================================================="
local defsT = FP.defsT
local newcdefs = {}
@@ -2056,7 +2082,7 @@ function M.Parser()
--clean class and get name
if it.re_name == "class_re" then
it.name = it.item:match("class%s+(%S+)")
print("cleaning class",it.name)
print("cleaning class",it.name,"-------------------------------------")
--it.item = it.item:gsub("private:.+};$","};")
--it.item = it.item:gsub("private:","")
it.item = it.item:gsub("public:","")
@@ -2119,22 +2145,22 @@ function M.Parser()
if derived then
local derived2 = derived:gsub("%b<>","")
derived2 = derived2:gsub("%w+::","")
print("--derived check",stname, derived, derived2)
M.prtable(self.opaque_structs)
print(" --derived check",stname, derived, derived2)
--M.prtable(self.opaque_structs)
if self.opaque_structs[derived2] then
print("--make opaque opaque derived",it.name,derived,derived2)
print(" --make opaque opaque derived",it.name,derived,derived2)
it.opaque_struct = get_parents_name(it)..it.name
self.opaque_structs[it.name] = it.opaque_struct
end
end
if derived and derived:match"std::" then
print("--make opaque std::derived",it.name,derived)
print(" --make opaque std::derived",it.name,derived)
--it.opaque_struct = (itparent and itparent.name .."::" or "")..it.name
it.opaque_struct = get_parents_name(it)..it.name
self.opaque_structs[it.name] = it.opaque_struct
end
if self.forced_opaque[it.name] then
print("--make forced opaque opaque derived",it.name)
print(" --make forced opaque opaque derived",it.name)
it.opaque_struct = get_parents_name(it)..it.name
self.opaque_structs[it.name] = it.opaque_struct
end
@@ -2143,12 +2169,12 @@ function M.Parser()
-- print("=====using",child.item)
-- end
if (child.re_name == "vardef_re") and child.item:match"std::" then
print("--make opaque",it.name,child.item)
print(" --make opaque with child std::",it.name,child.item)
--M.prtable(itparent)
--it.opaque_struct = (itparent and itparent.name .."::" or "")..it.name
it.opaque_struct = get_parents_name(it)..it.name
print("===parents1",get_parents_name(it),"===parents2",(itparent and itparent.name .."::" or ""))
print("===",it.opaque_struct)
print(" ===parents1",get_parents_name(it),"===parents2",(itparent and itparent.name .."::" or ""))
print(" ===",it.opaque_struct)
--cant do that as function is recursive
--self.opaque_structs[it.name] = get_parents_name(it)..it.name--(itparent and itparent.name .."::" or "")..it.name
self.opaque_structs[it.name] = it.opaque_struct
@@ -2176,6 +2202,9 @@ function M.Parser()
return table.concat(txtclean)
end
function par:parseItems()
print"================================================================"
print"===================parseItems==================================="
print"================================================================"
--self:initTypedefsDict()
self.linenumdict = {}
@@ -2198,9 +2227,13 @@ function M.Parser()
local txt = table.concat(cdefs2,"\n")
--string substitution
if self.str_subst then
print("========== str_subst")
local nn
for k,v in pairs(self.str_subst) do
txt = txt:gsub(k,v)
txt,nn = txt:gsub(k,v)
print(k,"done times:",nn)
end
print("========== str_subst end")
end
--clean = default in constructor (implot3d)
txt = txt:gsub("=%s*default","")
@@ -2545,7 +2578,9 @@ function M.Parser()
end
end
function par:gen_structs_and_enums()
print"======================================================="
print"--------------gen_structs_and_enums"
print"======================================================="
--M.prtable(self.typenames)
local outtab = {}
local outtabpre = {}
@@ -2834,7 +2869,9 @@ function M.Parser()
end
par.enums_for_table = enums_for_table
function par:gen_structs_and_enums_table()
print"--------------gen_structs_and_enums_table"
print"================================================================"
print"===================gen_structs_and_enums_table==================================="
print"================================================================"
local outtab = {enums={},structs={},locations={},enumtypes={},struct_comments={},enum_comments={},opaque_structs={}}
--self.typedefs_table = {}
local enumsordered = {}
@@ -3010,6 +3047,9 @@ function M.Parser()
end
function par:compute_overloads()
print"================================================================"
print"===================compute_overloads==================================="
print"================================================================"
-- if self.IMGUI_HAS_TEXTURES then
-- print"----------replacing ImTextureID with ImTextureUserID"
-- REPLACE_TEXTUREID(self)
@@ -3236,6 +3276,9 @@ function M.Parser()
end
--generate cimgui.cpp cimgui.h
function par:cimgui_generation( cimgui_header)
print"=========================================================="
print"===============cimgui_generation==========================="
print"=========================================================="
local name = self.modulename
local hstrfile = read_data("./"..name.."_template.h")
M.prtable("templates",self.templates)