From 48491750e4ece19d2252592850b75d100afc2455 Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Wed, 29 Apr 2026 19:26:18 -0700 Subject: The refactor from HELL --- util.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'util.lua') diff --git a/util.lua b/util.lua index 2b84d85..5d31a2a 100644 --- a/util.lua +++ b/util.lua @@ -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 -- cgit v1.3