aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAsbjørn Sloth Tønnesen <ast@2e8.dk>2019-07-17 22:06:12 +0000
committerAsbjørn Sloth Tønnesen <ast@2e8.dk>2019-07-17 22:06:12 +0000
commitd9391277ce7cf8c47346da0df9a12d7ac36c9d56 (patch)
treec9faa083780ff9b2837e06a8b49f2252df34b138
parent50a063b8ea319cb4c340e69824bb4725300b35f9 (diff)
downloadlua-inet-d9391277ce7cf8c47346da0df9a12d7ac36c9d56.tar.gz
lua-inet-d9391277ce7cf8c47346da0df9a12d7ac36c9d56.tar.xz
lua-inet-d9391277ce7cf8c47346da0df9a12d7ac36c9d56.zip
tests: readme: improve readability
Signed-off-by: Asbjørn Sloth Tønnesen <ast@2e8.dk>
-rw-r--r--test/readme.lua10
1 files changed, 7 insertions, 3 deletions
diff --git a/test/readme.lua b/test/readme.lua
index 79e165a..dd39dac 100644
--- a/test/readme.lua
+++ b/test/readme.lua
@@ -73,6 +73,10 @@ local function run_example(name, code)
return run(name, format('return %s', code))
end
+local function get_meta_function(t, fname)
+ return rawget(getmetatable(t) or {}, fname)
+end
+
local function table2str(t)
local nt = {}
for i=1,#t do
@@ -90,7 +94,7 @@ local function pack2str(t)
if vt == 'nil' then
new[i] = 'nil'
elseif vt == 'table' then
- local tostr = rawget(getmetatable(v) or {}, "__tostring") or table2str
+ local tostr = get_meta_function(v, '__tostring') or table2str
new[i] = tostr(v)
else
new[i] = format('%s "%s"', vt, v)
@@ -100,8 +104,8 @@ local function pack2str(t)
end
local function compare_tables(a, b)
- local aeq = rawget(getmetatable(a) or {}, "__eq")
- local beq = rawget(getmetatable(b) or {}, "__eq")
+ local aeq = get_meta_function(a, '__eq')
+ local beq = get_meta_function(b, '__eq')
if aeq or beq then
if aeq ~= beq then return false end
if a ~= b then return false end