Server Plugins
Read Me
What follows is an advanced subject. In almost all cases you should use the standard project based API. A server plugin is useful if you need to access specific functionality within multiple api projects, create a plugin that is internal to your company, or share with the community.
Custom built plugins can be used to extend the Coronium Core server. These plugins become available in the server-side core
namespace for use in server-side project API files.
Because of this, you must be careful in choosing the name of your plugin. If a name conflict exists, Coronium will always choose the internal module.
Creating Plugins
A custom plugin is simply a Lua module you place in a certain directory structure on your Coronium Core server.
Your custom plugins live in the /home/coronium/plugins directory.
Make sure to use the coronium user when uploading your plugins via SFTP.
Example Plugin
Custom plugins have access to the core namespace server modules as well.
--Basic plugin local echo = {} function echo.hello( name ) return "Hello " .. name end return echo
Namespaces
Your plugin should be placed in a unique directory to avoid conflicts with other developer plugins.
Example
plugins/ example/ echo.lua
In the example above the echo plugin is placed inside the plugins/example directory.
You can use a developer nickname, company, etc. as the directory name. You can store multiple plugins you create in this folder for use; providing each plugin has a unique name.
Example
plugins/ develephant/ echo.lua otherplugin.lua
Enabling plugins
To enable a plugin, add an entry to the /home/coronium/plugins/plugins.lua file. Choose the key the plugin will use, and then literally require
it.
Warning
Be very careful when editing the plugins.lua file. If the syntax is incorrect the service will not be able to start correctly. Make sure to use the coronium user when working with the plugins.lua via SFTP.
Example
--/home/coronium/plugins/plugins.lua local plugins = { --enable the echo plugin implementation echo = require("develephant.echo") } return plugins
Restart the Coronium service with sudo coronium restart
.
Accessing
Your plugin is available in the core
server-side namespace as the key specified in the plugins.lua file for use in server-side project API files.
Server API Example
local api = core.api() function api.test( input ) -- Using the custom `echo` plugin local resp = core.echo.hello( "Coronium" ) return resp end return api
The response should be "Hello Coronium" when received by the client.