Menu.count readonly property
Get the current count of menu items.
Example
local ui = require "ui"
-- create a simple Window
local win = ui.Window("Menu.count 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