lua-users home
lua-l archive

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


On Thu, 2006-01-19 at 10:19 +0000, Mark Meijer wrote:
> Without taking a position on whether or not the __typeof metamethod feature 
> should be added (I like the idea but I can't say much about what code it may 
> or may not break), with regard to its return values, I think that Lua is 
> more about providing flexibility and choice to their users, and less about 
> enforcing polite coding behaviour. I remember reading in PiL (I think) 
> something along the lines of, if you don't want to do this or this in your 
> code, then simply don't do it. In this respect I think forcing the first 
> return value of __typeof to be "userdata" by hardcoding it into the lua 
> core, is limiting and takes away that choice from the user. Besides it's an 
> extra condiion for the user to remember and deal with, which hurts the 
> language's simplicity and uniformity. Just my two cents on the subject.

I'm wondering exactly how the addition of __typeof would break existing
functions.  First, the argument of if you don't want it, don't use it.
Next the question I have is simple, if a third-party module is
attempting to inspect every userdata that comes along, I would consider
that an error.  Third party mods should only be using userdata that they
themselves created, so an error should occur when you pass in your
special userdata/table with the __typeof metamethod that returns "foo".
Implementing a __typeof metamethod, I think, would help provide a
universal code standard for using unusual data types, and would
therefore produce better code.

Though I agree that certain third-party modules may be broken by this,
I'd think that would only point out areas in the third-party code that
NEEDS to be improved.  I would certainly be irritated using something
third-party that starts messing with my userdata without my
knowledge/permission, and would probably not use such a module.

I do, however, feel that a __typeof metamethod would effectively be
useful only rarely outside of lua programs with large class heirarchies.
If I ever need it in an embedded scripting language, I will likely be
patching it in though.

JJS