Code: Select all
function callback1()
print("button1")
end
function callback2(
print("button2")
end
buttons = {{ x = 10, y = 10, width = 100, height = 100, callback = callback1 }, { x = 20, y = 20, width = 25, height = 27, callback = callback2}}
Code: Select all
for i,button in ipairs(buttons) do
--do stuff with the button
end
Code: Select all
function newButton( x, y, width, height )
table.insert(buttons,{ x = x, y = y, width = width, height = height }
end
function buttonClicked( mouseX, mouseY )
for i,button in ipairs(buttons) do
if mouseX > button.x and mouseX < button.x + button.width and mouseY > button.y and mouseY < button.y + button.height then
button.callback()
end
end
end