Skip to content

Commit

Permalink
fix(callable): __call cannot be in a nested metatable
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Nov 5, 2024
1 parent 599d657 commit 66b2dd0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lua/pl/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ local types = {}
--- 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
if type(obj) == 'function' then
return true
end
local mt = getmetatable(obj)
if not mt then
return false
end
return type(rawget(mt, "__call")) == "function"
end

--- is the object of the specified type?.
Expand Down

0 comments on commit 66b2dd0

Please sign in to comment.