Module Remote

Description

Module Status: Polishing.

Usage:

    local Remote = require('__eradicators-library__/erlib/factorio/Remote')()
    

Misc

try_call(interface_name, method_name, ...) Calls a remote interface method if it exists.

PackedInterfaceGroup

PackedInterfaceGroup Concept. A table distributed in parts accross multiple remote interfaces.
PackedInterfaceGroup(name) Create a new PackedInterfaceGroup object instance.
PackedInterfaceGroup:get(key) Decodes and returns the value of a key.
PackedInterfaceGroup:get_all() Decodes and returns all (key → value) pairs.
PackedInterfaceGroup:set(key, value) Encodes the given (key → value) mapping and makes it publically accessible.

Wrapper

get_interface(interface_name) Imports a LuaRemote interface as a local module.


Misc

try_call(interface_name, method_name, ...)
Calls a remote interface method if it exists.

Parameters:

Returns:

  1. boolean If the method exists or not.
  2. AnyValue The return value(s) of the remote call.

PackedInterfaceGroup

PackedInterfaceGroup
Concept. A table distributed in parts accross multiple remote interfaces.

A PackedInterfaceGroup encodes static data into the method names of multiple remote interfaces. One (key → value) pair is encoded per method. Keys are unique within the group. They can only be written once and can never be removed. The methods themselfs are No-Op dummies.

A PackedInterfaceGroup object provides read access to the data of an arbitary number of sequentially numbered remote interfaces. Each instance has write access to a single such numbered interface.

Used to transfer static data between mods before on_load. For example event names generated by script.generate_event_name().

This allows all mods using the same PackedInterfaceGroup name to transparently access each others constants without having to know which mods are installed.

However you can only read data from mods that were loaded before yours. So if you want to read data from a particular mod you must declare an (optional) dependency on that mod.

PackedInterfaceGroup(name)
Create a new PackedInterfaceGroup object instance.

Parameters:

  • name string The name of this group. The same name must be used by all mods that intend to share data.

Returns:

    PackedInterfaceGroup
PackedInterfaceGroup:get(key)
Decodes and returns the value of a key.

Parameters:

Returns:

    string, number, table or nil Returns nil if there is no such key.
PackedInterfaceGroup:get_all()
Decodes and returns all (key → value) pairs.

Returns:

    table
PackedInterfaceGroup:set(key, value)
Encodes the given (key → value) mapping and makes it publically accessible. All keys are writeable only once. Keys that already have a value can not be altered or deleted.

Writing the exact same value that the key already maps will be silently ignored.

Parameters:

Returns:

    string, number or table The input value.

Wrapper

get_interface(interface_name)
Imports a LuaRemote interface as a local module. Behaves identical to calling the interface manually.

Syntactic sugar for candy lovers.

Parameters:

  • interface_name string The name of any remote interface.

Returns:

    table The pseudo-module wrapper.

Usage:

    local Freeplay = Remote.get_interface('freeplay')
    
    -- Native syntax.
    for method_name in pairs(remote.interfaces['freeplay']) do
      print(method_name)
      end
    
    -- Sugar coated syntax.
    for method_name in pairs(Freeplay) do
      print(method_name)
      end
    
    > get_created_items
    > set_created_items
    > get_respawn_items
    > set_respawn_items
    > set_skip_intro
    > set_chart_distance
    > set_disable_crashsite
    > get_ship_items
    > set_ship_items
    > get_debris_items
    > set_debris_items
    
    print(Hydra.lines(Freeplay.get_created_items()))
    
    > {
    >   ["wood"] = 1
    >   ["pistol"] = 1,
    >   ["iron-plate"] = 8,
    >   ["stone-furnace"] = 1,
    >   ["firearm-magazine"] = 10,
    >   ["burner-mining-drill"] = 1,
    >   }
    
generated by LDoc 1.4.6 Last updated 2021-09-10 19:51:19