What is newproxy and how is it useful?
Asked Answered
A

1

6

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
]]
Audiometer answered 1/10, 2014 at 23:36 Comment(3)
lua-users.org/cgi-bin/…Haunted
Slightly more lightweight than a table, and supports some meta-methods not supported on tables before it was removed again.Cheesy
newproxy was deprecated in Lua 5.1 and removed in Lua 5.2.Journal
C
1

See this related SO question and answer. Empty userdata were useful for detecting when GC reclaimed objects. That role can be played by zero sized tables in Lua 5.2.

Centroclinal answered 2/10, 2014 at 1:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.