Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions dump.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,37 @@ local function dump_state(file, options)
processed[obj] = processed_counter;
return processed_counter;
end
local function skip(obj)
processed[obj] = 0;
end

if pcall(string.format, "%p", "") then
local format = string.format;
local function new_id(obj)
local t = type(obj);
if t == "function" or t == "string" or t == "table" or t == "userdata" or t == "thread" then
return format("%s:%p", t, obj);
elseif t == "number" or t == "boolean" or t == "nil" then
return format("%s:%q", t, obj);
else
error("don't know how to reference a "..t)
end
end

function skip(obj)
processed[ new_id(obj) ] = 0;
end

function get_id(obj) --> string | 0
if nil == obj then return 0; end
local id = new_id(obj);
if not processed[id] then
push(obj);
processed[id] = 0;
end
return id;
end
end

local escapes = {
["\""] = "\\\"", ["\\"] = "\\\\", ["\b"] = "\\b",
Expand Down Expand Up @@ -159,8 +190,8 @@ local function dump_state(file, options)
thread_mt = debug.getmetatable(debug.getregistry()[1]);
};

processed[dump_state] = 0;
processed[root] = 0;
skip(dump_state);
skip(root);

push(root);

Expand Down