From 629289f8e654c790f64a42953a667a885c67c0c1 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 5 Nov 2024 22:06:25 +0100 Subject: [PATCH] fix(metatable): meta-fields are fetched using rawget --- src/util.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/util.lua b/src/util.lua index da2f247..5b66ebd 100644 --- a/src/util.lua +++ b/src/util.lua @@ -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 ----------------------------------------------- @@ -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 -----------------------------------------------