Lua Code:
local allFrames = {}
local framesConstructor = {}
function framesConstructor:create(name, width, height, constructor, updater)--method for frame creation - simulates OOP
self.frame = CreateFrame("Frame", name .. "BackgroundFrame", mainFrame)
self.name = name
self.height = height
self.width = width
self.constructor = constructor
self.updater = updater
return self
end
function framesConstructor:create2(name, width, height, constructor, updater)--method for frame creation - simulates OOP
local tbl = {}
tbl.frame = CreateFrame("Frame", name .. "BackgroundFrame", mainFrame)
tbl.name = name
tbl.height = height
tbl.width = width
tbl.constructor = constructor
tbl.updater = updater
return tbl
end
tinsert(allFrames, framesConstructor:create("runicpower", 120, 16, "setupRpower", "updateRpower"))
tinsert(allFrames, framesConstructor:create("runes", 120, 12, "setupRunes", "updateRunes"))
tinsert(allFrames, framesConstructor:create("diseases", 64, 64, "setupDis", "updateDis"))
tinsert(allFrames, framesConstructor:create2("runicpower", 120, 16, "setupRpower", "updateRpower"))
tinsert(allFrames, framesConstructor:create2("runes", 120, 12, "setupRunes", "updateRunes"))
tinsert(allFrames, framesConstructor:create2("diseases", 64, 64, "setupDis", "updateDis"))
for i=1, #allFrames do
print(allFrames[i].constructor)
end
The first 3 tinserts replicate what you are doing and in the print, they all end up containing the information of the last call to create() because "return self" means return framesConstructor (always returning the same table, not a new instance). The last 3 create/return a new table each call containing the passed information.
If you wanted an inherited "instance" of framesConstructor for each entry:
Lua Code:
tinsert(allFrames, Mixin({}, framesConstructor))
allFrames[#allFrames]:create("runicpower", 120, 16, "setupRpower", "updateRpower")
tinsert(allFrames, Mixin({}, framesConstructor))
allFrames[#allFrames]:create("runes", 120, 12, "setupRunes", "updateRunes")
tinsert(allFrames, Mixin({}, framesConstructor))
allFrames[#allFrames]:create("diseases", 64, 64, "setupDis", "updateDis")