From 738b3cfadc508e85794ebefadff456204ec08428 Mon Sep 17 00:00:00 2001 From: y5nw Date: Sat, 22 Feb 2025 21:47:00 +0100 Subject: [PATCH] fixup --- builtin/common/serialize.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/builtin/common/serialize.lua b/builtin/common/serialize.lua index aa1a5c0a7..221ac66fd 100644 --- a/builtin/common/serialize.lua +++ b/builtin/common/serialize.lua @@ -31,24 +31,26 @@ local function prepare_objects(value) if type_ == "boolean" or type_ == "number" then return end + local count = counts[val] if not recount then - local count = counts[val] counts[val] = (count or 0) + 1 end - local mt = (not recount) and (type_ == "table" or type_ == "userdata") and getmetatable(val) + local mt = (not count) and (type_ == "table" or type_ == "userdata") and getmetatable(val) if mt and core.known_metatables[mt] then type_lookup[val] = core.known_metatables[mt] count_values(val, true) elseif type_ == "table" then - for k, v in pairs(val) do - count_values(k) - count_values(v) + if recount or not count then + for k, v in pairs(val) do + count_values(k) + count_values(v) + end end - elseif type_ ~= "string" then + elseif type_ ~= "string" and type_ ~= "function" then error("unsupported type: " .. type_) end end - count_values(value, false) + count_values(value) return counts, type_lookup end