Lua Script Extension and menu API

I was working on this issue and making some progress with the final API:

This is an example:

function init(plugin)
  print('foo init')

  if plugin.preferences.count == nil then
    plugin.preferences.count = 0
  end

  plugin:newCommand{
    id="fooFirstCommand",
    title="Foo First Command",
    group="cel_popup",
    onclick=function()
      plugin.preferences.count = plugin.preferences.count+1
    end
  }
end

function exit(plugin)
  print("foo exit - count=" .. plugin.preferences.count)
end

Both functions init() and exit() will be optional. The "group" attribute should indicate the exact menu where to put the new command (anyway if no group is specified, the command will be available for keyboard shortcuts anyway). (All commands are deleted/unregistered automatically when the extension is disabled/uninstalled or at exit, so generally there will no need to define an exit() function).

2 Likes