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:
Hornwitser committed 2020-03-12 15:39:25 +01:00
1 parent 5ef6d02054
commit 1e6b807ae3
8 files changed
+328 -59

No files matched your search

+22 -18
View File
@@ -32,26 +32,30 @@ function clusterio_private.update_instance(new_id, new_name)
end
function impl.add_remote_interface()
remote.add_interface('clusterio_api', {
-- Returns a table of events raised by clusterio
get_events = function()
return api.events
end,
-- This is not part of the add_remote_interface callback to ensure it is
-- available when the clusterio_lib mod is loaded. The reason this is
-- neccessary is that on_init for newly added mods happen before on_load
-- for existing mods, and the add_remote_interface callback is done in
-- on_load. See https://forums.factorio.com/viewtopic.php?f=25&t=81552 for
-- more details.
remote.add_interface('clusterio_api', {
get_events = function()
return api.events
end,
-- Returns the instance id the game is run under
-- This may change over time and/or be nil.
get_instance_id = function()
return global.clusterio.instance_id
end,
get_instance_id = function()
return global.clusterio.instance_id
end,
-- Returns the name of the instance the game runs under.
-- This may change over time and/or be nil.
get_instance_name = function()
return global.clusterio.instance_name
end,
})
end
get_instance_name = function()
return global.clusterio.instance_name
end,
get_file_no = function()
global.clusterio_file_no = (global.clusterio_file_no or 0) + 1
return global.clusterio_file_no
end,
})
return impl