summaryrefslogtreecommitdiff
path: root/city/util.lua
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-02-25 11:14:06 -0600
committersanine <sanine.not@pm.me>2022-02-25 11:14:06 -0600
commit2ae6baefb71149bc1158f94acc780567cf1613a7 (patch)
treeaa9938a5185443cd3d74ed98cf4f4e5f64b96368 /city/util.lua
parent1b93d166d6beeccffe3a3279a2b8ab93a2efc82a (diff)
add multi-recursion insert test
Diffstat (limited to 'city/util.lua')
-rw-r--r--city/util.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/city/util.lua b/city/util.lua
new file mode 100644
index 0000000..49ead55
--- /dev/null
+++ b/city/util.lua
@@ -0,0 +1,37 @@
+local util = {}
+
+util.table_str = function(tbl, recursive, indent)
+ local tab = '\t'
+
+ local recursive = recursive or false
+ local indent = indent or ''
+
+ local str = '{'
+
+ for key, value in pairs(tbl) do
+ local key_str, value_str
+ if type(key) == 'table' and recursive then
+ key_str = util.table_str(key, recursive, indent..tab)
+ else
+ key_str = tostring(key)
+ end
+
+ if type(value) == 'table' and recursive then
+ value_str = util.table_str(value, recursive, indent..tab)
+ else
+ value_str = tostring(value)
+ end
+
+ str = str .. string.format(
+ '\n%s%s = %s', indent..tab,
+ key_str, value_str)
+ end
+
+ if string.len(str) > 1 then
+ str = str .. '\n' .. indent
+ end
+ str = str .. '}'
+ return str
+end
+
+return util