Skip to content

Commit

Permalink
fix(metatable): meta-fields are fetched using rawget
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Nov 5, 2024
1 parent 7b4f451 commit 629289f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,14 @@ end
-- @param object element to inspect on being callable or not
-- @return boolean, true if the object is callable
function util.callable(object)
return type(object) == "function" or type((debug.getmetatable(object) or {}).__call) == "function"
if type(object) == 'function' then
return true
end
local mt = debug.getmetatable(object)
if not mt then
return false
end
return type(rawget(mt, "__call")) == "function"
end

-----------------------------------------------
Expand All @@ -282,7 +289,7 @@ end
-- @param object element to inspect on having tostring or not
-- @return boolean, true if the object has tostring
function util.hastostring(object)
return type(object) == "string" or type((debug.getmetatable(object) or {}).__tostring) == "function"
return type(object) == "string" or type(rawget(debug.getmetatable(object) or {}, "__tostring")) == "function"
end

-----------------------------------------------
Expand Down

0 comments on commit 629289f

Please sign in to comment.