fix(events): tolerate unserializable values

This commit is contained in:
Guillaume ARM 2026-06-07 22:21:23 +02:00
parent b070d96de5
commit b9a776485a

View File

@ -1,4 +1,4 @@
local _VERSION = '1.0.1';
local _VERSION = '1.0.2';
local command = ...;
@ -10,12 +10,44 @@ local function printUsage()
print('\t\t\tevents help');
end
local function sanitize(value, seen)
local valueType = type(value);
if valueType == 'function' then
return '<function>';
end
if valueType ~= 'table' then
return value;
end
seen = seen or {};
if seen[value] then
return '<cycle>';
end
seen[value] = true;
local result = {};
for k, v in pairs(value) do
result[sanitize(k, seen)] = sanitize(v, seen);
end
seen[value] = nil;
return result;
end
local function valueToString(value)
if type(value) == 'string' then
return value;
end
return textutils.serialize(value, { compact = true });
local ok, serialized = pcall(textutils.serialize, sanitize(value), { compact = true });
if ok then
return serialized;
end
return '<' .. type(value) .. '>';
end
if command == 'version' or command == '-version' or command == '--version' then