|
On Mar 22, 2010, at 4:44 AM, Ignacio Burgueño wrote:
This is also why getmetatable(bot:getLoc()).__mul(bot:getLoc(),2) works. Thanks to the __metatable entry it is essentially the same as: bot:getLoc().__mul(bot:getLoc(),2) Which is then essentially the same as: bot:getLoc():__mul(2) But the operator* code does not call the Lua getmetatable -- specifically because it doesn't want to get fouled by metatable hiding -- and hence it doesn't look in the methods table. What is probably needed is for the methods table created by Lunar to have a __newindex metamethod in its metatable which would recognize certain keys (e.g., "__mul") and store a copy of the value into the metatable as well as the methods table. Mark P.S. Why does Lua have this __metatable entry? Presumably so that one can protect metatables from access by untrusted code. This also points out why the circular via __index trick for metatables is a bad idea if you care about information hiding since the metatable for the object is then available as obj.__index. |