expose and require_plugin), and one tells the others what happened (emit and on_plugin). None of these needs a permission.
Everything that goes from one plugin to another is copied as JSON, by the rules of reskate.json: tables, strings, numbers, booleans and nil cross, and functions, vectors and buffers never do. A plugin never gets another plugin’s tables, only copies of them.
A plugin is named by its mod folder name or by the name in its manifest.json, without regard to case. Only plugins running on the same side reach each other: a player’s copies talk to a player’s copies, and the server copies to the server copies.
Libraries
reskate.expose(functions)
Offers functions to other plugins. Each call replaces what the plugin offered before: pass every function each time.
Names and the functions they call:
{name = function, ...}. At most 64, each name at most 48 characters.Raises an error for a key that is not a string, a value that is not a function, more than 64 functions, or a name longer than 48 characters.
reskate.require_plugin(name)
Gets the functions another running plugin exposes.
A read-only table with one function for each function the plugin exposed when you asked, or
nil when it is not running.spots.count()), not a colon.
A call raises an error, in your plugin, named <plugin>.<function>: <why>, when:
- the plugin is no longer running;
- it no longer exposes that function (it called
exposeagain without it); - it raised an error (its own log says which), or it stopped;
- it is in a call already: a plugin cannot be called back into while it is calling you;
- an argument or the result cannot be copied as JSON.
The function runs under the other plugin’s limits: a call past 50 ms is warned about and one past 1000 ms stops it (see limits), and its errors count against it, not you. A plugin can get its own library, but calling it raises “a plugin calls its own functions directly”.
Events between plugins
reskate.emit(event, data)
Sends an event to every other running plugin with an on_plugin handler for it. It arrives at the next tick, not at once.
The event’s name: 1 to 48 letters, digits,
_, . or -. Your own names; they are not the game’s events.true when it was queued; false when more than 1024 events from all plugins wait for the next tick.Raises an error for a bad name, data that cannot be turned into JSON or is larger than 64 KB, and more than 64 events from one plugin in one tick. The 64 are counted in the plugin’s own ticks, wherever the
emit runs: a handler, a timer or a console command. A plugin does not hear its own events.reskate.on_plugin(source, event, handler)
Adds a handler for events another plugin emits.
The plugin to listen to, by its folder name or
manifest.json name (1 to 48 letters, digits, _, . or -), or "*" for any plugin.Called with
(source, data): the emitting plugin’s id (reskate.id: its folder name, or <folder>@server for a server copy on a lobby’s host), and a copy of its data.Raises an error for a bad name, a handler that is not a function, and more than 64
on_plugin handlers in one plugin. There is no way to take a handler away. Each handler call is timed like any handler: a warning past 50 ms, stopped past 1000 ms (see limits).