From 13aac22a353f403ab95124472afea6d7d98e39c3 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Thu, 4 Mar 2021 12:44:49 +0100 Subject: [PATCH] cpp2ffi: allow function typedefs (not only function pointer typedefs) --- generator/cpp2ffi.lua | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index 7edd2e5..fd3cf77 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -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