So I was curious and started to inspect code from Freya which is a framework for Roblox. I was reading the code for Arbiters and saw this code:
--code
Controller.new = Hybrid(function(f)
local newobs = newproxy(true)
local omt = getmetatable(newobs)
for k, v in pairs(ObserverMt) do
omt[k] = v
end
ObserverCallbacks[newobs] = f
ObserverEmitters[newobs] = Event.new()
ObserverRules[newobs] = { }
end)
--more code
The part that I'm curious about is
local omt = getmetatable(newobs)
for k, v in pairs(ObserverMt) do
omt[k] = v
end
I searched up on the wiki about newproxy and all it does is create a blank userdata.
Why not just do local omt = setmetatable({}, ObserverMt)?
What does newproxy(true) really do?
Does it have an effect on metatables? If so, what is it?
