attaching metatables within tabes
snippet in lua

attaching metatables within tabes

user106

local function attach_mt(tbl, parent)
   setmetatable(tbl, {__index = parent or root.global})
   for k, v in pairs(tbl) do
      if type(v) == 'table' then
         attach_mt(v, tbl)
      end
   end
end
attach_mt(root)
setmetatable(root.global, nil)