View Single Post
06-11-15, 05:05 PM   #8
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by Seerah View Post
Your sometable table doesn't have anything in it, that's why your pairs() loop doesn't see anything. If you were actually trying to index something (doing sometable[key] or sometable.key) and the key does not exist in your table, *that's* when it will look it up in the __index in the metatable to get a value.
That's where I got confused as according to the code from lua.org, it shows that the ipairs function (not entirely sure about the pairs function) actually does try to index sometable[n] where n is an index number so I thought that would trigger __Index if index n doesn't exist in the table with nothing in it, but strangely it doesn't.

But I do understand how the __Index method works and how it looks at the original table before looking at the "inherited" one I just wish that for loop iterator functions would trigger the __index method when it tries to index something that does not exist in the original table but from reading the link Resike sent I just have to assume its impossible.
  Reply With Quote