Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Node()
- local node = {}
- local proxy = {}
- setmetatable(proxy,{__newindex = function(t,k,v)
- rawset(node,k,v)
- if (type(v) == "table") then
- node[k].__parent = node
- end
- end,
- __index = function(t,k,v)
- return rawget(node,k) or rawget(_G,k)
- end,
- __pairs = function(t)
- local function stateless_iter(t, k)
- local v
- k, v = next(node, k)
- if v then return k,v end
- end
- return stateless_iter, node, nil
- end,
- __ipairs = function(t)
- local function stateless_iter(t, i)
- i = i + 1
- local v = node[i]
- if v then return i, v end
- end
- return stateless_iter, node, 0
- end
- })
- return proxy
- end
- local top = Node()
- top.child = Node()
- top.child.child2 = Node()
- top.child.child2.child3 = Node()
- top.child.child2.child3 = Node()
Advertisement
Add Comment
Please, Sign In to add comment