lua-users home
lua-l archive

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


It's less flexible, rather than more, to impose a standard on the way different userdata are told apart.
If you like to use a __type metafield, then simply reassign type using either debug.getmetatable, or
via the C api.

For example, I like to use an integer ID stored at the start of each userdata. So I'd rather not have the
default type function lookup metatables and whatnot.

On Sat Jan 19 13:14 , 'Greg Fitzgerald' sent:

Hi Luiz,

>> Would there be any downside to Lua's 'type()' returning the value of a
>> '__type' metamethod if its type is 'userdata'?
>> return t == "userdata" and mt and mt.__type or t

> Yes, it'd break all programs that rely on type returning "userdata"...

How so?  It would only break programs with userdata types that have a metamethod named "__type".  All others would continue to return "userdata".  Do many (any?) Lua programs make use of a __type metamethod?

Thanks,
Greg