π Talking to other mods API¶
Through Pier your mod talks to mods of any language on the server, and LeviLamina native plugins that are not Pier mods join in through the bridge. Both sides pass strings in a format you agree on, JSON or SNBT; Pier does not look inside.
| Shape | A reply? | Name | |
|---|---|---|---|
| Service | ask and answer | yes | one provider per name |
| Bus | one speaks, everyone listens | no, but listeners can veto | anyone subscribes to a topic |
Services¶
Providing a service¶
Rust: service::register(name, provider)
Go: levilamina.RegisterService(name, provider)
Zig: levilamina.registerService(name, provider)
- Parameters:
- name : string
the service name; namespace it, asplot:owner - provider : function
takes the request and returns the reply, or an error whose message reaches the caller unchanged, so it can tell "no such plot" from "the database is down"
- name : string
- Return value: the registration; keep it to withdraw the service
- Return type: Rust
Result<Registration>, Go(*ServiceRegistration, error), Ziglevilamina.Error!ServiceRegistration- The provider runs on the caller's thread, and is still called while your mod is disabled but loaded, since other mods may need it in their own load stage.
- Slot:
service_register -
Example:
- Rust
Rust - Go
Go - Zig
Calling another mod's service¶
Rust: service::call(name, request)
Go: levilamina.CallService(name, request)
Zig: levilamina.callService(allocator, name, request)
- Parameters:
- name : string
the service name - request : string
the request
- name : string
- Return value: the reply
- Return type: Rust
CallResult<String>, Go(string, error)(the error is a*CallError), Ziglevilamina.Error!CallOutcome- A failure is one of four: not found (nobody provides the name), provider refused (with its reason), host refused (a bad name, a call to yourself, or a cycle), unavailable (this Pier has no services).
- For an optional integration: Rust
service::call_optional, Golevilamina.CallServiceOptional.
- Slot:
service_call -
Example:
- Rust
Rust - Go
Go - Zig
Who is calling¶
Rust: service::caller()
Go: levilamina.ServiceCaller()
Zig: levilamina.serviceCaller(allocator)
The request can claim anything. Inside the provider, ask the host which mod's call is running.
- Return value: the calling mod's name; absent for a native plugin through the bridge
- Return type: Rust
Option<String>, Go(string, bool), Ziglevilamina.Error!?[]u8 - Slot:
service_caller -
Example:
- Rust
Rust - Go
Go - Zig
Zig
The bus¶
Subscribing to a topic¶
Rust: bus::subscribe(topic, handler)
Go: levilamina.BusSubscribe(topic, handler)
Zig: levilamina.busSubscribe(topic, handler)
- Parameters:
- topic : string
the topic; namespace it, asplot:enter - handler : function
runs on the publisher's thread for each message. It returns a veto:trueobjects, and only a vetoable publish reads it
- topic : string
- Return value: the subscription; keep it to unsubscribe
- Return type: Rust
Result<Subscription>, Go(*Subscription, error), Ziglevilamina.Error!Subscription- When a subscriber panics, Pier counts it as no opinion and the publish goes on.
- Slot:
bus_subscribe -
Example:
- Rust
Rust - Go
Go - Zig
Publishing a message¶
Rust: bus::publish(topic, payload)
Go: levilamina.BusPublish(topic, payload)
Zig: levilamina.busPublish(topic, payload)
- Parameters:
- topic : string
the topic - payload : string
the message
- topic : string
- Return value: how many subscribers received it. 0 means nobody is listening right now; the publish itself succeeded
- Return type: Rust
Result<u32>, Go(uint32, error), Ziglevilamina.Error!u32 - Slot:
bus_publish -
Example:
- Rust
Rust - Go
Go - Zig
Zig
Asking everyone first¶
Rust: bus::publish_vetoable(topic, payload)
Go: levilamina.BusPublishVetoable(topic, payload)
Zig: levilamina.busPublishVetoable(topic, payload)
- Parameters:
- topic : string
the topic - payload : string
the message
- topic : string
- Return value: whether anyone objected, and how many received it
- Return type: Rust
Result<Vetoable>, Go(Vetoable, error), Ziglevilamina.Error!Vetoable- One subscriber returning
truemakes the result "vetoed"; the other subscribers still receive the message.
- One subscriber returning
- Slot:
bus_publish_vetoable -
Example:
- Rust
- Go
Go - Zig