-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoondumpalt.moon
More file actions
64 lines (59 loc) · 1.92 KB
/
moondumpalt.moon
File metadata and controls
64 lines (59 loc) · 1.92 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
--https://github.com/leafo/moonscript/wiki/Alternative-Table-Dumper-%28with-indentation%29
line = ""
buff = {}
idx = 1
io_write = (str)->
line = line..str
io_write_nl = ()->
buff[idx] = line
idx += 1
line = ""
ilevel = 0
indent = (a, b)->
steps, fn = if b
a, b
else
1, a
ilevel += steps
fn!
ilevel -= steps
writeindent = -> io_write " "\rep ilevel
dump = =>
visited = {}
_write = =>
if type(self) == 'table' and not visited[self]
if not (@@ and @@__name and not @__tostring)
visited[self] = true
io_write "{"
io_write_nl!
for k, v in pairs self
indent ->
writeindent!
_write k
io_write ': '
_write v
io_write_nl!
writeindent!
_write "}"
elseif @__tostring
io_write @__tostring!
else
io_write @@__name
else
io_write tostring self
_write self
table.concat buff, "\n"
if _cmdline==""
print "A simple table pretty-printer, using indentation."
print "Doesn't output valid moonscript code, because string values are not put in quotes."
print "This could easily be changed, but serialization isn't the purpose of this module."
print ""
print "To prevent cycles a simple rule is used that every table is only output once in a given invocation."
print "Even if there are no cycles, and the table structure just contains non-tree-like references, it will still output each table only once."
print ""
print "Every key-value pair is output on a separate line, so, although always remaining fairly readable, the output can get rather large fairly quickly."
elseif _cmdline
print dump _cmdline\eval!
return
else
return dump