__type metamethod not working on a newproxy?

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!

__type isn’t a Lua or Luau metamethod.


Here’s the internal metatable of an Instance warned in the console, and a change being done to __type live.

__type only works internally

^ this. It’s still not a Lua or Luau metamethod, but it’s likely being manually indexed by typeof on the C side. You can override typeof but that would require metatable access if you wanted to keep the __type schema.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.