summaryrefslogtreecommitdiffstats
path: root/Sluift
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2013-12-26 13:22:54 (GMT)
committerRemko Tronçon <git@el-tramo.be>2013-12-27 23:06:41 (GMT)
commit88702e2575bf8630a5f3ec2f876e617ca69b0018 (patch)
treef2db504e482d46c569bc77846736fcdab74932f5 /Sluift
parentf85b4104a1039165dbe1697174151d01c519b95a (diff)
downloadswift-88702e2575bf8630a5f3ec2f876e617ca69b0018.zip
swift-88702e2575bf8630a5f3ec2f876e617ca69b0018.tar.bz2
Sluift: tprint() enhancements
- Support recursive tables - Print functions Change-Id: Ic226243bdacc9da90b8b1e55c78311247e663af3
Diffstat (limited to 'Sluift')
-rw-r--r--Sluift/boot.lua15
1 files changed, 11 insertions, 4 deletions
diff --git a/Sluift/boot.lua b/Sluift/boot.lua
index e019fe6..6864884 100644
--- a/Sluift/boot.lua
+++ b/Sluift/boot.lua
@@ -48,26 +48,33 @@ local function table_value_tostring(value)
end
end
-local function table_tostring(table, indent, accumulator)
+local function table_tostring(table, print_functions, indent, accumulator, history)
local INDENT = ' '
local accumulator = accumulator or ''
+ local history = history or {}
local indent = indent or ''
accumulator = accumulator .. '{'
+ history[table] = true
local is_first = true
for key, value in pairs(table) do
- if type(value) ~= 'function' then
+ if print_functions or type(value) ~= 'function' then
if not is_first then
accumulator = accumulator .. ','
end
is_first = false
accumulator = accumulator .. '\n' .. indent .. INDENT .. '[' .. table_value_tostring(key) .. '] = '
if type(value) == 'table' then
- accumulator = table_tostring(value, indent .. INDENT, accumulator)
+ if history[value] then
+ accumulator = accumulator .. "..."
+ else
+ accumulator = table_tostring(value, print_functions, indent .. INDENT, accumulator, history)
+ end
else
accumulator = accumulator .. table_value_tostring(value)
end
end
end
+ history[table] = false
if not is_first then
accumulator = accumulator .. '\n' .. indent
end
@@ -76,7 +83,7 @@ local function table_tostring(table, indent, accumulator)
end
local function tprint(table)
- print(table_tostring(table))
+ print(table_tostring(table, true))
end
local function register_table_tostring(table)