Typeof override

This is kinda a long shot and I’m not actually expecting this to be possible, but what does roblox use to determine what the type a userdata is when typeof is called on it, and can you implement your own types?
I know __type used to be a thing so I’m guessing that’s all handled internally in C++ now.

1 Like

You could just overwrite typeof to first check through all your custom types, and if it’s not one of those types, call the “real” typeof. E.g.

local __oldTypeof

local function myTypeof(object)
	if object and __oldTypeof(object) == "table" then
		if object.MyClassName then
			return object.MyClassName
		end
	end

	--If we haven't returned one of our "custom types" yet, just return the built-in type of the object
	return __oldTypeof(object)
end	

--If this is a ModuleScript, then return the function
return myTypeof

Return/require it from a ModuleScript, and assign it to a variable called typeof. Falling back to the “old typeof” means you don’t have to deal with all the built-in types.