Commit fb7d6429 authored by Vicent Marti's avatar Vicent Marti

table.lua: Add support for decoding bitfield types

parent e6b7c740
...@@ -273,25 +273,31 @@ local function _decode_table_type(desc) ...@@ -273,25 +273,31 @@ local function _decode_table_type(desc)
return t return t
end end
local fields = "" local fields = {}
local struct = t[3] or "struct" local struct = t[3] or "struct"
for _, value in ipairs(t[2]) do for _, value in ipairs(t[2]) do
local f = nil
if #value == 2 then if #value == 2 then
fields = fields .. string.format("%s %s; ", _dec(value[2]), value[1]) f = string.format("%s %s;", _dec(value[2]), value[1])
elseif #value == 3 then elseif #value == 3 then
if type(value[3]) == "table" then if type(value[3]) == "table" then
fields = fields .. string.format("%s %s[%d]; ", _dec(value[2]), value[1], value[3][1]) f = string.format("%s %s[%d];", _dec(value[2]), value[1], value[3][1])
else elseif type(value[3]) == "number" then
error("not implemented: "..json_desc) local t = _dec(value[2])
assert(t == "int" or t == "unsigned int",
"bitfields can only appear in [unsigned] int types")
f = string.format("%s %s:%d;", t, value[1], value[3])
end end
else
error("failed to decode type "..json_desc)
end end
assert(f ~= nil, "failed to decode type "..json_desc)
table.insert(fields, f)
end end
assert(struct == "struct" or struct == "union", "unknown complex type: "..struct) assert(struct == "struct" or struct == "union", "unknown complex type: "..struct)
return string.format("%s { %s}", struct, fields) return string.format("%s { %s }", struct, table.concat(fields, " "))
end end
return _dec(json.parse(json_desc)) return _dec(json.parse(json_desc))
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment