Metatables __len description inaccurate

The Metatables page has an inaccurate description for the “__len” metamethod. It states (at the time of this post) the following:

Fired when the # length operator is used on the Object. NOTE: Only userdatas actually respect the __len() metamethod in Lua 5.1. As userdata cannot be created on Roblox, this metamethod is effectively disabled.

The description states that userdata cannot be created on roblox which is inaccurate as the global function “newproxy” allows developers to do just that. Using a newproxy(true) userdata you can utilize the __len metamethod which can be validated using the following code:

local Proxy=newproxy(true)
local Meta = getmetatable(Proxy)
Meta.__len = function(tab) return 1337 end
print(#Proxy)

Outputs: 1337

6 Likes