Code: Select all

```
local button = {}
button.__index = button
function newButton(f)
return setmetatable({function = f}, button)
end
function button:update(dt)
-- Assume clicked() is a pre-written function.
if clicked(self) then self.function() end
end
```

Code: Select all

```
local square = {}
square.__index = square
function newSquare(f)
return setmetatable({n = 0, button = newButton(?)}, square)
end
function square:increment()
self.n = self.n + 1
end
```