Menu:add(itemtext, [ submenu ]) method
Append a new item to the Menu.
Parameters
itemtext
A string representing the item text to be added to the Menu.This item can later be accessed using the Menu.items property, as a MenuItem object.
submenu
An optional submenu Menu object associated with the just added menu item.
Return value
This function returns the added MenuItemExample
local ui = require "ui"
-- create a simple Window
local win = ui.Window("Menu:add() sample", 316, 246)
local button = ui.Button(win, "Add Menu item", 110, 86)
-- create a Window menu with one menu item "Items" with an empty sub menu
win.menu = ui.Menu()
win.menu:add("Items").submenu = ui.Menu()
win:status("'Items' has no MenuItems")
function button:onClick()
local items = win.menu.items[1].submenu
-- add a new item to the submenu "Items" and set a MenuItem:onClick() event handler
items:add("Item"..items.count+1).onClick = function (self)
ui.info("You have clicked on "..self.text)
end
win:status("'Items' has "..items.count.." MenuItems")
end
-- shows the Window
win:show()
-- update user interface
repeat
ui.update()
until not win.visible