Trouble understanding newproxy() function

I have read many posts on the newproxy() function but I still haven’t been able to grasp the full application of using it. Like I know with newproxy() you can indirectly access a table and how its a lua global and userdata, but why would that be useful?? And what would be the best application / scenario of where I would use newproxy()

I am not really a fast learner I’m more of a visualizer so I would appreciate a code example too. Thanks

You can’t use setmetatable on a userdata, nor can you use rawget or rawset on a userdata. Making them perfect proxies, hence newproxy. And in Lua 5.1, __len only fires on userdata. In Roblox you probably won’t find too much use for newproxy though

1 Like

ohh so basically newproxy() is more convenient than without it since you don’t have to type rawget or rawset all the time due to indirect access of a proxy. I think thats what u mean. Gotchu.

no, not that. The point is to prevent the use to obtain access to private members.

3 Likes