I'm creating objects from a class and want to iterate them later. Is there a more efficient way than this?
class1 = {}
class1.value1 = "1"
class1.value2 = 2
class1.tvalue1 = {}
function class1:new()
local class = self
local object = {}
setmetatable(object,class)
class.__index = class
object.tvalue1 = {}
table.insert(objects, object) -- to iterate them later, stupid way I think
return object
end
function class1:alterValue1(input)
self.value1 = input
return self.value1
end
function class1:alterValue2(input)
self.value2 = input
return self.value2
end
randomName = class1:new()
otherName = class1:new()
weirdoName = class1:new()
.
.
.
(n)
Is there a more efficient way to iterate the objects than inserting them into some kind of objects-table in the constructor?