5

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
]]
David
  • 693
  • 1
  • 7
  • 20

1 Answers1

0

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.

Community
  • 1
  • 1
Doug Currie
  • 40,708
  • 1
  • 95
  • 119