The plugin function will be called in response to the application event.
This indicates an observer pattern. For example, if your application has two events: "foo" and "bar", you can write something like:
HostApp.listeners = { foo = {}, bar = {}, } function HostApp:addListener(event, listener) table.insert(self.listeners[event], listener) end function HostApp:notifyListeners(event, ...) for _,listener in pairs(self.listeners[event]) do listener(...) end end
Then, when the foo event occurs:
self:notifyListeners('foo', 'apple', 'donut')
A client (e.g. a plugin) interested in the foo event would simply register a listener for it:
HostApp:addListener('foo', function(...) print('foo happened!', ...) end)
Expansion to suit your needs.
In particular, I am wondering what is the best way to pass parameters to the plugin and get return values
The plugin simply provides you with a function to call. You can pass any parameters you want and handle their return values, but you want to.
source share