From 4645c082faf15668b32aec2516b3bd2edfd4f289 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Tue, 30 Jun 2020 09:39:48 +0200 Subject: [PATCH] cpp2ffi.lua: remove explicit keyword, get template_type from parser.templates instead of string substitution (solves issues #140 and #141) --- generator/cpp2ffi.lua | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index e5c29ec..a83827c 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -430,6 +430,7 @@ local function parseFunction(self,stname,lineorig,namespace,locat) line = line:gsub("static","") line = line:gsub("inline","") line = line:gsub("mutable","") + line = line:gsub("explicit","") --skip operator if line:match("operator") then return end --skip template @@ -1075,19 +1076,22 @@ function M.Parser() else --split type name1,name2; in several lines local typen,rest = line:match("%s*([^,]+)%s(%S+[,;])") - --local template_type = typen:match("/%*<(.+)>%*/") - --if template_type then typen = typen:match("(.+)/%*") end if not typen then -- Lets try Type*name typen,rest = line:match("([^,]+%*)(%S+[,;])") end local template_type for k,v in pairs(self.templates) do - template_type = typen:match(k.."_(.+)") - if template_type then break end - end - if template_type then - template_type = template_type:gsub("_"," ") - template_type = template_type:gsub("Ptr","%*") + local template_type2 = typen:match(k.."_(.+)") + if template_type2 then + for k1,k2 in pairs(v) do + if template_type2==k2 then + template_type=k1 + break + end + end + assert(template_type) + break + end end for name in rest:gmatch("([^%s,;]+)%s?[,;]") do --unnamed unions