luassert
luassert copied to clipboard
is_calleable assertion
It would be useful to have an is_calleable assertion that tests whether is_function(argument) or is_function(debug.getmetatable(argument)._call).
this should be easy to add, see http://stevedonovan.github.io/Penlight/api/libraries/pl.types.html#is_callable
care to create a PR @devurandom ?
You mean to copy the code from Penlight?
--- is the object either a function or a callable object?.
-- @param obj Object to check.
function types.is_callable (obj)
return type(obj) == 'function' or getmetatable(obj) and getmetatable(obj).__call and true
end
Sure, I can do that.
No, busted already relies on Penlight, so all you have to do is add an assertion that uses that function.
But the assertions reside in luassert/src/assertions.lua, i.e. in luassert, which currently does not depend on Penlight.
@devurandom you are totally right, sorry for the noise.
Feel free to make a PR and reference this issue
luassert has its own implementation btw; in luassert.util, see https://github.com/Olivine-Labs/luassert/blob/master/src/util.lua#L274
luassert has its own implementation btw; in
luassert.util, see https://github.com/Olivine-Labs/luassert/blob/master/src/util.lua#L274
Technically, that impl is incorrect. See here: https://github.com/neovim/neovim/pull/29536
The Penlight impl is also incorrect.
wouldn't an object with metatable that has another metatable with a __call method be callable? iirc those lookups are chained.
wouldn't an object with metatable that has another metatable with a __call method be callable? iirc those lookups are chained.
Not for Lua 5.1 and Luajit. Maybe this has changed since 5.1 though, not sure.
You can see the tests here (neovim is pinned to 5.1): https://github.com/neovim/neovim/pull/29536/files
https://github.com/neovim/neovim/pull/27457#issuecomment-1940787881