How does one change the length operator (#
) for a table in Lua, the manual suggests assigning the __len
function in a metatable and then assigning that metatable to the table I want to override, but this doesn't work as expected? I do not have the option to override this on the C side.
turtles = {1,2,3}
setmetatable(turtles, {__len = function(mytable) return 5 end})
print(#turtles)
--returns 3, should return 5