[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [PROPOSAL] more luaL_check* in lauxlib.h (for Lua 5.2)
- From: Peter Odding <peter@...>
- Date: Thu, 02 Jun 2011 02:49:46 +0200
>> I think there is no efficient way to check if a given object
>> is callable. I would say that one should protect-call it and check if
>> it throws an error. Thus you'd better not check it :-)
>
> isn't it just
>
> function callable (x)
> return type(x) == 'function' or getmetatable(x).__call
> end
>
> ?
Actually this makes me curious, I found the following in my local
directory of modules and I'm wondering whether the recursion has a point
or not?
function callable(value)
if type(value) == 'function' then
return true
else
local mt = getmetatable(value)
return type(mt) == 'table' and callable(mt.__call)
end
end
- Peter