From a277995372806803575d7f72177498dd91555573 Mon Sep 17 00:00:00 2001 From: hashchange Date: Mon, 24 Apr 2017 16:37:29 +0200 Subject: [PATCH] Added support for LrObservableTable --- inspect.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/inspect.lua b/inspect.lua index ae5b430..11a1411 100644 --- a/inspect.lua +++ b/inspect.lua @@ -107,10 +107,22 @@ local function getSequenceLength(t) return len - 1 end +local function isObservableTable(t) + return type(t) == "table" and type(t.pairs) == "function" and type(t.addObserver) == "function" and type(t.removeObserver) == "function" +end + +local function tpairs(t) + if isObservableTable(t) then + return t:pairs() + else + return pairs(t) + end +end + local function getNonSequentialKeys(t) local keys = {} local sequenceLength = getSequenceLength(t) - for k,_ in pairs(t) do + for k,_ in tpairs(t) do if not isSequenceKey(k, sequenceLength) then table.insert(keys, k) end end table.sort(keys, sortKeys) @@ -133,7 +145,7 @@ local function countTableAppearances(t, tableAppearances) if type(t) == 'table' then if not tableAppearances[t] then tableAppearances[t] = 1 - for k,v in pairs(t) do + for k,v in tpairs(t) do countTableAppearances(k, tableAppearances) countTableAppearances(v, tableAppearances) end @@ -172,7 +184,7 @@ local function processRecursive(process, item, path, visited) visited[item] = processedCopy local processedKey - for k,v in pairs(processed) do + for k,v in tpairs(processed) do processedKey = processRecursive(process, k, makePath(path, k, inspect.KEY), visited) if processedKey ~= nil then processedCopy[processedKey] = processRecursive(process, v, makePath(path, processedKey), visited)