summaryrefslogtreecommitdiff
path: root/script/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'script/plugins')
-rw-r--r--script/plugins/ffi/c-parser/ctypes.lua32
-rw-r--r--script/plugins/ffi/init.lua20
2 files changed, 47 insertions, 5 deletions
diff --git a/script/plugins/ffi/c-parser/ctypes.lua b/script/plugins/ffi/c-parser/ctypes.lua
index ec8294c8..284fbe84 100644
--- a/script/plugins/ffi/c-parser/ctypes.lua
+++ b/script/plugins/ffi/c-parser/ctypes.lua
@@ -125,6 +125,25 @@ local convert_value = typed("TypeList, table -> CType?, string?", function (lst,
}), nil
end)
+local function convert_fields(lst, field_src, fields)
+ if field_src.ids then
+ for i, id in ipairs(field_src.ids) do
+ id.type = utility.deepCopy(field_src.type)
+ if id.type and id[1] then
+ for i, v in ipairs(id[1]) do
+ table.insert(id.type, v)
+ end
+ if id[1].idx then
+ id.isarray = true
+ end
+ id[1] = nil
+ end
+ table.insert(fields, id)
+ end
+ return true
+ end
+end
+
-- Interpret field data from `field_src` and add it to `fields`.
local function add_to_fields(lst, field_src, fields)
if type(field_src) == "table" and not field_src.ids then
@@ -136,6 +155,9 @@ local function add_to_fields(lst, field_src, fields)
return true
end
+ if convert_fields(lst, field_src, fields) then
+ return true
+ end
local field, err = convert_value(lst, field_src)
if not field then
return nil, err
@@ -541,7 +563,15 @@ ctypes.register_types = typed("{Decl} -> TypeList?, string?", function (parsed)
return nil, err or "failed typedef"
end
else
- item.spec = util.expandSingle(item.spec)
+ local expandSingle <const> = {
+ ["struct"] = true,
+ ["union"] = true,
+ ["enum"] = true,
+ }
+ local spec = util.expandSingle(item.spec)
+ if expandSingle[spec.type] then
+ item.spec = spec
+ end
if item.spec.type == "struct" or item.spec.type == "union" then
local ok, err = register_structunion(lst, item)
if not ok then
diff --git a/script/plugins/ffi/init.lua b/script/plugins/ffi/init.lua
index 66101f90..a551973a 100644
--- a/script/plugins/ffi/init.lua
+++ b/script/plugins/ffi/init.lua
@@ -2,7 +2,7 @@ local searchCode = require 'plugins.ffi.searchCode'
local cdefRerence = require 'plugins.ffi.cdefRerence'
local cdriver = require 'plugins.ffi.c-parser.cdriver'
local util = require 'plugins.ffi.c-parser.util'
-local utility = require 'utility'
+local utility = require 'utility'
local SDBMHash = require 'SDBMHash'
local ws = require 'workspace'
local files = require 'files'
@@ -134,11 +134,23 @@ function builder:isVoid(ast)
return self:isVoid(self:getTypeAst(typename))
end
+local function getArrayType(arr)
+ if type(arr) ~= "table" then
+ return arr and '[]' or ''
+ end
+ local res = ''
+ for i, v in ipairs(arr) do
+ res = res .. '[]'
+ end
+ return res
+end
+
function builder:buildStructOrUnion(lines, tt, name)
lines[#lines+1] = '---@class ' .. self:getType(name)
for _, field in ipairs(tt.fields or {}) do
if field.name and field.type then
- lines[#lines+1] = ('---@field %s %s'):format(field.name, self:getType(field.type))
+ lines[#lines+1] = ('---@field %s %s%s'):format(field.name, self:getType(field.type),
+ getArrayType(field.isarray))
end
end
end
@@ -146,7 +158,7 @@ end
function builder:buildFunction(lines, tt, name)
local param_names = {}
for i, param in ipairs(tt.params or {}) do
- lines[#lines+1] = ('---@param %s %s'):format(param.name, self:getType(param.type))
+ lines[#lines+1] = ('---@param %s %s%s'):format(param.name, self:getType(param.type), getArrayType(param.idxs))
param_names[#param_names+1] = param.name
end
if tt.vararg then
@@ -213,7 +225,7 @@ do
end
local function pushEnumValue(enumer, name, v)
- v = tonumber(util.expandSingle(v))
+ v = tonumber(util.expandSingle(v))
enumer[name] = v
enumer[#enumer+1] = v
return v