diff --git a/scada-common/util.lua b/scada-common/util.lua index 76b7ff6..11dc2a8 100644 --- a/scada-common/util.lua +++ b/scada-common/util.lua @@ -66,9 +66,10 @@ function util.println_ts(message) print(os.date(p_time) .. tostring(message)) en ---@param val any ---@return string function util.strval(val) - if type(val) == "string" then return val end + local t = type(val) + if t == "string" then return val end -- this depends on Lua short-circuiting the or check for metatables (note: metatables won't have metatables) - if (type(val) == "table" and (getmetatable(val) == nil or getmetatable(val).__tostring == nil)) or type(val) == "function" then + if (t == "table" and (getmetatable(val) == nil or getmetatable(val).__tostring == nil)) or t == "function" then return table.concat{"[", tostring(val), "]"} else return tostring(val) end end