don't print brackets in util.strval if metatable __tostring is present

This commit is contained in:
Mikayla Fischler 2023-06-06 19:41:55 -04:00
parent 0f5ae9a756
commit 55dab6d675

View File

@ -65,7 +65,8 @@ end
---@return string
function util.strval(val)
local t = type(val)
if t == "table" or t == "function" then
-- this depends on Lua short-circuiting the or check for metatables (note: metatables won't have metatables)
if (t == "table" and (getmetatable(val) == nil or getmetatable(val).__tostring == nil)) or t == "function" then
return "[" .. tostring(val) .. "]"
else
return tostring(val)