lunarmodules / luassert

Assertion library for Lua
MIT License
202 stars 76 forks source link

is_calleable assertion #160

Open devurandom opened 5 years ago

devurandom commented 5 years ago

It would be useful to have an is_calleable assertion that tests whether is_function(argument) or is_function(debug.getmetatable(argument)._call).

Tieske commented 5 years ago

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 ?

devurandom commented 5 years ago

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.

Tieske commented 5 years ago

No, busted already relies on Penlight, so all you have to do is add an assertion that uses that function.

devurandom commented 5 years ago

But the assertions reside in luassert/src/assertions.lua, i.e. in luassert, which currently does not depend on Penlight.

Tieske commented 5 years ago

@devurandom you are totally right, sorry for the noise.

DorianGray commented 5 years ago

Feel free to make a PR and reference this issue

Tieske commented 3 years ago

luassert has its own implementation btw; in luassert.util, see https://github.com/Olivine-Labs/luassert/blob/master/src/util.lua#L274