Created
April 29, 2024 11:20
-
-
Save roman-orekhov/a989d7ffd49118eb1f7d8c7d618b9eda to your computer and use it in GitHub Desktop.
Revisions
-
roman-orekhov created this gist
Apr 29, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ function check_registry() local reg = debug.getregistry() local s, cur, min, max = #reg + 1, 0 local ids, lst = {}, {n = 0} while type(reg[cur]) == "number" do if ids[cur] then return false, (table.concat(lst, "-")..": cycle "..cur) end ids[cur] = 1 lst.n = lst.n + 1 lst[lst.n] = cur if lst.n == 1 then min = reg[cur] max = reg[cur] else if cur < min then min = cur end if cur > max then max = cur end end cur = reg[cur] end local path = table.concat(lst, "-").."#"..cur if reg[cur] == nil then if cur ~= s then return false, (path..": nil end at "..cur.." instead of "..s) else if min and max then for i = min, max do if type(reg[i]) == "number" then local id = ids[reg[i]] if id then if id < 1 then return false, (path..": duplicate int "..reg[i].." within "..min.."-"..max) end ids[reg[i]] = id - 1 end end end end return true, path end else return false, (path..": value of type "..type(reg[cur]).." at "..cur.." instead of number or last-nil") end end