Metamethods should be defined in class method table
7z99 opened this issue · 1 comments
7z99 commented
Hey,
I noticed in your constructors you make a new table as the object's metatable for each object which can impact memory negatively. Instead you should define your metamethods inside of the table that contains the functions so a single table used as the metatable is shared among all objects. It's a pretty minor change but,
local ParticleEmitter = {}
ParticleEmitter.__index = ParticleEmitter
-- ... then later in your ParticleEmitter constructor:
return setmetatable(self, ParticleEmitter)
joeldesante commented
Great recommendation! Metatables have always confused me but your simple explanation makes it clear why this would be beneficial. I plan on working on some updates tonight so I will definitely add this to the list.