cpp2ffi: allow function typedefs (not only function pointer typedefs)

This commit is contained in:
Victor Bombi
2021-03-04 12:44:49 +01:00
parent aa0baa777c
commit 13aac22a35

View File

@@ -287,7 +287,7 @@ local function getRE()
typedef_re = "^\n*%s*(typedef[^;]+;)",
typedef_st_re = "^\n*(typedef%s+struct%s*%b{}.-;)",
functypedef_re = "^\n*%s*(typedef[%w%s%*_]+%(%s*%*%s*[%w_]+%s*%)%s*%b()%s*;)",
functypedef_re = "^\n*%s*(typedef[%w%s%*_]+%([^*]*%*%s*[%w_]+%s*%)%s*%b()%s*;)",
functypedef_re = "^\n*%s*(typedef[%w%s%*_]+%([^*]*%*?%s*[%w_]+%s*%)%s*%b()%s*;)",
--vardef_re = "^\n*([^;{}%(%)]+;)",
--change for things as
--[[ImU8 Used4kPagesMap[((sizeof(ImWchar16) == 2 ? 0xFFFF : 0x10FFFF)+1)/4096/8];]]
@@ -1084,16 +1084,25 @@ function M.Parser()
local value,key = line:match("typedef%s+(.+)%s+([%w_]+);")
if key and value then
self.typedefs_dict[key] = value
else --try function typedef
else --try function pointer typedef
local key = line:match("%(%*([%w_]+)%)%([^%(%)]*%)")
if key then
local linet = line
linet = linet:gsub("typedef ","")
linet = linet:gsub("%(%*("..key..")%)","(*)")
self.typedefs_dict[key] = linet
elseif not line:match"typedef%s*struct" then --discard typedef struct
print("typedef not found")
print(key,value,line)
else
--try function typedef
key = line:match("%(([%w_]+)%)%([^%(%)]*%)")
if key then
local linet = line
linet = linet:gsub("typedef ","")
linet = linet:gsub("%(("..key..")%)","()")
self.typedefs_dict[key] = linet
elseif not line:match"typedef%s*struct" then --discard typedef struct
print("typedef not found")
print(key,value,line)
end
end
end
end