title: Lua Get/Set Metatable
body: <pre class="lang-lua prettyprint-override"><code>local ents = {
    GetLocalPlayer = function()
    
      local tbl = {
        localplayer = {&quot;Ava&quot;, &quot;1&quot;, {213,234,234}},
        
        GetIndex = function(self)
          return self.localplayer[2]
        end,
      }
      setmetatable(tbl, getmetatable(tbl.localplayer))
      return tbl
    end
  }
  
  local function main()
    print(ents.GetLocalPlayer()[2])
  end
  </code></pre>
  <p><code>main()</code> print returns nil. If I was to do <code>ents.GetLocalPlayer():GetIndex()</code> however, it returns 1.</p>
  <p>The idea is to have the default return value to be localplayer if I don't do things such as <code>GetIndex()</code></p>