mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 15:14:52 +09:00
Add Clusterio Library mod
Add a library mod for wrapping the Clusterio remote API and providing related utilities. This eases development of Clusterio related Lua code by providing the same interface for both mods and modules and also makes the serialize library available without having to duplicate it. It is not possible to implement this through save patching as mods cannot load Lua code from the level code like they can with code from other mods.
This commit is contained in:
1 parent
5ef6d02054
commit
1e6b807ae3
8 files changed
+328
-59
No files matched your search
@@ -1,42 +1,20 @@
|
||||
-- Important: Keep this API in sync with mod/api.lua
|
||||
local api = {}
|
||||
|
||||
|
||||
-- Table of events raised by clusterio
|
||||
api.events = {
|
||||
-- Raised after the name and id of an instance has been updated
|
||||
-- This may occur even if the id and name didn't change.
|
||||
|
||||
-- Event data:
|
||||
-- instance_id: The id of the instance.
|
||||
-- instance_name: the name of the instance.
|
||||
on_instance_updated = script.generate_event_name(),
|
||||
|
||||
-- Raised when the server is starting up
|
||||
-- This event serves as the stand-in for the on_init and
|
||||
-- on_configuration_changed events for modules. It is invoked as early
|
||||
-- as possible, before most but not all other events, every time the
|
||||
-- server is started up.
|
||||
|
||||
-- Use this event to initialize and and/or migrate the data structures
|
||||
-- you need. Keep in mind that Clusterio can switch from any version of
|
||||
-- your module to any version of your module so it should be able to
|
||||
-- handle both forwards and backwards migrations.
|
||||
on_server_startup = script.generate_event_name(),
|
||||
}
|
||||
|
||||
-- Send a table as json to Clusterio
|
||||
-- Send data to Clusterio over the given channel. Clusterio plugins can
|
||||
-- listen to channels and will receive an event with the data sent here.
|
||||
-- See docs/writing-plugins.md for more information.
|
||||
function api.get_instance_name()
|
||||
return global.clusterio.instance_name
|
||||
end
|
||||
|
||||
-- Note: Payloads greater than 4 MB will cause stuttering.
|
||||
function api.get_instance_id()
|
||||
return global.clusterio.instance_id
|
||||
end
|
||||
|
||||
-- Note: This is not a binary safe way of sending data. Strings embedded
|
||||
-- into the tables sent must be valid UTF-8 text.
|
||||
|
||||
-- Parameters:
|
||||
-- channel: string identifying which channel to send it on.
|
||||
-- data: table that can be converted to json with game.table_to_json
|
||||
function api.send_json(channel, data)
|
||||
|
||||
-- Escape bad characters. The question mark is used for separating the
|
||||
|
||||
Reference in new issue
Block a user