mirror of
https://github.com/neovim/neovim.git
synced 2025-01-01 17:23:36 -07:00
fix(api, lua): return NIL on failure to find converted function (#17779)
This commit is contained in:
parent
2ab52bd988
commit
77eb6f9dc7
@ -65,8 +65,7 @@ typedef struct {
|
|||||||
#define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun) \
|
#define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun) \
|
||||||
do { \
|
do { \
|
||||||
ufunc_T *fp = find_func(fun); \
|
ufunc_T *fp = find_func(fun); \
|
||||||
assert(fp != NULL); \
|
if (fp != NULL && fp->uf_cb == nlua_CFunction_func_call) { \
|
||||||
if (fp->uf_cb == nlua_CFunction_func_call) { \
|
|
||||||
LuaRef ref = api_new_luaref(((LuaCFunctionState *)fp->uf_cb_state)->lua_callable.func_ref); \
|
LuaRef ref = api_new_luaref(((LuaCFunctionState *)fp->uf_cb_state)->lua_callable.func_ref); \
|
||||||
kvi_push(edata->stack, LUAREF_OBJ(ref)); \
|
kvi_push(edata->stack, LUAREF_OBJ(ref)); \
|
||||||
} else { \
|
} else { \
|
||||||
|
@ -477,8 +477,7 @@ static bool typval_conv_special = false;
|
|||||||
#define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun) \
|
#define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun) \
|
||||||
do { \
|
do { \
|
||||||
ufunc_T *fp = find_func(fun); \
|
ufunc_T *fp = find_func(fun); \
|
||||||
assert(fp != NULL); \
|
if (fp != NULL && fp->uf_cb == nlua_CFunction_func_call) { \
|
||||||
if (fp->uf_cb == nlua_CFunction_func_call) { \
|
|
||||||
nlua_pushref(lstate, ((LuaCFunctionState *)fp->uf_cb_state)->lua_callable.func_ref); \
|
nlua_pushref(lstate, ((LuaCFunctionState *)fp->uf_cb_state)->lua_callable.func_ref); \
|
||||||
} else { \
|
} else { \
|
||||||
TYPVAL_ENCODE_CONV_NIL(tv); \
|
TYPVAL_ENCODE_CONV_NIL(tv); \
|
||||||
|
@ -6,6 +6,7 @@ local assert_alive = helpers.assert_alive
|
|||||||
local NIL = helpers.NIL
|
local NIL = helpers.NIL
|
||||||
local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq
|
local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq
|
||||||
local command = helpers.command
|
local command = helpers.command
|
||||||
|
local exec = helpers.exec
|
||||||
local eval = helpers.eval
|
local eval = helpers.eval
|
||||||
local expect = helpers.expect
|
local expect = helpers.expect
|
||||||
local funcs = helpers.funcs
|
local funcs = helpers.funcs
|
||||||
@ -1271,6 +1272,17 @@ describe('API', function()
|
|||||||
eq('Key is locked: lua', pcall_err(meths.del_var, 'lua'))
|
eq('Key is locked: lua', pcall_err(meths.del_var, 'lua'))
|
||||||
eq('Key is locked: lua', pcall_err(meths.set_var, 'lua', 1))
|
eq('Key is locked: lua', pcall_err(meths.set_var, 'lua', 1))
|
||||||
|
|
||||||
|
exec([[
|
||||||
|
function Test()
|
||||||
|
endfunction
|
||||||
|
function s:Test()
|
||||||
|
endfunction
|
||||||
|
let g:Unknown_func = function('Test')
|
||||||
|
let g:Unknown_script_func = function('s:Test')
|
||||||
|
]])
|
||||||
|
eq(NIL, meths.get_var('Unknown_func'))
|
||||||
|
eq(NIL, meths.get_var('Unknown_script_func'))
|
||||||
|
|
||||||
-- Check if autoload works properly
|
-- Check if autoload works properly
|
||||||
local pathsep = helpers.get_pathsep()
|
local pathsep = helpers.get_pathsep()
|
||||||
local xconfig = 'Xhome' .. pathsep .. 'Xconfig'
|
local xconfig = 'Xhome' .. pathsep .. 'Xconfig'
|
||||||
|
@ -1043,6 +1043,17 @@ describe('lua stdlib', function()
|
|||||||
exec_lua([[vim.api.nvim_get_var('funcs').add()]])
|
exec_lua([[vim.api.nvim_get_var('funcs').add()]])
|
||||||
eq(6, exec_lua([[return vim.api.nvim_get_var('funcs').get()]]))
|
eq(6, exec_lua([[return vim.api.nvim_get_var('funcs').get()]]))
|
||||||
|
|
||||||
|
exec([[
|
||||||
|
function Test()
|
||||||
|
endfunction
|
||||||
|
function s:Test()
|
||||||
|
endfunction
|
||||||
|
let g:Unknown_func = function('Test')
|
||||||
|
let g:Unknown_script_func = function('s:Test')
|
||||||
|
]])
|
||||||
|
eq(NIL, exec_lua([[return vim.g.Unknown_func]]))
|
||||||
|
eq(NIL, exec_lua([[return vim.g.Unknown_script_func]]))
|
||||||
|
|
||||||
-- Check if autoload works properly
|
-- Check if autoload works properly
|
||||||
local pathsep = helpers.get_pathsep()
|
local pathsep = helpers.get_pathsep()
|
||||||
local xconfig = 'Xhome' .. pathsep .. 'Xconfig'
|
local xconfig = 'Xhome' .. pathsep .. 'Xconfig'
|
||||||
@ -1136,6 +1147,17 @@ describe('lua stdlib', function()
|
|||||||
exec_lua([[vim.api.nvim_buf_get_var(0, 'funcs').add()]])
|
exec_lua([[vim.api.nvim_buf_get_var(0, 'funcs').add()]])
|
||||||
eq(6, exec_lua([[return vim.api.nvim_buf_get_var(0, 'funcs').get()]]))
|
eq(6, exec_lua([[return vim.api.nvim_buf_get_var(0, 'funcs').get()]]))
|
||||||
|
|
||||||
|
exec([[
|
||||||
|
function Test()
|
||||||
|
endfunction
|
||||||
|
function s:Test()
|
||||||
|
endfunction
|
||||||
|
let b:Unknown_func = function('Test')
|
||||||
|
let b:Unknown_script_func = function('s:Test')
|
||||||
|
]])
|
||||||
|
eq(NIL, exec_lua([[return vim.b.Unknown_func]]))
|
||||||
|
eq(NIL, exec_lua([[return vim.b.Unknown_script_func]]))
|
||||||
|
|
||||||
exec_lua [[
|
exec_lua [[
|
||||||
vim.cmd "vnew"
|
vim.cmd "vnew"
|
||||||
]]
|
]]
|
||||||
@ -1219,6 +1241,17 @@ describe('lua stdlib', function()
|
|||||||
exec_lua([[vim.api.nvim_win_get_var(0, 'funcs').add()]])
|
exec_lua([[vim.api.nvim_win_get_var(0, 'funcs').add()]])
|
||||||
eq(6, exec_lua([[return vim.api.nvim_win_get_var(0, 'funcs').get()]]))
|
eq(6, exec_lua([[return vim.api.nvim_win_get_var(0, 'funcs').get()]]))
|
||||||
|
|
||||||
|
exec([[
|
||||||
|
function Test()
|
||||||
|
endfunction
|
||||||
|
function s:Test()
|
||||||
|
endfunction
|
||||||
|
let w:Unknown_func = function('Test')
|
||||||
|
let w:Unknown_script_func = function('s:Test')
|
||||||
|
]])
|
||||||
|
eq(NIL, exec_lua([[return vim.w.Unknown_func]]))
|
||||||
|
eq(NIL, exec_lua([[return vim.w.Unknown_script_func]]))
|
||||||
|
|
||||||
exec_lua [[
|
exec_lua [[
|
||||||
vim.cmd "vnew"
|
vim.cmd "vnew"
|
||||||
]]
|
]]
|
||||||
|
Loading…
Reference in New Issue
Block a user