blob: 49ead55554a8c8122163b2eea0d82a28c4eacf3f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
|