How to create a plugin?
Last updated
Last updated
The Lua Plugin API allows you to extend Infinity's core functionality and create custom plugins. Whether running as independent scripts within the engine, or creating new services exposing Web endpoints
This tutorial describes how to write plugins using the updated plugin framework and best practices to speed up your development process.
Check that the plugins folder is well configured, the default is that you use the path $INFINITYDIR/plugins/
but you can configure the folder however you want in the file called infinity.conf
:
In this tutorial, we'll use a simple sample plugin designed to work with a new plugin framework, which simplifies plugin development. The plugin performs a simple task: once invoked by the engine it exposes a web interface /engine/status
with the method of then obtaining a printout for the user if the engine is running successfully.
You can download engine_status.lua
from here:
.lua
file to startTo begin with, your plugin must consist of a single Lua file that serves as an entry point. This file should define the main logic and include the necessary imports and primary functions that will be executed when the plugin is run.
Currently Infinity v1 only supports web gateways using plugins, but we have endpoints that the engine uses in websocket, if you create a web gateway and don't put a response by default, Infinity understands that the gateway exists and returns (200 OK)
All objects exposed by the engine, only each feature has 1 exposure, for example the running engine, you can access its methods and members through _engine
Note that I pass _engine.server
, which is used by the engine, to the Web
instance as the first parameter. Then, I access the is_running
member, which serves as an object _engine
control.
Expected response when we hit the /engine/status
endpoint :
If the created plugin needs to manipulate tables, it is necessary to import table
into lua.
lua.standard.libraries = ["base", "table"]
— include the table for the lua state to load the table
For more information about the response possibilities and methods supported by the gateway, go to section.
You can access all the objects that the mechanism exposes, you can check in the section the objects and their methods and members.
we will use the class to create a json and return the engine status with its fields to our endpoint
We use a default state to load plugins. So, let's assume you want to use a standard Lua library—you need to load it before your plugin. To do this, you must modify the lua.standard.libraries
configuration file, specifying the name of the standard Lua library. I recommend checking the section in the configuration file.