__index, i really dont get it
Posted: Sun Jul 26, 2009 4:21 am
sorry this is more of a pure LUA question but it is being used in my game so...
anyway, i really dont understand what __index does. could someone explain in layman's terms - the lua website isnt helping. they've made it very confusing. the example they've given is found here: http://lua-users.org/wiki/MetamethodsTutorial (scroll down a little bit bellow String class example). i sort of understand what that does but i dont think it's quiet it. to me it sounds like its just adding the length function to the mt metatable. and since s has had its metatable set to mt earlier on, it can now use this function. am i correct? is this the only use for it..? :
anyway, i really dont understand what __index does. could someone explain in layman's terms - the lua website isnt helping. they've made it very confusing. the example they've given is found here: http://lua-users.org/wiki/MetamethodsTutorial (scroll down a little bit bellow String class example). i sort of understand what that does but i dont think it's quiet it. to me it sounds like its just adding the length function to the mt metatable. and since s has had its metatable set to mt earlier on, it can now use this function. am i correct? is this the only use for it..? :