[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Feature Request: type() consult __type for userdata
- From: "Greg Fitzgerald" <garious@...>
- Date: Fri, 18 Jan 2008 16:44:53 -0800
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