mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(lua): stricter type check when calling API function (#16745)
Solves #13651 Co-authored-by: Gregory Anders <greg@gpanders.com>
This commit is contained in:
parent
76435c0cfa
commit
297ff97647
@ -1242,7 +1242,12 @@ LuaRef nlua_pop_LuaRef(lua_State *const lstate, Error *err)
|
|||||||
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT \
|
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT \
|
||||||
{ \
|
{ \
|
||||||
type ret; \
|
type ret; \
|
||||||
ret = (type)lua_tonumber(lstate, -1); \
|
if (lua_type(lstate, -1) != LUA_TNUMBER) { \
|
||||||
|
api_set_error(err, kErrorTypeValidation, "Expected Lua number"); \
|
||||||
|
ret = (type)-1; \
|
||||||
|
} else { \
|
||||||
|
ret = (type)lua_tonumber(lstate, -1); \
|
||||||
|
} \
|
||||||
lua_pop(lstate, 1); \
|
lua_pop(lstate, 1); \
|
||||||
return ret; \
|
return ret; \
|
||||||
}
|
}
|
||||||
|
@ -183,6 +183,8 @@ describe('luaeval(vim.api.…)', function()
|
|||||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 'test', 1, false)")]])))
|
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 'test', 1, false)")]])))
|
||||||
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Number is not integral',
|
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Number is not integral',
|
||||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 1.5, 1, false)")]])))
|
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 1.5, 1, false)")]])))
|
||||||
|
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected Lua number',
|
||||||
|
remove_trace(exc_exec([[call luaeval("vim.api.nvim_win_is_valid(nil)")]])))
|
||||||
|
|
||||||
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table',
|
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table',
|
||||||
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_float('test')")]])))
|
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_float('test')")]])))
|
||||||
|
Loading…
Reference in New Issue
Block a user