I need userdata objects to support both methods and the index operator (with integer indices). Is there a way to achieve this in a common metatable without simulating methods via a function?
I tried chaining metatables, by setting metatable(object).__index to a table with the actual methods, and metatable(metatable(object).__index).__index to a function that implements the index operator. However, that function is called with the first __index table as an argument, instead of the original object. Tbh this seems like a design oversight, since it makes much more sense to pass the original object when the __index metamethod is a function. Regardless, is there a way to achieve what I want without explicitly checking for method names in the __index function?