-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is_calleable assertion #160
Comments
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 |
Technically, that impl is incorrect. See here: neovim/neovim#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. |
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 |
It would be useful to have an
is_calleable
assertion that tests whetheris_function(argument)
oris_function(debug.getmetatable(argument)._call)
.The text was updated successfully, but these errors were encountered: