Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is getmetatable essentially useless?

Asked by 5 years ago

I've never seen getmetatable used anywhere. Is it useless? Can't you just return the setmetatable and cache it into a variable?

You could do something like this:

local tab = {}

function tab.new()
    return setmetatable({}, tab)
end

local s = tab.new() -- here is your metatable
0
getmetatable is not useless. The call `setmetatable(x, m)` sets `m` to be `x's metatable. You can **get** `x`'s metatable by calling `getmetatable(x)`. getmetatable(x) will return nil if `x` has no metatable. User#24403 69 — 5y

Answer this question