diff options
| author | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-04-29 19:26:18 -0700 |
|---|---|---|
| committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-04-29 19:26:18 -0700 |
| commit | 48491750e4ece19d2252592850b75d100afc2455 (patch) | |
| tree | 54a1edb6f390053c0ecee47da7e6121a9a387839 /util.lua | |
| parent | 42aeb43e2c8a959f5ea1f9a33cfe63d667321c56 (diff) | |
| download | dyl8-48491750e4ece19d2252592850b75d100afc2455.tar.gz dyl8-48491750e4ece19d2252592850b75d100afc2455.zip | |
The refactor from HELL
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 |
