How Lua plugins and hooks work
masterLua plugins allow you to run custom scripts through hooks triggered by Server Manager (SM) events.
Execution Flow:
- An event occurs in the SM UI (e.g., the 'Event Start' button is pressed).
- The SM backend calls a specific Lua function (e.g.,
onEventStart) and sends the event data encoded as JSON. - The Lua script receives the data, decodes it into a Lua
Table, and can modify the contents. - The Lua script encodes the modified data back to JSON and returns it to the backend.
- The backend uses the (potentially modified) data to execute the event.
Important Constraints:
- Type Fidelity: While Lua is not strictly typed, the backend is written in Go and is strictly typed. When modifying data in a Lua
Table, you must keep the data types consistent. For example, do not change anintvalue to afloat. - JSON Handling: The backend handles JSON encoding/decoding within the Lua functions. Do not modify the existing encoding/decoding logic, as this will break the integration.
Event Start button is pressed in the SM UI
Backend calls Lua function onEventStart and sends the configured event encoded as json
Lua code can be used to modify the event
Lua encodes the event back to json and returns it to the backend
Backend starts the event