The process of binding an action:
-- load the package PkgLoad("pcb-gpmi/actions", 0); -- action callback function ev_action(id, name, argc, x, y) if name == "cake" then size = action_arg(1); -- put cake drawing code here else -- must be candy amount = action_arg(1); -- put candy drawing code here end end -- register and bind action action_register("cake", "cake center xy?", "cake service", "cake(size)", ""); action_register("candy", "candy cloud center xy?", "cake service", "candy(amount)", ""); Bind("ACTE_action", "ev_action");
When the script is unloaded all actions the script registered are removed from pcb-rnd automatically.
PkgLoad("pcb-rnd-gpmi/actions", 0); function ev_action1(id, name, argc, x, y) action("undo()") action("undo()") end -- register and bind action action_register("untwo", "", "undo twice", "untwo()", "CONTEXT!");
The above script registers a new action called untwo(). When untwo() is executed, it executes action undo() twice.
The first argument of create_menu() is the menu path. The path is a list of visible menu names separated by slashes (e.g. "/main_menu/File/Save as..." means "File" menu, "Save as..." submenu).
Paths are interpreted as menu paths, which are a slightly simplified version of lihata paths found in menu.lht. Basically there's a main directory directly under root that determines the type of the menu:
The simplification compared to lihata paths is that only menu and submenu names are on the path, so lihata nodes like "li:submenu" should be ignored. In other words, the path represents how the menus can be reached from the user interface, plus a "main menu type prefix" as discussed above.
By convention, scripts should create new menu items under the "/main_menu/Plugins/" menu.
The following example lua script registers a new menu item
PkgLoad("pcb-rnd-gpmi/actions", 0); function ev_gui_init(argc, argv) create_menu("/main_menu/Plugins/foo", "undo()", "o", "Ctrl<Key>o", "tooltip for foo"); end -- register and bind action Bind("ACTE_gui_init", "ev_gui_init");
When the user clicks on the menu, the action script specified in the second argument of create_menu() is executed. Thus the script usually registers a new action first then registers one or more menu items executing those actions.