diff options
Diffstat (limited to 'aconf/model/node.lua')
-rw-r--r-- | aconf/model/node.lua | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/aconf/model/node.lua b/aconf/model/node.lua index bdf8311..b4fd685 100644 --- a/aconf/model/node.lua +++ b/aconf/model/node.lua @@ -66,6 +66,7 @@ function M.TreeNode:init(context, params) mt.name = pth.name(mt.path) mt.__eq = equal_tns + mt.__pairs = M.pairs if not (mt.txn and mt.txn.user) then mt.privileged = true end mt.escalate = mt.privileged and self or mt.class( @@ -343,6 +344,13 @@ end M.List = class(M.Collection) +local function _ipairs(mt, i) + i = i + 1 + local v = mt.load(i, {create=false}) + if v == nil then return end + return i, v +end + function M.List:init(context, params) super(self, M.List):init(context, setdefaults(params, {dtype='list'})) @@ -390,6 +398,8 @@ function M.List:init(context, params) end tmt._save(i, v) end + + function mt.__ipairs(t) return _ipairs, mt, 0 end end @@ -446,16 +456,5 @@ function M.pairs(tbl, dereference) return pairs(res) end -local function _ipairs(mt, i) - i = i + 1 - local v = mt.load(i, {create=false}) - if v == nil then return end - return i, v -end -function M.ipairs(tbl) - if not isinstance(tbl, M.TreeNode) then return ipairs(tbl) end - return _ipairs, getmetatable(tbl), 0 -end - return M |