diff options
Diffstat (limited to 'pp.lua')
-rw-r--r-- | pp.lua | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/pp.lua b/pp.lua index 85d323e..9c1a6d0 100644 --- a/pp.lua +++ b/pp.lua | |||
@@ -3,11 +3,27 @@ | |||
3 | local pp = {} | 3 | local pp = {} |
4 | table.unpack = table.unpack or unpack | 4 | table.unpack = table.unpack or unpack |
5 | 5 | ||
6 | pp.luadump = | ||
7 | function (x) | ||
8 | end | ||
9 | |||
10 | pp.luapp = function (x) print(pp.luadump(x)) end | ||
11 | |||
12 | pp.lamdump = | ||
13 | function (x) | ||
14 | end | ||
15 | |||
16 | pp.lampp = function (x) print(pp.lamdump(x)) end | ||
17 | |||
18 | -- The following should be at some point replaced by the preceding | ||
19 | |||
6 | function pp.dump (x, lvl) | 20 | function pp.dump (x, lvl) |
7 | lvl = lvl or 0 | 21 | lvl = lvl or 0 |
8 | local space = string.rep(" ", lvl) | 22 | local space = string.rep(" ", lvl) |
9 | local output = "" | 23 | local output = "" |
10 | if type(x) == "table" then | 24 | --[[if getmetatable(x) and getmetatable(x).__tostring then |
25 | output = output .. tostring(x) | ||
26 | else]]if type(x) == "table" then | ||
11 | local subo = "" | 27 | local subo = "" |
12 | for k,v in pairs(x) do | 28 | for k,v in pairs(x) do |
13 | if v == x then | 29 | if v == x then |
@@ -20,10 +36,8 @@ function pp.dump (x, lvl) | |||
20 | end | 36 | end |
21 | output = output .. string.format("\n%s{%s\n%s}", | 37 | output = output .. string.format("\n%s{%s\n%s}", |
22 | space, subo, space) | 38 | space, subo, space) |
23 | elseif type(x) == "string" then | ||
24 | output = output .. string.format("'%s'", x) | ||
25 | else | 39 | else |
26 | output = output .. string.format("%s", x) | 40 | output = output .. tostring(x) |
27 | end | 41 | end |
28 | return output | 42 | return output |
29 | end | 43 | end |