What is the best method and what do u guys do?
1) Give the object keys that refrence to classes its composed of:
function Car.new(properties)
local NewCar = setmetatable(properties, {__index = Car})
NewCar.Wheels = Wheels.New()
NewCar.Engine = Engine.new()
return NewCar
end
2) Make the class composed of components:
local Components = {Classes}
local Car = setmetatable({}, {__index = function(t, k)
local m
for _, Component in Components do
if Component[k] then
m = Component[k]
break
end
end
return m
end)
- Option 1
- Option 2
0 voters