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.


userdata = newproxy(boolean) or newproxy(userdata)


  • 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)


  • userdata - A zero-length user-data object. (userdata)


proxy = newproxy(true)
getmetatable(proxy).__len = function() return 3 end
print(#proxy) -- prints 3
This function is defined in the Lua standard libraries