lua-users home
lua-l archive

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


Would there be any downside to Lua's 'type()' returning the value of a '__type' metamethod if its type is 'userdata'?

That is, this behavior (but done in the VM):

local oldType = type
function type(x)
   local t, mt = oldType(x), getmetatable(x)
   return t == "userdata" and mt and mt.__type or t
end

The reason I ask is that I'd like to be able to create a C library that add new types in such a way that there would be no way for a Lua user to know those types were implemented with userdata and not by modifying the VM.  The binary and unary metamethods get us most of the way there - just need a type metamethod to complete the abstraction.

Thanks,
Greg