What is the __type metamethod?

It’s not a metamethod, this is just a variable in the table and the variable is named ‘__type’.


The reason it prints that is because

{__type = "test"}

is a table (hence the curly brackets)

1 Like

Yes, i am good with this, and i understand really good OOP, but i not understand that it was a variable, why and how? So, my question is when use this?

You use it whenever you want.
You can assign values to it and read it.

local tab = {__type = "test"}
print(tab.__type) -- test
tab.__type = 4
print(tab.__type) -- 4

just like a normal variable, there’s no difference, because __type is a normal variable, it has nothing to do with metamethods and metatables, except that its name is similiar to the metamethod’s names

local tab = {a = "test"}
print(tab.a) -- test
tab.a = 4
print(tab.a) -- 4

In this case __type isn’t a true metamethod, but rather a value dictating a custom “type” of the custom “class”.


There is actually a __type metamethod, its just you can’t use it, or it just appears you cant.



Also, can’t we use the function “typeof()” or “type” with it? Pity. @EpicMetatableMoment , I just want to say that if it would be so, then we can use the new luau instead of this value. But that depends on the user. If you are interested, here is a link for you, hope it help.

it is a metamethod dude roblox uses it

It’s not a metamethod. Look at the documentation.

The code example that used __type explicitly checks it.

It’s literally just a table property with a similar naming scheme as a metamethod

look in the roblox source code bro its right there

it is used by roblox see lol

As explained to me by someone through DMs, the __type metamethod is not usable or accessible to developers. Therefore, my statement still holds true.

Because in the code sample, that’s all it is. Create a metatable with __type and try calling type or typeof with it

1 Like

you said its a table property and it is usable to developrs and we dont know what someone explains to you through dms so my point still stands

if its not acccessible to devs how come i was able to read it, every roblox instance and class has it

While it is a metamethod in Vanilla Lua, it is disabled in Luau. Period.

It is probably only effective on a specific type of userdata

No it was added in luau its not in vanilla lua

Oops yes indeed, what I meant it was enabled in Vanilla Luau, not Luau Handicapped

no its the same for all its just that only host-created user datas can use it

…So, not on luau handicapped??

what ru reffering to by handicapped??