diff options
Diffstat (limited to 'pp.lua')
-rw-r--r-- | pp.lua | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/pp.lua b/pp.lua deleted file mode 100644 index 4d9d9af..0000000 --- a/pp.lua +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | --- lam.pp | ||
2 | |||
3 | local pp = {} | ||
4 | local type = require "type" | ||
5 | local unpack = table.unpack or unpack | ||
6 | |||
7 | function pp.dump (x, lvl) | ||
8 | lvl = lvl or 0 | ||
9 | local space = string.rep(" ", lvl) | ||
10 | local output = "" | ||
11 | --[[if getmetatable(x) and getmetatable(x).__tostring then | ||
12 | output = output .. tostring(x) | ||
13 | else]]if type.luatype(x) == "table" then | ||
14 | local subo = "" | ||
15 | for k,v in pairs(x) do | ||
16 | if v == x then | ||
17 | v = "self" | ||
18 | else | ||
19 | v = pp.dump(v, lvl+2) | ||
20 | end | ||
21 | subo = subo .. string.format("\n%s[%s] = %s,", | ||
22 | (space.." "), k, v) | ||
23 | end | ||
24 | output = output .. string.format("\n%s{%s\n%s}", | ||
25 | space, subo, space) | ||
26 | else | ||
27 | output = output .. tostring(x) | ||
28 | end | ||
29 | return output | ||
30 | end | ||
31 | |||
32 | function pp.pp (x) | ||
33 | print(pp.dump(x)) | ||
34 | end | ||
35 | |||
36 | --- | ||
37 | return pp | ||