My goal
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))
Problem
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.

8 comments
no
you can run the function inside the table by saying print(getmetatable(tbl)())
It does print the function memory address, but I want getmetatable to return the result of the function which is nil
so you don't want to do getmetatable(tbl)(), you want to call the function when you get the metatable, not afterwards?
No i want it to return nil, i want getmetatable to return nil
You could do the following, not sure if theres a way to have the function inside the table since Lua will error because it's expecting a metatable https://pastebin.com/ZqCj1ejL I'll look into it some more if that isn't okay
just set __metatable to nil
Not gonna work since it won't even add the field