aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils.lua5
-rw-r--r--utils.moon5
2 files changed, 8 insertions, 2 deletions
diff --git a/utils.lua b/utils.lua
index 548ce0d..dde056c 100644
--- a/utils.lua
+++ b/utils.lua
@@ -16,7 +16,10 @@ utils = {
end
local _exp_0 = type(x)
if 'table' == _exp_0 then
- if utils.is_list(x) then
+ local mt = getmetatable(x)
+ if mt and mt.__tostring then
+ return mt.__tostring(x)
+ elseif utils.is_list(x) then
return "{" .. tostring(table.concat((function()
local _accum_0 = { }
local _len_0 = 1
diff --git a/utils.moon b/utils.moon
index eb222fb..c439e8f 100644
--- a/utils.moon
+++ b/utils.moon
@@ -10,7 +10,10 @@ utils = {
repr: (x, add_quotes=false)->
switch type(x)
when 'table'
- if utils.is_list x
+ mt = getmetatable(x)
+ if mt and mt.__tostring
+ mt.__tostring(x)
+ elseif utils.is_list x
"{#{table.concat([utils.repr(i, true) for i in *x], ", ")}}"
else
"{#{table.concat(["[#{utils.repr(k, true)}]= #{utils.repr(v, true)}" for k,v in pairs x], ", ")}}"