lua-users home
lua-l archive

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


Jeff Sheets wrote:
> 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.

I think the real problem is not when you use __typeof to report some
custom type string, but rather when a userdata poses as one of the
built-in types. When __typeof returns "table" ("string"), does the
corresponding object really behave like a table (string)? Think of
ipairs, pairs, get/setmetatable (all the string functions). True, in a
modified Lua you can probably do all that, and adding support for
__typeof seems like a minor issue in this situation, but what about
stock Lua?

As useful as __typeof may be in a controlled for power-users, I guess
it is this kind of thinking that makes the Lua authors hesitate about
adding it to stock Lua. (Am I right here? ;)

Just playing devil's advocate,

Holger Stenger