Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
5

Difference between metatable usage with newproxy and tables?

Asked by 9 years ago

newproxy

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?

1 answer

Log in to vote
3
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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 newproxyhas 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.)

0
I'm still slightly confused. Can you provide an example of how it is used for indirect access? DigitalVeer 1473 — 9y
0
The article I linked gives a better overview of it than I can: http://www.lua.org/pil/13.4.4.html adark 5487 — 9y
Ad

Answer this question