lua-users home
lua-l archive

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

As example when " library authors took that mechanism and built a more complete class or type system " happened was __pairs metamethod in my opinion.

On Thu, Dec 24, 2020 at 9:33 PM Andrew Starks <> wrote:

On Thu, Dec 24, 2020 at 10:55 AM Spar <> wrote:
I used __type with overridden type function for my scripts


I've used similar magic and as has been pointed out, this has been done by many libraries.

To me, the border between "a good idea" and "a good idea for your code, but not for the language" is:

What's required for interoperability? In this case, is the situation improved for the user if the language offers this mechanism for subtyping tables?

Drawing this border is tricky. As it is, if I know how a certain library works, and I have chosen a different way, I can pretty easily patch their method into my own and deal with it appropriately, if not somewhat clumsily. Perhaps adding broader support for `__name` and a `table.type` method is a good idea. Can library authors take that mechanism and build a more complete class or type system? Would the existence of that feature make those systems more interoperable?

Or would it cause confusion, owing to the different ideas and requirements of different users and library authors, who would now be using `__name` and extending it in different ways?

I don't know the answer to this. Just asking questions. :)