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

1 comment

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.