You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
This will load all plugins in the current user's Library/Application Support/CommandPost/Plugins folder.
cp.plugins.getPluginModule(id)
Once the plugins have been loaded, the module can be accessed by their ID via the getPluginModule(id) function. It will return the module returned by the plugin's init function. This can also be done via the default function for the library. Eg:
plugins("my.plugin.id").doSomething()
Plugin Modules
Plugins typically have two parts:
The plugin table, which defines details about the plugin, and
The module, or result, which could be anything, which is returned from the init function.
A plugin file should return a plugin table that allows the plugin to be initialised. The table will look something like this:
localmodule= {}
localmodule.init(otherPlugin)
-- do stuff with otherPlugin hereendlocalplugin= {
id="my.plugin.id",
group="foo",
dependencies= {
["some.other.plugin"] ="otherPlugin",
},
}
functionplugin.init(dependencies)
-- do stuff to initialise the module heremodule.init(dependencies.otherPlugin)
returnmodule
}
functionplugin.postInit(dependencies)
-- do stuff that will happen after all plugins have been initialised.end
As you can see above, plugin module can have a few simple functions and properties. The key ones are:
plugin.id
This is a unique ID for the plugin. It is used to load the plugin externally, as well as to define dependencies between plugins.
plugin.group
This is the group ID for the plugin. This is used to group plugins visually in the Properties panel for Plugins.
plugin.required
This optional property can be specified for plugins which should never be disabled. This should only be set for plugins which will break the application if disabled.
plugin.dependencies
This is a table with the list of other plugins that this plugin requires to be loaded prior to this plugin. Be careful of creating infinite loops of dependencies - we don't check for them currently!
A plugin will only have its init function called after its dependencies have successfully had their init functions called. Additionally, if a plugin has a postInit, all declared postInits for dependencies will have been called prior to the plugin's postInit function.
function plugin.init(dependencies[, environment]) -> module
This function is basically required. It will be executed when the plugin is initialised. The dependencies parameter is a table containing the list of dependencies that the plugin defined via the dependencies property. The environment provides access to resources such as images, HTML files, or other lua modules that are bundled with the plugin. See Simple vs Complex Plugins below.
As you may have noted, there are two ways to specify a plugin is required. Either by simply specifying it as an 'array' item (the first example) or as a key/value (the second example). Doing the later allows you to specify an alias for the dependency, which can be used in the init(...) function, like so:
localplugin= {}
plugin.dependencies= {
"cp.plugins.myplugin",
["cp.plugins.otherplugin"] ="otherplugin"
}
functionplugin.init(dependencies)
localmyplugin=dependencies["cp.plugins.myplugin"]
localotherplugin=dependencies.otherplugin-- do other stuff with the dependenciesreturnmyinstanceendreturnplugin
Simple vs Complex Plugins
There are two types of plugin structures supported. The Simple version is a single .lua file that matches the above format for plugin. The Complex version is a folder containing an init.lua file that matches the above format.
The key advantage of Complex Plugins is that the folder can contain other resources, such as images, HTML templates, or other .lua files - including 3rd-party libraries if desired. These can be accessed via two main mechanisms:
The second environment parameter in the init function. This is a cp.plugins.env table, which provides access to files and templates inside the plugin folder. See the documentation for details.
The standard require method will allow loading of *.lua files inside the plugin from the init.lua.
For example, if you have a file called foo.lua in your folder, it can be required like so:
localfoo=require("foo")
You do not have to know anything about where the plugin folder is stored, or use the plugin ID. Just use the local file path within the plugin. If you have another file in a foo folder called bar.lua, it can be loaded via:
localfooBar=require("foo.bar")
These modules will not be accessible to other plugins or to the main application. They are only available to code inside the plugin.