Hi,
In Roblox, If you were to have access to the C side and be able to modify the metamethods of Instances such as game
aka DataModel, and you were to modify the __type
metamethod of it, calling the typeof()
and passing the Instance as the first arg will return the string that you set to the __type
metamethod.
local mt = unrestrictedgetmetatable(game) -- pretend this is a function which has access to the C side and has the same functionality as getmetatable except it bypasses __metatable restrictions
print(type(game)) -- userdata
print(typeof(game)) -- Instance
mt.__type = "spoofed"
print(type(game)) -- userdata
print(typeof(game)) -- spoofed
Now, since Instances are just userdatas, and you can create your own blank userdata with a metatable with newproxy(true)
, you can make objects that act like Instances. With a newproxy, you can utilize metamethods that Instances use, such as __namecall
and etc. But there’s an issue. __type
does not seem to work on userdatas which I created. I was wondering I did something wrong, or if this was intentional, or if this is a bug.
local proxy = newproxy(true)
local mt = getmetatable(proxy)
mt.__type = "hi"
print(type(proxy)) -- userdata
print(typeof(proxy)) -- userdata
Is this intentional and I really cant use the __type
metamethod on my own userdata? Or perhaps a bug? Or maybe I did something wrong?
Thank you!