You can achieve what you want by combining Doug's answer with the source script, for example:
Button = { x = 0, y = 0, w = 10, h = 10, Texture = "buttonimg.png", onClick = function() end } setmetatable(Button, { __call = function(self, init) return setmetatable(init or {}, { __index = Button }) end }) newbutton = Button { onClick = function() print("button 1 pressed") end } newbutton2 = Button { x = 12, onClick = function() print("button 2 pressed") end }
(I really tested this, it works.)
Change You can make it a little prettier and reuse it like this:
function prototype(class) return setmetatable(class, { __call = function(self, init) return setmetatable(init or {}, { __index = class }) end }) end Button = prototype { x = 0, y = 0, w = 10, h = 10, Texture = "buttonimg.png", onClick = function() end } ...
source share