aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/generators/gen_api_dispatch.lua
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2024-01-31 22:02:06 +0100
committerbfredl <bjorn.linse@gmail.com>2024-02-08 11:14:01 +0100
commitf9d81c43d2296d212c9cebcbdce401cd76cf0f1f (patch)
tree60166b94bddd63438c02b5619dfbc90f151884dd /src/nvim/generators/gen_api_dispatch.lua
parent24d26b4cd1db3d312a6c6e9d025c0016159f99dc (diff)
downloadrneovim-f9d81c43d2296d212c9cebcbdce401cd76cf0f1f.tar.gz
rneovim-f9d81c43d2296d212c9cebcbdce401cd76cf0f1f.tar.bz2
rneovim-f9d81c43d2296d212c9cebcbdce401cd76cf0f1f.zip
refactor(api): use keydict and arena for more api return values
Implement api_keydict_to_dict as the complement to api_dict_to_keydict Fix a conversion error when nvim_get_win_config gets called from lua, where Float values "x" and "y" didn't get converted to lua numbers.
Diffstat (limited to 'src/nvim/generators/gen_api_dispatch.lua')
-rw-r--r--src/nvim/generators/gen_api_dispatch.lua30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua
index 2eee1724c0..6d2beee0f8 100644
--- a/src/nvim/generators/gen_api_dispatch.lua
+++ b/src/nvim/generators/gen_api_dispatch.lua
@@ -212,6 +212,9 @@ for _, f in ipairs(functions) do
end
f_exported.parameters[i] = param
end
+ if startswith(f.return_type, 'Dict(') then
+ f_exported.return_type = 'Dictionary'
+ end
exported_functions[#exported_functions + 1] = f_exported
end
end
@@ -279,7 +282,7 @@ for _, k in ipairs(keysets) do
return k.name .. '_table[' .. idx .. '].str'
end)
- keysets_defs:write('extern KeySetLink ' .. k.name .. '_table[];\n')
+ keysets_defs:write('extern KeySetLink ' .. k.name .. '_table[' .. (1 + #neworder) .. '];\n')
local function typename(type)
if type == 'HLGroupID' then
@@ -596,7 +599,17 @@ for i = 1, #functions do
output:write(');\n')
end
- if fn.return_type ~= 'void' then
+ local ret_type = real_type(fn.return_type)
+ if string.match(ret_type, '^KeyDict_') then
+ local table = string.sub(ret_type, 9) .. '_table'
+ output:write(
+ '\n ret = DICTIONARY_OBJ(api_keydict_to_dict(&rv, '
+ .. table
+ .. ', ARRAY_SIZE('
+ .. table
+ .. '), arena));'
+ )
+ elseif ret_type ~= 'void' then
output:write('\n ret = ' .. string.upper(real_type(fn.return_type)) .. '_OBJ(rv);')
end
output:write('\n\ncleanup:')
@@ -869,7 +882,7 @@ local function process_function(fn)
output,
string.format(
[[
- const %s ret = %s(%s);
+ %s ret = %s(%s);
]],
fn.return_type,
fn.name,
@@ -877,6 +890,7 @@ local function process_function(fn)
)
)
+ local ret_type = real_type(fn.return_type)
if fn.has_lua_imp then
-- only push onto the Lua stack if we haven't already
write_shifted_output(
@@ -890,6 +904,16 @@ local function process_function(fn)
return_type
)
)
+ elseif string.match(ret_type, '^KeyDict_') then
+ write_shifted_output(
+ output,
+ string.format(
+ [[
+ nlua_push_keydict(lstate, &ret, %s_table);
+ ]],
+ string.sub(ret_type, 9)
+ )
+ )
else
local special = (fn.since ~= nil and fn.since < 11)
write_shifted_output(