aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAsbjørn Sloth Tønnesen <ast@2e8.dk>2019-07-17 22:01:46 +0000
committerAsbjørn Sloth Tønnesen <ast@2e8.dk>2019-07-17 22:01:46 +0000
commit50a063b8ea319cb4c340e69824bb4725300b35f9 (patch)
treef28cd6112102c59c03c7b62fd69bc8d81cb91396
parent62499d3d401ec775e18a4a8f3acf98c92740da11 (diff)
downloadlua-inet-50a063b8ea319cb4c340e69824bb4725300b35f9.tar.gz
lua-inet-50a063b8ea319cb4c340e69824bb4725300b35f9.tar.xz
lua-inet-50a063b8ea319cb4c340e69824bb4725300b35f9.zip
tests: readme: show differences in first table layer
Signed-off-by: Asbjørn Sloth Tønnesen <ast@2e8.dk>
-rw-r--r--test/readme.lua11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/readme.lua b/test/readme.lua
index 7581dc5..79e165a 100644
--- a/test/readme.lua
+++ b/test/readme.lua
@@ -73,6 +73,14 @@ local function run_example(name, code)
return run(name, format('return %s', code))
end
+local function table2str(t)
+ local nt = {}
+ for i=1,#t do
+ nt[i] = tostring(t[i])
+ end
+ return '{ ' .. concat(nt, ', ') .. ' }'
+end
+
local function pack2str(t)
local new = {}
local n = t.n
@@ -81,6 +89,9 @@ local function pack2str(t)
local vt = type(v)
if vt == 'nil' then
new[i] = 'nil'
+ elseif vt == 'table' then
+ local tostr = rawget(getmetatable(v) or {}, "__tostring") or table2str
+ new[i] = tostr(v)
else
new[i] = format('%s "%s"', vt, v)
end