Should I use metatables?

I am making an OOP module, should I use metatables?
Example of what I mean:

-- metatables
local module = { }
module.__index = module

    local Class = setmetatable({ }, module)
    Class.Instance = "something"
    return Class

or should I do:

local module = { }

    local t = { }

    function t:print(...)

    return t

return module

I believe they achieve the same thing. If not, tell me!

1 Like

I think it depends on what you want to acheive here.

Personally, I’d use metatables if I wanted to have custom events/functions.

What does that mean? Do you mean custom RBXScriptConnection's?

I tried both, they worked completely the same.

Generally speaking the convention would be using metatables in order that class member functions would be defined outside of the constructor.

Both work, but I personally use metatables when following an OOP design.


You’re also not constructing functions for every object, which helps out with performance, especially when working with large quantities of objects

1 Like

I see where your going and what you mean- If I call the constructor lots of times new functions will be constructed as well.