commit 329fc0e5b7f7777c405e4828650567a93620ba50
parent f150b62423d57b6f9fbe57330589937dfbb34f4a
Author: zeertzjq <zeertzjq@outlook.com>
Date: Wed, 17 Apr 2024 06:34:10 +0800
test: API can return Lua function to Lua code (#28380)
Diffstat:
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/src/nvim/api/private/converter.c b/src/nvim/api/private/converter.c
@@ -76,8 +76,7 @@ static Object typval_cbuf_to_obj(EncodedData *edata, const char *data, size_t le
do { \
ufunc_T *fp = find_func(fun); \
if (fp != NULL && (fp->uf_flags & FC_LUAREF)) { \
- LuaRef ref = api_new_luaref(fp->uf_luaref); \
- kvi_push(edata->stack, LUAREF_OBJ(ref)); \
+ kvi_push(edata->stack, LUAREF_OBJ(api_new_luaref(fp->uf_luaref))); \
} else { \
TYPVAL_ENCODE_CONV_NIL(tv); \
} \
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
@@ -559,6 +559,16 @@ describe('API', function()
eq('Vim:E121: Undefined variable: bogus', pcall_err(request, 'nvim_eval', 'bogus expression'))
eq('', eval('v:errmsg')) -- v:errmsg was not updated.
end)
+
+ it('can return Lua function to Lua code', function()
+ eq(
+ [["a string with \"double quotes\" and 'single quotes'"]],
+ exec_lua([=[
+ local fun = vim.api.nvim_eval([[luaeval('string.format')]])
+ return fun('%q', [[a string with "double quotes" and 'single quotes']])
+ ]=])
+ )
+ end)
end)
describe('nvim_call_function', function()
@@ -624,6 +634,16 @@ describe('API', function()
pcall_err(request, 'nvim_call_function', 'Foo', too_many_args)
)
end)
+
+ it('can return Lua function to Lua code', function()
+ eq(
+ [["a string with \"double quotes\" and 'single quotes'"]],
+ exec_lua([=[
+ local fun = vim.api.nvim_call_function('luaeval', { 'string.format' })
+ return fun('%q', [[a string with "double quotes" and 'single quotes']])
+ ]=])
+ )
+ end)
end)
describe('nvim_call_dict_function', function()