diff options
Diffstat (limited to 'util.lua')
| -rw-r--r-- | util.lua | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -53,12 +53,30 @@ function filter(a, pred) return filtered end -function fmt(x) +function fmt(x, depth) + depth = depth or 1 + if (depth > 4) then return "STACK_OVERFLOW" end + + if x == nil then + return "nil" + end + t = type(x) if t == "number" then return "" .. x elseif t == "string" then return x + elseif t == "table" then + s = "{" + i = 0 + for k, v in pairs(x) do + if i ~= 0 then s = s .. ", " end + i += 1 + s = s .. fmt(k, depth + 1) .. "=" .. fmt(v, depth + 1) + end + return s .. "}" + elseif t == "function" then + return "F()" elseif t == "boolean" and x then return "true" elseif t == "boolean" and not x then |
