lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Sun, Sep 24, 2017 at 11:16 PM, ThePhD <> wrote:

> At the end of my talk, I briefly mentioned that a possible solution would be including the "initial missed target" that began the cascading chain of `__index` or `__newindex` lookups as a new argument at the end of the current argument list __index and __newindex.

Let's say for a given table (T) we have an __index metamethod that is a table (M) that has itself an __index metamethod, which is a function (F). Suppose your request is satisfied and the function gets the original table as an additional argument. Then, unless I am mistaken, if F returns a non-nil value, both T and M will get a new key assigned with that value.

In certain cases, that might be undesirable. For example, we want to implement a "class" with constant generic "methods" (generic in the sense that they work whatever the content of T is, where T is one of the class, and have no upvalues bound to T-specific data) and variable T-specific "properties", then M should ideally only have those constant methods, and T should get "properties" from F without polluting M. How could we implement that efficiently?