Get getmetatable
to return nil
by a function I've assigned a __metatable
field to.
Code:
local tbl, mt = {}, { __metatable = function() return nil; end }; setmetatable(tbl, mt); print(getmetatable(tbl))
The call getmetatable(tbl)
is literally evaluating to the function itself and not calling it,
Is there a way to get this to happen, or would I just have to use some other value? I'd really prefer nil
being the output, but if not then oh well.
The __metatable
field takes any value, not just a function. Furthermore it will NOT cause getmetatable()
to call the function you assigned to it. It will simply return the function instead of the metatable, but not call it.