Registry of interfaces between scripts. An interface is simply a dictionary mapping names to functions. A script or mod can then register an interface with LuaRemote, after that any script can call the registered functions, provided it knows the interface name and the desired function name. An instance of LuaRemote is available through the global object named remote
.
-- Will register a remote interface containing two functions. Later, it will call these functions through `remote`.
remote.add_interface("human interactor",
{
hello = function() game.player.print("Hi!") end,
bye = function(name) game.player.print("Bye " .. name) end
})
-- Some time later, possibly in a different mod...
remote.call("human interactor", "hello")
remote.call("human interactor", "bye", "dear reader")
add_interface(name, functions) | Add a remote interface. | |
Add a remote interface. | ||
remove_interface(name) | → boolean | Removes an interface with the given name. |
Removes an interface with the given name. | ||
call(interface, function, ...) | → Any? | Call a function of an interface. [...] |
Call a function of an interface. [...] | ||
object_name | :: R string | The class name of this object. [...] |
The class name of this object. [...] | ||
interfaces | :: R dictionary[string → dictionary[string → true ]] | List of all registered interfaces. [...] |
List of all registered interfaces. [...] |
Add a remote interface.
name | :: string | Name of the interface. If the name matches any existing interface, an error is thrown. |
Name of the interface. If the name matches any existing interface, an error is thrown. | ||
functions | :: dictionary[string → function()] | List of functions that are members of the new interface. |
List of functions that are members of the new interface. |
Call a function of an interface.
Providing an unknown interface or function name will result in a script error.
interface | :: string | Interface to look up |
Interface to look up | ||
function | :: string | Function name that belongs to the |
Function name that belongs to the | ||
... | :: Any | Arguments to pass to the called function. Note that any arguments passed through the interface are a copy of the original, not a reference. Metatables are not retained, while references to LuaObjects stay intact. Functions cannot be passed through the interface. |
Arguments to pass to the called function. Note that any arguments passed through the interface are a copy of the original, not a reference. Metatables are not retained, while references to LuaObjects stay intact. Functions cannot be passed through the interface. |
The class name of this object. Available even when valid
is false. For LuaStruct objects it may also be suffixed with a dotted path to a member of the struct.
true
]] List of all registered interfaces. For each interface name, remote.interfaces[name]
is a dictionary mapping the interface's registered functions to true
.
-- Assuming the "human interactor" interface is registered as above
game.player.print(tostring(remote.interfaces["human interactor"]["hello"])) -- prints true
game.player.print(tostring(remote.interfaces["human interactor"]["nonexistent"])) -- prints nil