I was looking up newproxy
on the RobloxWiki and I noticed it creates a new userdata.
Now, my question is, what is the point of attaching specific meta-methods such as __index and __call, etc when you can attach it to a table aswell with the same functionality?
Why would you use a metatable with userdata values with new proxy instead of just using an array?
Why
local proxyValue = newproxy(true) getmetatable(proxyValue).__index = {seraplz= function() print("@sera plz") end} proxyValue.seraplz()
Vs
local meta = { __index = {seraplz = "@sera plz"} } local array = setmetatable({},meta) print(array.seraplz)
Other than the obviously shorter way of doing the meta-table.
What are some strong advantages and disadvantages for both?
You can't use a Userdata returned by newproxy
with setmetatable
or rawset
. In effect - they are perfect proxies. The entire point of a proxy is indirect access, which you can read about here.
The downside is that newproxy
has been removed from Lua as of version 5.2, so don't rely on it working. Supposedly new features have made it redundant, but I have yet to actually figure out what they are. (ROBLOX currently uses Lua 5.1 - but I expect an upgrade eventually.)