diff options
Diffstat (limited to 'script/plugins/ffi/c-parser/util.lua')
-rw-r--r-- | script/plugins/ffi/c-parser/util.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/script/plugins/ffi/c-parser/util.lua b/script/plugins/ffi/c-parser/util.lua new file mode 100644 index 00000000..cb493efa --- /dev/null +++ b/script/plugins/ffi/c-parser/util.lua @@ -0,0 +1,28 @@ +local m = {} + +local function tableLenEqual(t, len) + for key, value in pairs(t) do + len = len - 1 + if len < 0 then + return false + end + end + return true +end + +local function isSingleNode(ast) + if type(ast) ~= 'table' then + return false + end + local len = #ast + return len == 1 and tableLenEqual(ast, len) +end + +function m.expandSingle(ast) + if isSingleNode(ast) then + return ast[1] + end + return ast +end + +return m |