jay5476, on 02 September 2013 - 01:59 AM, said:
I want to make it so the user does not have t set the metatable of there button to mainButton
You could make a function which creates a new class for you given your own constructor. Example usage of such a function:
local myButtonSubclass = class(mainButton, function(self, x, y, w, h)
mainButton.init(self, x, x + w, y, y + h)
end)
It could be implemented as
function class(extend, constructor)
local newClass = { }
newClass.init = constructor
setmetatable(newClass, extend)
function newClass.new(self, ...)
local self = setmetatable({ }, {__index = newClass})
constructor(self, ...)
return self
end
return newClass
end
I do something similar in my SEE runtime. You can of course implement this in different ways to suite your needs.