title: What does metatable field __index actually means?
body: <p>In Programming in Lua, I known the metatable field <code>__index</code> is a function that takes 2 arguments, they are:</p>
  <ol>
  <li>table itself</li>
  <li>key value</li>
  </ol>
  <p>But something confusing happens when I was reading Object-Oriented Programming, Chapter 21, there is an example(like it):</p>
  <pre class="lang-lua prettyprint-override"><code>local A = {
      greet = function()
          print 'hello world'
      end
  }
  
  local B = {}
  
  setmetatable(B, {
      __index = A
  })
  
  B.greet()
  </code></pre>
  <p>I cant understand why <code>__index = A</code> let <code>B</code> becomes an object of <code>A</code>, it should be a funciton here, right? Just like following:</p>
  <pre class="lang-lua prettyprint-override"><code>__index = function(_, key)
      return A[key]
  end
  </code></pre>