mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 15:33:12 +09:00
Rework module loading
Change module loading to use a module.json file describing the module and patch in all files in a directory path passed to the patcher instead of having to pass the files names and their content. This allows the specification of which files should be passed to the event_handler lib and an easy implementation of loading stand alone modules.
This commit is contained in:
1 parent
11992d1839
commit
80bd75ba16
11 files changed
+120
-47
No files matched your search
@@ -180,13 +180,40 @@ for some pointers if you get stuck.
|
||||
Clusterio Modules
|
||||
-----------------
|
||||
|
||||
Modules are primarily used by plugins to inject code into Factorio
|
||||
games with the save patcher. The save patcher puts modules into the
|
||||
`modules` folder of the Factorio save and adds code to `control.lua` to
|
||||
Modules are primarily used by plugins to inject code into Factorio games
|
||||
with the save patcher, though it's also possible to make stand alone
|
||||
modules that are loaded into the game if you don't need the capabilites
|
||||
of the plugin system. The save patcher puts modules into the `modules`
|
||||
folder of the Factorio save and adds code to `control.lua` to
|
||||
load the modules by requiring it and passing the result of the require
|
||||
call to the `add_lib` function of the event_handler lib. See the
|
||||
section on the [event_handler interface](#event_handler-interface) for a
|
||||
detailed description on how this works.
|
||||
detailed description on how the event_handler lib works.
|
||||
|
||||
Stand alone modules are placed into the modules folder of Clusterio,
|
||||
plugin modules are located in the module folder of the plugin. In
|
||||
either case a `module.json` file is required and has the following
|
||||
structure:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "my_module",
|
||||
"load": ["foo.lua"]
|
||||
}
|
||||
```
|
||||
|
||||
The following entries are supported in the module.json file:
|
||||
|
||||
- `name`:
|
||||
Name of the module, must match the folder the module is located in
|
||||
for stand alone modules or the name of the plugin the module is
|
||||
located in.
|
||||
- `load`:
|
||||
Lua files to load with the `event_handler` lib. They should be
|
||||
specified as paths that's relative to the module and uses forward
|
||||
slashes as directory sepparators. Thus foo.lua will require a file
|
||||
by that name and feed the result of that require to the event
|
||||
handler lib.
|
||||
|
||||
Because modules can be patched into an existing game you cannot rely on
|
||||
the `on_init` callback to be called in Clusterio Modules. Nor can you
|
||||
@@ -194,11 +221,6 @@ rely on the `on_configuration_changed` callback, as this is not called
|
||||
when level code changes. Instead you will have to initialize whatever
|
||||
global variable you need when you first use them.
|
||||
|
||||
Currently any files in a folder named `lua` in a Clusterio plugin is
|
||||
assumed to be a module and will be patched into the save before starting
|
||||
up Factorio. This will most likely change with the planned plugin
|
||||
restructuring.
|
||||
|
||||
|
||||
Clusterio Plugins
|
||||
-----------------
|
||||
|
||||
@@ -18,7 +18,8 @@ The basic file structure of a plugin is the following.
|
||||
+- instance.js
|
||||
+- test/
|
||||
| +- plugin.js
|
||||
+- lua/
|
||||
+- module/
|
||||
+- module.json
|
||||
+- plugin.lua
|
||||
|
||||
The most important file is the `info.js` file. Without it the plugin
|
||||
@@ -70,6 +71,12 @@ The following properties are recognized:
|
||||
Object with link messages definitions for this plugin. See guide
|
||||
for [defining link messages](#defining-link-messages) below.
|
||||
|
||||
The optional module folder contains a Clusterio module that will be
|
||||
patched into the save when the plugin is enabled. See the section on
|
||||
[Clusterio Modules](developing-for-clusterio.md) in the Developing for
|
||||
Clusterio document. The only restriction imposed on modules embedded
|
||||
into plugins is that they must be named the same as the plugin.
|
||||
|
||||
While there is no standard for how to organize a plugin it's recommended
|
||||
to put the MasterPlugin class definition into master.js and the
|
||||
InstancePlugin class definition into instance.js. You can put them into
|
||||
|
||||
Reference in new issue
Block a user