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

What is newproxy and how is it useful?

Asked by 9 years ago

I was messing around with Lua yesterday and stumbled upon the 'newproxy' function.

http://wiki.roblox.com/index.php?title=Function_dump/Basic_functions#newproxy

I kind of understand it, but I'm not sure how it is useful. I know it creates a blank userdata object with a metatable attached (if the argument is true).

How it newproxy useful? Here is an example of what I did while messing around with it:

local proxy = newproxy(true)
local metatable = getmetatable(proxy)

metatable.__index = function(array, key) print(array, key) end

local y = proxy[100]

--[[
    OUTPUT:
        userdata: 0x443ad4b4 100
]]

1 answer

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

Proxies in this regard appear to just be empty Tables with another empty Table set as its metatable, assigned as a 'userdata' (I.e. a C-level data construct) instead of a Table.

I'm using this as reference, since as that page says, newproxy is undocumented.

EDIT: Basically, turning a Table into an Object, sorta.

Ad

Answer this question