Creates a zero-length userdata with an optional metatable.. newproxy is a experimental, undocumented and unsupported function in the Lua base library. It can be used to create a zero-length userdata, with a optional proxy.
This function allows you to bypass the table type restriction on setmetatable, and thus create just a metatable. One of the main benefits from doing this is that you don't have to take the full overhead of creating a dummy table, and it's the only object that honors the metamethod __len.
See also Secure execution utility functions, Blizzard internal functions.
Signature:
userdata
=
newproxy(boolean)
or
newproxy(userdata)
Arguments:
boolean
- Controls if the returned userdata should have a metatable or not. (boolean
)userdata
- Needs to be a proxy. The metatable will be shared between the proxies. (userdata
)
Returns:
userdata
- A zero-length user-data object. (userdata
)
Examples:
proxy = newproxy(true) getmetatable(proxy).__len = function() return 3 end print(#proxy) -- prints 3