add typedefs_dict

This commit is contained in:
sonoro1234
2018-07-19 11:14:26 +02:00
parent 1c61237dbf
commit ac4a2f13c0
3 changed files with 65 additions and 5 deletions

View File

@@ -539,6 +539,7 @@ local function gen_structs_and_enums_table(cdefs)
local enumnames = {}
local enums_re = "^%s*enum%s+([^%s;]+)"
local outtab = {structs={},enums={}}
local typedefs_dict = {}
for i,line in ipairs(cdefs) do
repeat -- simulating continue with break
@@ -546,7 +547,23 @@ local function gen_structs_and_enums_table(cdefs)
local linecom = line
local line, comment = split_comment(line)
line = clean_spaces(line)
--typedefs dictionary
if line:match("typedef") then
local value,key = line:match("typedef%s+(.+)%s+([%w_]+);")
if key and value then
typedefs_dict[key] = value
else --try function typedef
local key = line:match("%(%*([%w_]+)%)%([^%(%)]*%)")
if key then
local linet = line
linet = linet:gsub("typedef ","")
linet = linet:gsub("%(%*("..key..")%)","(*)")
typedefs_dict[key] = linet
else
print(key,value,line)
end
end
end
if line:match(namespace_re) then
in_namespace = true
end
@@ -617,7 +634,7 @@ local function gen_structs_and_enums_table(cdefs)
end
until true
end
return outtab
return outtab, typedefs_dict
end
@@ -632,6 +649,7 @@ local function gen_structs_and_enums(cdefs)
local structnames = {}
local innerstructs = {}
local typedefs_table = {}
local outtab = {}
-- Output the file
--table.insert(outtab,"/////////////// BEGIN AUTOGENERATED SEGMENT\n")
@@ -644,7 +662,7 @@ local function gen_structs_and_enums(cdefs)
local desired_linelen = (linelen==0) and 0 or math.max(math.ceil(linelen/10)*10,40)
local spaces_to_add = 0 --desired_linelen - linelen
local linecom = line..string.rep(" ",spaces_to_add)..comment
if line:match(namespace_re) then
in_namespace = true
end
@@ -943,9 +961,9 @@ end
save_data("./generated/definitions.lua",serializeTable("defs",pFP.defsT),"\nreturn defs")
----------save struct and enums lua table in structs_and_enums.lua for using in bindings
local structs_and_enums_table = gen_structs_and_enums_table(pSTP.lines)
local structs_and_enums_table,typedefs_dict = gen_structs_and_enums_table(pSTP.lines)
save_data("./generated/structs_and_enums.lua",serializeTable("defs",structs_and_enums_table),"\nreturn defs")
save_data("./generated/typedefs_dict.lua",serializeTable("defs",typedefs_dict),"\nreturn defs")
--=================================Now implementations
local iFP,iSTP
@@ -1005,6 +1023,7 @@ end
local json = require"json"
save_data("./generated/definitions.json",json.encode(json_prepare(pFP.defsT)))
save_data("./generated/structs_and_enums.json",json.encode(structs_and_enums_table))
save_data("./generated/typedefs_dict.json",json.encode(typedefs_dict))
if iFP then
save_data("./generated/impl_definitions.json",json.encode(json_prepare(iFP.defsT)))
end