Advertisement
Symmetryc

Variable or Infinite Depth Table Function

Dec 5th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.26 KB | None | 0 0
  1. return function(_size)
  2.     local function f(self, key, i)
  3.         i = i or 1
  4.         self[key] = setmetatable({}, {
  5.             __index = i >= _size and {} or function(self2, key2)
  6.                 return f(self2, key2, _size ~= -1 and i + 1)
  7.             end;
  8.         })
  9.         return self[key]
  10.     end
  11.     return f
  12. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement