From e7a883d9f3ed523d5b504f3f42f1ebccadb4fc06 Mon Sep 17 00:00:00 2001 From: Victor Bombi Date: Thu, 26 Mar 2020 11:56:17 +0100 Subject: [PATCH] use loadstring for parsing size of struct members, clean spaces around + --- generator/cpp2ffi.lua | 13 ++++++------- generator/output/structs_and_enums.json | 2 +- generator/output/structs_and_enums.lua | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/generator/cpp2ffi.lua b/generator/cpp2ffi.lua index ab97d2e..d5f606f 100644 --- a/generator/cpp2ffi.lua +++ b/generator/cpp2ffi.lua @@ -129,7 +129,7 @@ end local function clean_spaces(cad) cad = strip(cad) cad = cad:gsub("%s+"," ") --not more than one space - cad = cad:gsub("%s*([%(%),=:])%s*","%1") --not spaces with ( , ) or ( = ) or ( : ) + cad = cad:gsub("%s*([%(%),=:%+])%s*","%1") --not spaces with ( , ) or ( = ) or ( : ) or + return cad end @@ -1017,7 +1017,6 @@ function M.Parser() 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.."_(.+)") @@ -1138,13 +1137,13 @@ function M.Parser() t.size = tonumber(val) elseif allenums[val] then t.size = allenums[val] - elseif val:match"%+" then - local s1,s2 = val:match("(%d+)%s*%+%s*(%d+)") - t.size = s1+s2 else - print("Error size is",val) + local f,err = loadstring("estevalor="..val) + if not f then print("error on loadstring",err,"with val:",val) end + f() + t.size = estevalor end - assert(t.size) + assert(t.size,val) end end end diff --git a/generator/output/structs_and_enums.json b/generator/output/structs_and_enums.json index 7e6d3da..dc18e6d 100644 --- a/generator/output/structs_and_enums.json +++ b/generator/output/structs_and_enums.json @@ -3796,7 +3796,7 @@ }, { "name": "TempBuffer[1024*3+1]", - "size": 4, + "size": 3073, "type": "char" } ], diff --git a/generator/output/structs_and_enums.lua b/generator/output/structs_and_enums.lua index 223cc72..f03377d 100644 --- a/generator/output/structs_and_enums.lua +++ b/generator/output/structs_and_enums.lua @@ -2940,7 +2940,7 @@ defs["structs"]["ImGuiContext"][173]["name"] = "WantTextInputNextFrame" defs["structs"]["ImGuiContext"][173]["type"] = "int" defs["structs"]["ImGuiContext"][174] = {} defs["structs"]["ImGuiContext"][174]["name"] = "TempBuffer[1024*3+1]" -defs["structs"]["ImGuiContext"][174]["size"] = 4 +defs["structs"]["ImGuiContext"][174]["size"] = 3073 defs["structs"]["ImGuiContext"][174]["type"] = "char" defs["structs"]["ImGuiDataTypeInfo"] = {} defs["structs"]["ImGuiDataTypeInfo"][1] = {}