title: Does Lua share tables within tables?
body: <p>I started developing a game with Love2d engine and Lua, and I have the following code structure. </p>
  
  <pre><code>BaseEntity = { 
          x = 0,
          y = 0,
          w = 0,
          h = 0,
          img = {},
       }
  
  function BaseEntity:new(obj)
      obj = obj or {}
      setmetatable(obj, self)
      self.__index = self
      return obj
  end
  
  function BaseEntity:setPos(x, y)
      self.x = x
      self.y = y
  end
  
  function BaseEntity:setImage( index, image )
      self.img[index] = image
  end
  
  PlayerType  = {["NORMAL"] = 0, ["AI"] = 1}
  PlayerState = {["SELECTED"] = 0, ["NOT_SELECTED"] = 1}
  
  Player =    {
                  type    = PlayerType.NORMAL,
                  state   = PlayerState.NOT_SELECTED
              }
  
  Player = BaseEntity:new(Player)
  
  function Player:new( obj )
      obj = obj or BaseEntity:new()
      setmetatable(obj, self)
      self.__index = self
      return obj
  end
  
  function Player:setImage( image )
      self.img["sprite"] = image
  end
  </code></pre>
  
  <p>When I create a few Player objects and assign different images using <code>setImage()</code> function to each object, they all share the same image I assigned to the last object. But when I set different positions to each object using <code>setPos()</code> method, they are drawn in correct distinctive positions. Why does it happen like that? Does Lua share the table <code>img</code> inside <code>BaseEntity</code> with all its instances created from it?</p>