Reputation: 688
Its obviously that getmetatable can access the metatables of several types:
getmetatable("")
getmetatable({})
getmetatable(newproxy(true))
However it appears as though you cannot get the metatable of other types (functions aside). There appears to be no way to access the metatable of numbers, booleans, or nil.
I was also wondering if one would be able to access a metatable of the entire table type. To be able to do something like this:
({}) + ({})
Upvotes: 2
Views: 3387
Reputation: 4311
Numbers, Booleans and nil have no metatable by default (hence getmetatable returning nil
). You can give them one with debug.setmetatable
though.
There is no common table metatable. (and same for userdata (at least of the heavy variety))
Upvotes: 0
Reputation: 62573
strings, numbers, nil, functions and lightuserdata have a single metatable for the whole type. tables and full userdata have a metatable for each instance.
from the docs:
Tables and full userdata have individual metatables (although multiple tables and userdata can share their metatables). Values of all other types share one single metatable per type; that is, there is one single metatable for all numbers, one for all strings, etc.strings, etc.
there's no 'table type metatable', just like there's no 'metatable for this string'
the string type has the 'string' table as metatable by default; but you can set the metatable for other types using the debug.setmetatable()
function.strings, etc.
Upvotes: 5