Skip to content

Commit 629289f

Browse files
committed
fix(metatable): meta-fields are fetched using rawget
1 parent 7b4f451 commit 629289f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/util.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,14 @@ end
272272
-- @param object element to inspect on being callable or not
273273
-- @return boolean, true if the object is callable
274274
function util.callable(object)
275-
return type(object) == "function" or type((debug.getmetatable(object) or {}).__call) == "function"
275+
if type(object) == 'function' then
276+
return true
277+
end
278+
local mt = debug.getmetatable(object)
279+
if not mt then
280+
return false
281+
end
282+
return type(rawget(mt, "__call")) == "function"
276283
end
277284

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

288295
-----------------------------------------------

0 commit comments

Comments
 (0)